Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b2d1605 authored by Makoto Onuki's avatar Makoto Onuki Committed by Automerger Merge Worker
Browse files

Merge "Revert 111b3a2a, "Allow short-service to hold a wake lock during doze""...

Merge "Revert 111b3a2a, "Allow short-service to hold a wake lock during doze"" into udc-dev am: 4a280931

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21654367



Change-Id: Ibcb6e2ca75b7961175f7b4c2d26fea33bb31a0e3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8fa281a5 4a280931
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -967,14 +967,6 @@ public abstract class ActivityManagerInternal {
     */
     */
    public abstract void stopForegroundServiceDelegate(@NonNull ServiceConnection connection);
    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
     * 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
     * even if the profile is disabled - it should only be called by
+0 −19
Original line number Original line Diff line number Diff line
@@ -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.INSTR_FLAG_NO_RESTART;
import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
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_IMPORTANT_FOREGROUND;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT;
import static android.app.ActivityManager.PROCESS_STATE_TOP;
import static android.app.ActivityManager.PROCESS_STATE_TOP;
@@ -3328,7 +3327,6 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        }
        mBatteryStatsService.noteProcessDied(app.info.uid, pid);
        mBatteryStatsService.noteProcessDied(app.info.uid, pid);
        mOomAdjuster.updateShortFgsOwner(app.info.uid, pid, false);
        if (!app.isKilled()) {
        if (!app.isKilled()) {
            if (!fromBinderDied) {
            if (!fromBinderDied) {
@@ -18718,23 +18716,6 @@ public class ActivityManagerService extends IActivityManager.Stub
            mStrictModeCallbacks.remove(callingPid);
            mStrictModeCallbacks.remove(callingPid);
        }
        }
        @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
        @Override
        public boolean startProfileEvenWhenDisabled(@UserIdInt int userId) {
        public boolean startProfileEvenWhenDisabled(@UserIdInt int userId) {
            return mUserController.startProfile(userId, /* evenWhenDisabled= */ true,
            return mUserController.startProfile(userId, /* evenWhenDisabled= */ true,
+0 −51
Original line number Original line Diff line number Diff line
@@ -127,7 +127,6 @@ import android.os.Trace;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseSetArray;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;


import com.android.internal.annotations.CompositeRWLock;
import com.android.internal.annotations.CompositeRWLock;
@@ -367,19 +366,6 @@ public class OomAdjuster {
    @GuardedBy("mService")
    @GuardedBy("mService")
    private boolean mPendingFullOomAdjUpdate = false;
    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 */
    /** Overrideable by a test */
    @VisibleForTesting
    @VisibleForTesting
    protected boolean isChangeEnabled(@CachedCompatChangeId int cachedCompatChangeId,
    protected boolean isChangeEnabled(@CachedCompatChangeId int cachedCompatChangeId,
@@ -1956,7 +1942,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,
        // 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
        // allow it to get a higher rank in memory for some time, compared to other foreground
@@ -3466,40 +3451,4 @@ public class OomAdjuster {
            mCachedAppOptimizer.unfreezeAppLSP(app, oomAdjReason);
            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;
    }
}
}
+3 −5
Original line number Original line Diff line number Diff line
@@ -40,7 +40,6 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.SynchronousUserSwitchObserver;
import android.app.SynchronousUserSwitchObserver;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
@@ -317,7 +316,6 @@ public final class PowerManagerService extends SystemService
    private SettingsObserver mSettingsObserver;
    private SettingsObserver mSettingsObserver;
    private DreamManagerInternal mDreamManager;
    private DreamManagerInternal mDreamManager;
    private LogicalLight mAttentionLight;
    private LogicalLight mAttentionLight;
    private ActivityManagerInternal mAmInternal;


    private final InattentiveSleepWarningController mInattentiveSleepWarningOverlayController;
    private final InattentiveSleepWarningController mInattentiveSleepWarningOverlayController;
    private final AmbientDisplaySuppressionController mAmbientDisplaySuppressionController;
    private final AmbientDisplaySuppressionController mAmbientDisplaySuppressionController;
@@ -1244,7 +1242,6 @@ public final class PowerManagerService extends SystemService
            mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class);
            mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class);
            mPolicy = getLocalService(WindowManagerPolicy.class);
            mPolicy = getLocalService(WindowManagerPolicy.class);
            mBatteryManagerInternal = getLocalService(BatteryManagerInternal.class);
            mBatteryManagerInternal = getLocalService(BatteryManagerInternal.class);
            mAmInternal = getLocalService(ActivityManagerInternal.class);
            mAttentionDetector.systemReady(mContext);
            mAttentionDetector.systemReady(mContext);


            SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
            SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
@@ -4088,8 +4085,9 @@ public final class PowerManagerService extends SystemService
                    final UidState state = wakeLock.mUidState;
                    final UidState state = wakeLock.mUidState;
                    if (Arrays.binarySearch(mDeviceIdleWhitelist, appid) < 0 &&
                    if (Arrays.binarySearch(mDeviceIdleWhitelist, appid) < 0 &&
                            Arrays.binarySearch(mDeviceIdleTempWhitelist, appid) < 0 &&
                            Arrays.binarySearch(mDeviceIdleTempWhitelist, appid) < 0 &&
                            (mAmInternal != null && !mAmInternal.canHoldWakeLocksInDeepDoze(
                            state.mProcState != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                                    state.mUid, state.mProcState))) {
                            state.mProcState >
                                    ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
                        disabled = true;
                        disabled = true;
                    }
                    }
                }
                }
+0 −56
Original line number Original line Diff line number Diff line
@@ -305,60 +305,4 @@ public class OomAdjusterTests {
        assertEquals("Interaction event time was not updated correctly.",
        assertEquals("Interaction event time was not updated correctly.",
                interactionEventTime, mProcessRecord.mState.getInteractionEventTime());
                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);
    }
}
}
Loading