Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ public void onDrawn() {
private ThreeFingersSwipeListener mThreeFingersSwipe;
private boolean mThreeFingersSwipeHasAction;

private boolean mScreenOnReclaim;
private volatile boolean mScreenOnReclaim;

private PocketManager mPocketManager;
private PocketLock mPocketLock;
Expand Down Expand Up @@ -3706,8 +3706,7 @@ void updateSettings(Handler handler) {
Settings.System.LOCKSCREEN_ENABLE_POWER_MENU, 1,
UserHandle.USER_CURRENT) != 0;

mScreenOnReclaim = Settings.System.getIntForUser(resolver,
Settings.System.SCREEN_ON_MEMORY_RECLAIM, 1, UserHandle.USER_CURRENT) == 1;
mScreenOnReclaim = isScreenOnMemoryReclaimEnabled();

kidsModeEnabled = Settings.Secure.getIntForUser(resolver,
Settings.Secure.NAV_BAR_KIDS_MODE, 0, UserHandle.USER_CURRENT) == 1;
Expand Down Expand Up @@ -6546,10 +6545,13 @@ public void finishedWakingUp(int displayGroupId, @WakeReason int pmWakeReason) {
}
}

private final Runnable mMemoryOpt = new Runnable() {
@VisibleForTesting
final Runnable mMemoryOpt = new Runnable() {
@Override
public void run() {
releaseMemoryAtScreenOn();
if (isScreenOnMemoryReclaimEnabled()) {
releaseMemoryAtScreenOn();
}
}
};

Expand Down Expand Up @@ -8256,6 +8258,13 @@ private void toggleRingerModes() {
}
}

private boolean isScreenOnMemoryReclaimEnabled() {
return Settings.System.getIntForUser(
mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM,
1, UserHandle.USER_CURRENT) == 1;
}

private void releaseMemoryAtScreenOn() {
long currentTime = System.currentTimeMillis();
if (lastMemoryReleaseTime == 0L || currentTime - lastMemoryReleaseTime > MEMORY_RELEASE_INTERVAL_MS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,50 @@ public void testScreenTurnedOn_forAdjacentDisplayGroup() {
verify(mKeyguardServiceDelegate).onFinishedWakingUp();
}

@Test
public void screenOnMemoryReclaimDisabledAtExecution_doesNotReleaseMemory()
throws Exception {
initPhoneWindowManager();
final int originalValue = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, 1);
try {
doNothing().when(ActivityManager.getService()).releaseMemory(
anyInt(), anyInt(), anyBoolean(), anyBoolean());
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, 0);

mPhoneWindowManager.mMemoryOpt.run();

verify(ActivityManager.getService(), never())
.releaseMemory(900, 25, false, false);
} finally {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, originalValue);
}
}

@Test
public void screenOnMemoryReclaimEnabledAtExecution_releasesMemory()
throws Exception {
initPhoneWindowManager();
final int originalValue = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, 1);
try {
doNothing().when(ActivityManager.getService()).releaseMemory(
anyInt(), anyInt(), anyBoolean(), anyBoolean());
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, 1);

mPhoneWindowManager.mMemoryOpt.run();

verify(ActivityManager.getService())
.releaseMemory(900, 25, false, false);
} finally {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.SCREEN_ON_MEMORY_RECLAIM, originalValue);
}
}

@Test
public void testCheckAddPermission_withoutAccessibilityOverlay_noAccessibilityAppOpLogged() {
mSetFlagsRule.enableFlags(android.view.contentprotection.flags.Flags.FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED);
Expand Down