Change CacheOomRanker's "uses" feature. am: 7d611c750c am: bcf575e987
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15684479 Change-Id: I91449ae6098473db6f9da6406dd1e18538f94f21
This commit is contained in:
@@ -771,6 +771,11 @@ public class ActivityManager {
|
|||||||
return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
|
return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide Should this process state be considered in the cache? */
|
||||||
|
public static final boolean isProcStateCached(int procState) {
|
||||||
|
return procState >= PROCESS_STATE_CACHED_ACTIVITY;
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide Is this a foreground service type? */
|
/** @hide Is this a foreground service type? */
|
||||||
public static boolean isForegroundService(int procState) {
|
public static boolean isForegroundService(int procState) {
|
||||||
return procState == PROCESS_STATE_FOREGROUND_SERVICE;
|
return procState == PROCESS_STATE_FOREGROUND_SERVICE;
|
||||||
|
|||||||
@@ -577,6 +577,10 @@ final class ProcessStateRecord {
|
|||||||
|
|
||||||
@GuardedBy({"mService", "mProcLock"})
|
@GuardedBy({"mService", "mProcLock"})
|
||||||
void setSetProcState(int setProcState) {
|
void setSetProcState(int setProcState) {
|
||||||
|
if (ActivityManager.isProcStateCached(mSetProcState)
|
||||||
|
&& !ActivityManager.isProcStateCached(setProcState)) {
|
||||||
|
mCacheOomRankerUseCount++;
|
||||||
|
}
|
||||||
mSetProcState = setProcState;
|
mSetProcState = setProcState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,12 +844,7 @@ final class ProcessStateRecord {
|
|||||||
|
|
||||||
@GuardedBy("mService")
|
@GuardedBy("mService")
|
||||||
void setCached(boolean cached) {
|
void setCached(boolean cached) {
|
||||||
if (mCached != cached) {
|
mCached = cached;
|
||||||
mCached = cached;
|
|
||||||
if (cached) {
|
|
||||||
++mCacheOomRankerUseCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mService")
|
@GuardedBy("mService")
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.IApplicationThread;
|
import android.app.IApplicationThread;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -581,7 +582,7 @@ public class CacheOomRankerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ProcessRecord nextProcessRecord(int setAdj, long lastActivityTime, long lastRss,
|
private ProcessRecord nextProcessRecord(int setAdj, long lastActivityTime, long lastRss,
|
||||||
int returnedToCacheCount) {
|
int wentToForegroundCount) {
|
||||||
ApplicationInfo ai = new ApplicationInfo();
|
ApplicationInfo ai = new ApplicationInfo();
|
||||||
ai.packageName = "a.package.name" + mNextPackageName++;
|
ai.packageName = "a.package.name" + mNextPackageName++;
|
||||||
ProcessRecord app = new ProcessRecord(mAms, ai, ai.packageName + ":process", mNextUid++);
|
ProcessRecord app = new ProcessRecord(mAms, ai, ai.packageName + ":process", mNextUid++);
|
||||||
@@ -593,9 +594,9 @@ public class CacheOomRankerTest {
|
|||||||
app.setLastActivityTime(lastActivityTime);
|
app.setLastActivityTime(lastActivityTime);
|
||||||
app.mProfile.setLastRss(lastRss);
|
app.mProfile.setLastRss(lastRss);
|
||||||
app.mState.setCached(false);
|
app.mState.setCached(false);
|
||||||
for (int i = 0; i < returnedToCacheCount; ++i) {
|
for (int i = 0; i < wentToForegroundCount; ++i) {
|
||||||
app.mState.setCached(false);
|
app.mState.setSetProcState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE);
|
||||||
app.mState.setCached(true);
|
app.mState.setSetProcState(ActivityManager.PROCESS_STATE_CACHED_RECENT);
|
||||||
}
|
}
|
||||||
// Sets the thread returned by ProcessRecord#getThread, which we use to check whether the
|
// Sets the thread returned by ProcessRecord#getThread, which we use to check whether the
|
||||||
// app is currently launching.
|
// app is currently launching.
|
||||||
|
|||||||
Reference in New Issue
Block a user