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

Commit 2951818e authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "Add ability to disable wakelocks in light idle." into main

parents b6ad0847 3869da75
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ aconfig_srcjars = [
    ":android.service.autofill.flags-aconfig-java{.generated_srcjars}",
    ":com.android.net.flags-aconfig-java{.generated_srcjars}",
    ":device_policy_aconfig_flags_lib{.generated_srcjars}",
    ":service-jobscheduler-deviceidle.flags-aconfig-java{.generated_srcjars}",
    ":surfaceflinger_flags_java_lib{.generated_srcjars}",
]

+17 −0
Original line number Diff line number Diff line
// Device Idle
aconfig_declarations {
    name: "service-deviceidle.flags-aconfig",
    package: "com.android.server.deviceidle",
    srcs: [
        "device_idle.aconfig",
    ],
}

java_aconfig_library {
    name: "service-jobscheduler-deviceidle.flags-aconfig-java",
    aconfig_declarations: "service-deviceidle.flags-aconfig",
    defaults: ["framework-minus-apex-aconfig-java-defaults"],
    visibility: ["//frameworks/base:__subpackages__"],
}

// JobScheduler
aconfig_declarations {
    name: "service-job.flags-aconfig",
@@ -15,6 +31,7 @@ java_aconfig_library {
}

service_jobscheduler_aconfig_srcjars = [
    ":service-jobscheduler-deviceidle.flags-aconfig-java{.generated_srcjars}",
    ":service-jobscheduler-job.flags-aconfig-java{.generated_srcjars}",
]

+8 −0
Original line number Diff line number Diff line
package: "com.android.server.deviceidle"

flag {
    name: "disable_wakelocks_in_light_idle"
    namespace: "backstage_power"
    description: "Disable wakelocks for background apps while Light Device Idle is active"
    bug: "299329948"
}
+17 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.os.PowerManagerInternal.isInteractive;
import static android.os.PowerManagerInternal.wakefulnessToString;

import static com.android.internal.util.LatencyTracker.ACTION_TURN_ON_SCREEN;
import static com.android.server.deviceidle.Flags.disableWakelocksInLightIdle;

import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -644,9 +645,11 @@ public final class PowerManagerService extends SystemService
    private boolean mBatteryLevelLow;

    // True if we are currently in device idle mode.
    @GuardedBy("mLock")
    private boolean mDeviceIdleMode;

    // True if we are currently in light device idle mode.
    @GuardedBy("mLock")
    private boolean mLightDeviceIdleMode;

    // Set of app ids that we will respect the wake locks for while in device idle mode.
@@ -4035,6 +4038,9 @@ public final class PowerManagerService extends SystemService
        synchronized (mLock) {
            if (mLightDeviceIdleMode != enabled) {
                mLightDeviceIdleMode = enabled;
                if (!mDeviceIdleMode && disableWakelocksInLightIdle()) {
                    updateWakeLockDisabledStatesLocked();
                }
                setPowerModeInternal(MODE_DEVICE_IDLE, mDeviceIdleMode || mLightDeviceIdleMode);
                return true;
            }
@@ -4045,7 +4051,7 @@ public final class PowerManagerService extends SystemService
    void setDeviceIdleWhitelistInternal(int[] appids) {
        synchronized (mLock) {
            mDeviceIdleWhitelist = appids;
            if (mDeviceIdleMode) {
            if (doesIdleStateBlockWakeLocksLocked()) {
                updateWakeLockDisabledStatesLocked();
            }
        }
@@ -4054,7 +4060,7 @@ public final class PowerManagerService extends SystemService
    void setDeviceIdleTempWhitelistInternal(int[] appids) {
        synchronized (mLock) {
            mDeviceIdleTempWhitelist = appids;
            if (mDeviceIdleMode) {
            if (doesIdleStateBlockWakeLocksLocked()) {
                updateWakeLockDisabledStatesLocked();
            }
        }
@@ -4114,7 +4120,7 @@ public final class PowerManagerService extends SystemService
                    <= ActivityManager.PROCESS_STATE_RECEIVER;
            state.mProcState = procState;
            if (state.mNumWakeLocks > 0) {
                if (mDeviceIdleMode || mLowPowerStandbyActive) {
                if (doesIdleStateBlockWakeLocksLocked() || mLowPowerStandbyActive) {
                    handleUidStateChangeLocked();
                } else if (!state.mActive && oldShouldAllow !=
                        (procState <= ActivityManager.PROCESS_STATE_RECEIVER)) {
@@ -4134,7 +4140,8 @@ public final class PowerManagerService extends SystemService
                state.mProcState = ActivityManager.PROCESS_STATE_NONEXISTENT;
                state.mActive = false;
                mUidState.removeAt(index);
                if ((mDeviceIdleMode || mLowPowerStandbyActive) && state.mNumWakeLocks > 0) {
                if ((doesIdleStateBlockWakeLocksLocked() || mLowPowerStandbyActive)
                        && state.mNumWakeLocks > 0) {
                    handleUidStateChangeLocked();
                }
            }
@@ -4168,6 +4175,11 @@ public final class PowerManagerService extends SystemService
        }
    }

    @GuardedBy("mLock")
    private boolean doesIdleStateBlockWakeLocksLocked() {
        return mDeviceIdleMode || (mLightDeviceIdleMode && disableWakelocksInLightIdle());
    }

    @GuardedBy("mLock")
    private void updateWakeLockDisabledStatesLocked() {
        boolean changed = false;
@@ -4207,7 +4219,7 @@ public final class PowerManagerService extends SystemService
                                    != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                            wakeLock.mUidState.mProcState > ActivityManager.PROCESS_STATE_RECEIVER);
                }
                if (mDeviceIdleMode) {
                if (doesIdleStateBlockWakeLocksLocked()) {
                    // If we are in idle mode, we will also ignore all partial wake locks that are
                    // for application uids that are not allowlisted.
                    final UidState state = wakeLock.mUidState;
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ android_test {
    ],

    static_libs: [
        "flag-junit",
        "frameworks-base-testutils",
        "platform-compat-test-rules",
        "platform-test-annotations",
Loading