summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/ActivityManagerInternal.java8
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java19
-rw-r--r--services/core/java/com/android/server/am/OomAdjuster.java51
-rw-r--r--services/core/java/com/android/server/power/PowerManagerService.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/am/OomAdjusterTests.java56
-rw-r--r--services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java15
6 files changed, 3 insertions, 154 deletions
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index b9f38d3c8907..d810f055e96e 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -968,14 +968,6 @@ public abstract class ActivityManagerInternal {
public abstract void stopForegroundServiceDelegate(@NonNull ServiceConnection connection);
/**
- * Called by PowerManager. Return whether a given procstate is allowed to hold
- * wake locks in deep doze. Because it's called with the power manager lock held, we can't
- * hold AM locks in it.
- * @hide
- */
- public abstract boolean canHoldWakeLocksInDeepDoze(int uid, int procstate);
-
- /**
* Same as {@link android.app.IActivityManager#startProfile(int userId)}, but it would succeed
* even if the profile is disabled - it should only be called by
* {@link com.android.server.devicepolicy.DevicePolicyManagerService} when starting a profile
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 4a134eef8532..8d6c8db80b06 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -32,7 +32,6 @@ import static android.app.ActivityManager.INSTR_FLAG_DISABLE_TEST_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_NO_RESTART;
import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
-import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
import static android.app.ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityManager.PROCESS_STATE_TOP;
@@ -3341,7 +3340,6 @@ public class ActivityManagerService extends IActivityManager.Stub
}
mBatteryStatsService.noteProcessDied(app.info.uid, pid);
- mOomAdjuster.updateShortFgsOwner(app.info.uid, pid, false);
if (!app.isKilled()) {
if (!fromBinderDied) {
@@ -18769,23 +18767,6 @@ public class ActivityManagerService extends IActivityManager.Stub
}
@Override
- public boolean canHoldWakeLocksInDeepDoze(int uid, int procstate) {
- // This method is called with the PowerManager lock held. Do not hold AM here.
-
- // If the procstate is high enough, it's always allowed.
- if (procstate <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
- return true;
- }
- // IF it's too low, it's not allowed.
- if (procstate > PROCESS_STATE_IMPORTANT_FOREGROUND) {
- return false;
- }
- // If it's PROCESS_STATE_IMPORTANT_FOREGROUND, then we allow it only wheen the UID
- // has a SHORT_FGS.
- return mOomAdjuster.hasUidShortForegroundService(uid);
- }
-
- @Override
public boolean startProfileEvenWhenDisabled(@UserIdInt int userId) {
return mUserController.startProfile(userId, /* evenWhenDisabled= */ true,
/* unlockListener= */ null);
diff --git a/services/core/java/com/android/server/am/OomAdjuster.java b/services/core/java/com/android/server/am/OomAdjuster.java
index 0c366268604d..2c2bb5a04914 100644
--- a/services/core/java/com/android/server/am/OomAdjuster.java
+++ b/services/core/java/com/android/server/am/OomAdjuster.java
@@ -127,7 +127,6 @@ import android.os.Trace;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;
-import android.util.SparseSetArray;
import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.CompositeRWLock;
@@ -366,19 +365,6 @@ public class OomAdjuster {
@GuardedBy("mService")
private boolean mPendingFullOomAdjUpdate = false;
- /**
- * PIDs that has a SHORT_SERVICE. We need to access it with the PowerManager lock held,
- * so we use a fine-grained lock here.
- */
- @GuardedBy("mPidsWithShortFgs")
- private final ArraySet<Integer> mPidsWithShortFgs = new ArraySet<>();
-
- /**
- * UIDs -> PIDs map, used with mPidsWithShortFgs.
- */
- @GuardedBy("mPidsWithShortFgs")
- private final SparseSetArray<Integer> mUidsToPidsWithShortFgs = new SparseSetArray<>();
-
/** Overrideable by a test */
@VisibleForTesting
protected boolean isChangeEnabled(@CachedCompatChangeId int cachedCompatChangeId,
@@ -1955,7 +1941,6 @@ public class OomAdjuster {
}
}
}
- updateShortFgsOwner(psr.mApp.uid, psr.mApp.mPid, hasShortForegroundServices);
// If the app was recently in the foreground and moved to a foreground service status,
// allow it to get a higher rank in memory for some time, compared to other foreground
@@ -3467,40 +3452,4 @@ public class OomAdjuster {
mCachedAppOptimizer.unfreezeAppLSP(app, oomAdjReason);
}
}
-
- /**
- * Update {@link #mPidsWithShortFgs} and {@link #mUidsToPidsWithShortFgs} to keep track
- * of which UID/PID has a short FGS.
- *
- * TODO(short-FGS): Remove it and all the relevant code once SHORT_FGS use the FGS procstate.
- */
- void updateShortFgsOwner(int uid, int pid, boolean add) {
- synchronized (mPidsWithShortFgs) {
- if (add) {
- mUidsToPidsWithShortFgs.add(uid, pid);
- mPidsWithShortFgs.add(pid);
- } else {
- mUidsToPidsWithShortFgs.remove(uid, pid);
- mPidsWithShortFgs.remove(pid);
- }
- }
- }
-
- /**
- * Whether a UID has a (non-timed-out) short FGS or not.
- * It's indirectly called by PowerManager, so we can't hold the AM lock in it.
- */
- boolean hasUidShortForegroundService(int uid) {
- synchronized (mPidsWithShortFgs) {
- final ArraySet<Integer> pids = mUidsToPidsWithShortFgs.get(uid);
- if (pids == null || pids.size() == 0) {
- return false;
- }
- for (int i = pids.size() - 1; i >= 0; i--) {
- final int pid = pids.valueAt(i);
- return mPidsWithShortFgs.contains(pid);
- }
- }
- return false;
- }
}
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index b83d509b47b1..bf8cbeac30c8 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -40,7 +40,6 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
-import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.app.SynchronousUserSwitchObserver;
import android.content.BroadcastReceiver;
@@ -317,7 +316,6 @@ public final class PowerManagerService extends SystemService
private SettingsObserver mSettingsObserver;
private DreamManagerInternal mDreamManager;
private LogicalLight mAttentionLight;
- private ActivityManagerInternal mAmInternal;
private final InattentiveSleepWarningController mInattentiveSleepWarningOverlayController;
private final AmbientDisplaySuppressionController mAmbientDisplaySuppressionController;
@@ -1244,7 +1242,6 @@ public final class PowerManagerService extends SystemService
mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class);
mPolicy = getLocalService(WindowManagerPolicy.class);
mBatteryManagerInternal = getLocalService(BatteryManagerInternal.class);
- mAmInternal = getLocalService(ActivityManagerInternal.class);
mAttentionDetector.systemReady(mContext);
SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
@@ -4088,8 +4085,9 @@ public final class PowerManagerService extends SystemService
final UidState state = wakeLock.mUidState;
if (Arrays.binarySearch(mDeviceIdleWhitelist, appid) < 0 &&
Arrays.binarySearch(mDeviceIdleTempWhitelist, appid) < 0 &&
- (mAmInternal != null && !mAmInternal.canHoldWakeLocksInDeepDoze(
- state.mUid, state.mProcState))) {
+ state.mProcState != ActivityManager.PROCESS_STATE_NONEXISTENT &&
+ state.mProcState >
+ ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
disabled = true;
}
}
diff --git a/services/tests/servicestests/src/com/android/server/am/OomAdjusterTests.java b/services/tests/servicestests/src/com/android/server/am/OomAdjusterTests.java
index 4412cfe4a3b5..8cbed2c7ffb8 100644
--- a/services/tests/servicestests/src/com/android/server/am/OomAdjusterTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/OomAdjusterTests.java
@@ -305,60 +305,4 @@ public class OomAdjusterTests {
assertEquals("Interaction event time was not updated correctly.",
interactionEventTime, mProcessRecord.mState.getInteractionEventTime());
}
-
- private void updateShortFgsOwner(int uid, int pid, boolean add) {
- sService.mOomAdjuster.updateShortFgsOwner(uid, pid, add);
- }
-
- private void assertHasUidShortForegroundService(int uid, boolean expected) {
- assertEquals(expected, sService.mOomAdjuster.hasUidShortForegroundService(uid));
- }
-
- @Test
- public void testHasUidShortForegroundService() {
- assertHasUidShortForegroundService(1, false);
- assertHasUidShortForegroundService(2, false);
- assertHasUidShortForegroundService(3, false);
- assertHasUidShortForegroundService(100, false);
- assertHasUidShortForegroundService(101, false);
-
- updateShortFgsOwner(1, 100, true);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(100, false);
- assertHasUidShortForegroundService(2, false);
-
- updateShortFgsOwner(1, 101, true);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(101, false);
- assertHasUidShortForegroundService(2, false);
-
- updateShortFgsOwner(2, 200, true);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, true);
- assertHasUidShortForegroundService(200, false);
-
- updateShortFgsOwner(1, 101, false);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, true);
-
- updateShortFgsOwner(1, 99, false); // unused PID
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, true);
-
- updateShortFgsOwner(1, 100, false);
- assertHasUidShortForegroundService(1, false);
- assertHasUidShortForegroundService(2, true);
-
- updateShortFgsOwner(1, 100, true);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, true);
-
- updateShortFgsOwner(2, 200, false);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, false);
-
- updateShortFgsOwner(2, 201, true);
- assertHasUidShortForegroundService(1, true);
- assertHasUidShortForegroundService(2, true);
- }
}
diff --git a/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java
index d71deaf3a88d..a0fb3deeb131 100644
--- a/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java
@@ -16,7 +16,6 @@
package com.android.server.power;
-import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP;
import static android.app.ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
import static android.app.AppOpsManager.MODE_ALLOWED;
@@ -30,8 +29,6 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.AdditionalMatchers.gt;
-import static org.mockito.AdditionalMatchers.leq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -153,9 +150,6 @@ public class PowerManagerServiceTest {
@Mock
private InattentiveSleepWarningController mInattentiveSleepWarningControllerMock;
- @Mock
- private ActivityManagerInternal mActivityManagerInternal;
-
private PowerManagerService mService;
private ContextWrapper mContextSpy;
private BatteryReceiver mBatteryReceiver;
@@ -211,7 +205,6 @@ public class PowerManagerServiceTest {
addLocalServiceMock(ActivityManagerInternal.class, mActivityManagerInternalMock);
addLocalServiceMock(AttentionManagerInternal.class, mAttentionManagerInternalMock);
addLocalServiceMock(DreamManagerInternal.class, mDreamManagerInternalMock);
- addLocalServiceMock(ActivityManagerInternal.class, mActivityManagerInternal);
mContextSpy = spy(new ContextWrapper(ApplicationProvider.getApplicationContext()));
mResourcesSpy = spy(mContextSpy.getResources());
@@ -228,14 +221,6 @@ public class PowerManagerServiceTest {
mClock = new OffsettableClock.Stopped();
mTestLooper = new TestLooper(mClock::now);
-
- // Set up canHoldWakeLocksInDeepDoze.
- // - procstate <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE -> true
- // - procstate > PROCESS_STATE_BOUND_FOREGROUND_SERVICE -> false
- when(mActivityManagerInternal.canHoldWakeLocksInDeepDoze(
- anyInt(), leq(PROCESS_STATE_BOUND_FOREGROUND_SERVICE))).thenReturn(true);
- when(mActivityManagerInternal.canHoldWakeLocksInDeepDoze(
- anyInt(), gt(PROCESS_STATE_BOUND_FOREGROUND_SERVICE))).thenReturn(false);
}
private PowerManagerService createService() {