MemoryBudget
public
final
class
MemoryBudget
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.content.pm.MemoryBudget |
Memory budget information for an application. MemoryBudget entries are retrieved from
<memory-budget> entries in an application's manifest, and can be obtained through
ERROR(/ApplicationInfo.getMemoryBudgets).
A MemoryBudget that is declared in the Android manifest sets a ceiling on the memory
available to the package or to a process within the package. MemoryBudget declarations
may appear at the application level and at the process level. The two are independent and
neither overrides the other. In practice, however, the smaller budget dominates.
Every MemoryBudget has a state and a feature; these two attributes determine if and
when the MemoryBudget is applicable.
- The state is the operational state of the process or the application, and is one of Foreground, Perceptible, or Background.
- The feature selects for device form-factor and is one of Unspecified, TV, Auto, and Watch.
MemoryBudget is applicable to a process if its feature is Unspecified or if
its feature matches the device's form-factor. A MemoryBudget applies to a
process if it is applicable to the process and the MemoryBudget state is less than or
equal to the operational state of the process. Applications also have state, which is roughly
the lowest state of any process running in the application.
A MemoryBudget declares an upper bound on the amount of memory the process or
application may use. The upper bound is computed from three factors:
-
maxMbis a baseline amount of memory, expressed in MiB. This must be positive. -
additionalBytesPerPixelis a scaling factor: bytes per display pixel. This must be non-negative and defaults to zero. -
additionalMbPerDensityis a scaling factor: MiB times display density. This must be non-negative and defaults to zero.
maxMb value plus the scale factors applied to the
default display of the device.
If a process RSS exceeds its declared budget then the kernel will force it to drop memory. This usually means dropping file cache pages but it may also mean that some memory will be moved to swap. In most cases this happens without any impact on the process, but if the process is actively using more memory than the budget limit, the process will slow down as pages are swapped out and then back in. In the limit, the process may ANR.
Summary
Constants | |
|---|---|
int |
FEATURE_AUTOMOTIVE
Indicates that this |
int |
FEATURE_LEANBACK
Indicates that this |
int |
FEATURE_UNSPECIFIED
Indicates that this |
int |
FEATURE_WATCH
Indicates that this |
int |
STATE_BACKGROUND
Indicates that this |
int |
STATE_FOREGROUND
Indicates that this |
int |
STATE_PERCEPTIBLE
Indicates that this |
Inherited constants |
|---|
Fields | |
|---|---|
public
static
final
Creator<MemoryBudget> |
CREATOR
|
Public methods | |
|---|---|
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
boolean
|
equals(Object o)
Indicates whether some other object is "equal to" this one. |
long
|
getAdditionalBytesPerDisplayPixel()
Returns the additional bytes per pixel that this |
long
|
getAdditionalMbPerDensity()
Returns the additional memory (in MiB) that this |
int
|
getFeature()
Returns the form factor to which this |
long
|
getMaxMb()
Returns the memory limit (in MiB) that this |
int
|
getState()
Returns the process state in which this |
int
|
hashCode()
Returns a hash code value for the object. |
String
|
toString()
Returns a string representation of the object. |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
|---|---|
Constants
FEATURE_AUTOMOTIVE
public static final int FEATURE_AUTOMOTIVE
Indicates that this MemoryBudget applies to the automotive form factor.
Constant Value: 1 (0x00000001)
FEATURE_LEANBACK
public static final int FEATURE_LEANBACK
Indicates that this MemoryBudget applies to the TV form factor.
Constant Value: 2 (0x00000002)
FEATURE_UNSPECIFIED
public static final int FEATURE_UNSPECIFIED
Indicates that this MemoryBudget is generic, and can apply to any form factor. This
is the default if "feature" is not specified in the manifest.
Constant Value: 0 (0x00000000)
FEATURE_WATCH
public static final int FEATURE_WATCH
Indicates that this MemoryBudget applies to the watch form factor.
Constant Value: 3 (0x00000003)
STATE_BACKGROUND
public static final int STATE_BACKGROUND
Indicates that this MemoryBudget can apply to a process that is in the background.
Constant Value: 300 (0x0000012c)
STATE_FOREGROUND
public static final int STATE_FOREGROUND
Indicates that this MemoryBudget can apply to a process that is in the foreground (or
in a less important state). This is the default if "state" is not specified in the manifest.
Constant Value: 100 (0x00000064)
STATE_PERCEPTIBLE
public static final int STATE_PERCEPTIBLE
Indicates that this MemoryBudget can apply to a process that is perceptible (or in a
less important state).
Constant Value: 200 (0x000000c8)
Fields
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(Parcel,int),
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or
|
equals
public boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| Parameters | |
|---|---|
o |
Object: the reference object with which to compare. |
| Returns | |
|---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
getAdditionalBytesPerDisplayPixel
public long getAdditionalBytesPerDisplayPixel ()
Returns the additional bytes per pixel that this MemoryBudget's limit will be raised
by.
| Returns | |
|---|---|
long |
The additionalBytesPerDisplayPixel attribute. |
getAdditionalMbPerDensity
public long getAdditionalMbPerDensity ()
Returns the additional memory (in MiB) that this MemoryBudget's limit will be raised
by, based on the screen density of the device. The formula used for calculating the
additional memory is (N * { ldpi=0.75, mdpi=1.0, hdpi=1.5, xhdpi=2... }).
| Returns | |
|---|---|
long |
The additionalMbPerDensity attribute. |
getFeature
public int getFeature ()
Returns the form factor to which this MemoryBudget applies.
| Returns | |
|---|---|
int |
The form factor to which this MemoryBudget applies.
Value is one of the following: |
getMaxMb
public long getMaxMb ()
Returns the memory limit (in MiB) that this MemoryBudget represents.
| Returns | |
|---|---|
long |
The memory limit (in MiB) that this MemoryBudget represents. |
getState
public int getState ()
Returns the process state in which this MemoryBudget applies.
| Returns | |
|---|---|
int |
The process state in which this MemoryBudget applies.
Value is one of the following: |
hashCode
public int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
| Returns | |
|---|---|
int |
a hash code value for this object. |
toString
public String toString ()
Returns a string representation of the object.
| Returns | |
|---|---|
String |
a string representation of the object. |
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
dest |
Parcel: This value cannot be null. |
flags |
int: Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.
Value is either 0 or a combination of the following:
|