Loading core/java/android/os/PowerManagerInternal.java +8 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,14 @@ public abstract class PowerManagerInternal { public abstract void uidIdle(int uid); /** * Used to notify the power manager that wakelocks should be disabled. * * @param force {@code true} to activate force disable wakelocks, {@code false} to turn it off. */ public abstract void setForceDisableWakelocks(boolean force); /** * Boost: It is sent when user interacting with the device, for example, * touchscreen events are incoming. Loading services/core/java/com/android/server/power/PowerManagerService.java +35 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,9 @@ public final class PowerManagerService extends SystemService // Message: Sent when the processes frozen state changes private static final int MSG_PROCESS_FROZEN_STATE_CHANGED = 7; // Message: Sent when the policy wants to force disable wakelocks. private static final int MSG_FORCE_DISABLE_WAKELOCKS = 8; // Dirty bit: mWakeLocks changed private static final int DIRTY_WAKE_LOCKS = 1 << 0; // Dirty bit: mWakefulness changed Loading Loading @@ -742,6 +745,10 @@ public final class PowerManagerService extends SystemService // Whether to keep dreaming when the device is unplugging. private boolean mKeepDreamingWhenUnplugging; // Whether to force disable wakelocks. @GuardedBy("mLock") private boolean mForceDisableWakelocks; @GuardedBy("mLock") private ScreenTimeoutOverridePolicy mScreenTimeoutOverridePolicy; Loading Loading @@ -4392,6 +4399,15 @@ public final class PowerManagerService extends SystemService } } void setForceDisableWakelocksInternal(boolean force) { synchronized (mLock) { if (mFeatureFlags.isForceDisableWakelocksEnabled()) { mForceDisableWakelocks = force; updateWakeLockDisabledStatesLocked(); } } } @GuardedBy("mLock") private boolean doesIdleStateBlockWakeLocksLocked() { return mDeviceIdleMode || (mLightDeviceIdleMode && disableWakelocksInLightIdle()); Loading Loading @@ -4470,6 +4486,10 @@ public final class PowerManagerService extends SystemService } } } // Disable all PARTAIL_WAKE_LOCKS if mForceDisableWakelocks is true. if (mForceDisableWakelocks) { disabled = true; } return wakeLock.setDisabled(disabled); } else if (mDisableScreenWakeLocksWhileCached && isScreenLock(wakeLock)) { final int appid = UserHandle.getAppId(wakeLock.mOwnerUid); Loading Loading @@ -5511,6 +5531,13 @@ public final class PowerManagerService extends SystemService case MSG_PROCESS_FROZEN_STATE_CHANGED: handleProcessFrozenStateChange(msg.obj, msg.arg1); break; case MSG_FORCE_DISABLE_WAKELOCKS: if (msg.arg1 == 1) { setForceDisableWakelocksInternal(true); } else { setForceDisableWakelocksInternal(false); } break; } return true; Loading Loading @@ -7565,6 +7592,14 @@ public final class PowerManagerService extends SystemService updateSettingsLocked(); } } @Override public void setForceDisableWakelocks(boolean force) { Slog.i(TAG, (force ? "Starting" : "Stopping") + " to force disable partial wakelocks"); Message msg = mHandler.obtainMessage(MSG_FORCE_DISABLE_WAKELOCKS, force ? 1 : 0, 0 /*unused*/); mHandler.sendMessageAtTime(msg, mClock.uptimeMillis()); } } /** Loading services/core/java/com/android/server/power/feature/PowerManagerFlags.java +11 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,9 @@ public class PowerManagerFlags { new FlagState(Flags.FLAG_DISABLE_FROZEN_PROCESS_WAKELOCKS, Flags::disableFrozenProcessWakelocks); private final FlagState mForceDisableWakelocks = new FlagState(Flags.FLAG_FORCE_DISABLE_WAKELOCKS, Flags::forceDisableWakelocks); private final FlagState mEnableAppWakelockDataSource = new FlagState(Flags.FLAG_ENABLE_APP_WAKELOCK_DATA_SOURCE, Flags::enableAppWakelockDataSource); Loading Loading @@ -125,6 +128,13 @@ public class PowerManagerFlags { return mDisableFrozenProcessWakelocks.isEnabled(); } /** * @return Whether the feature to force disable wakelocks is enabled */ public boolean isForceDisableWakelocksEnabled() { return mForceDisableWakelocks.isEnabled(); } /** * @return Whether the new Perfetto data source for tracing app wakelocks is enabled */ Loading @@ -144,6 +154,7 @@ public class PowerManagerFlags { pw.println(" " + mMoveWscLoggingToNotifier); pw.println(" " + mWakelockAttributionViaWorkchain); pw.println(" " + mDisableFrozenProcessWakelocks); pw.println(" " + mForceDisableWakelocks); pw.println(" " + mEnableAppWakelockDataSource); } Loading services/core/java/com/android/server/power/feature/power_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,13 @@ flag { bug: "291115867" } flag { name: "force_disable_wakelocks" namespace: "power" description: "Feature flag to force disable wakelocks" bug: "370557028" } flag { name: "enable_app_wakelock_data_source" namespace: "power" Loading services/tests/powerservicetests/src/com/android/server/power/PowerManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -2991,6 +2991,26 @@ public class PowerManagerServiceTest { assertThat(wakeLock.mDisabled).isFalse(); } @Test @RequiresFlagsEnabled({Flags.FLAG_FORCE_DISABLE_WAKELOCKS}) public void testDisableWakelocks_whenForced() { createService(); startSystem(); WakeLock wakeLock = acquireWakeLock("forceDisableTestWakeLock", PowerManager.PARTIAL_WAKE_LOCK, Display.INVALID_DISPLAY); assertThat(wakeLock.mDisabled).isFalse(); advanceTime(1000); mService.setForceDisableWakelocksInternal(true); advanceTime(1000); assertThat(wakeLock.mDisabled).isTrue(); mService.setForceDisableWakelocksInternal(false); advanceTime(1000); assertThat(wakeLock.mDisabled).isFalse(); } @Test @RequiresFlagsEnabled({Flags.FLAG_DISABLE_FROZEN_PROCESS_WAKELOCKS}) public void testDisableWakelocks_whenFrozen() { Loading Loading
core/java/android/os/PowerManagerInternal.java +8 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,14 @@ public abstract class PowerManagerInternal { public abstract void uidIdle(int uid); /** * Used to notify the power manager that wakelocks should be disabled. * * @param force {@code true} to activate force disable wakelocks, {@code false} to turn it off. */ public abstract void setForceDisableWakelocks(boolean force); /** * Boost: It is sent when user interacting with the device, for example, * touchscreen events are incoming. Loading
services/core/java/com/android/server/power/PowerManagerService.java +35 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,9 @@ public final class PowerManagerService extends SystemService // Message: Sent when the processes frozen state changes private static final int MSG_PROCESS_FROZEN_STATE_CHANGED = 7; // Message: Sent when the policy wants to force disable wakelocks. private static final int MSG_FORCE_DISABLE_WAKELOCKS = 8; // Dirty bit: mWakeLocks changed private static final int DIRTY_WAKE_LOCKS = 1 << 0; // Dirty bit: mWakefulness changed Loading Loading @@ -742,6 +745,10 @@ public final class PowerManagerService extends SystemService // Whether to keep dreaming when the device is unplugging. private boolean mKeepDreamingWhenUnplugging; // Whether to force disable wakelocks. @GuardedBy("mLock") private boolean mForceDisableWakelocks; @GuardedBy("mLock") private ScreenTimeoutOverridePolicy mScreenTimeoutOverridePolicy; Loading Loading @@ -4392,6 +4399,15 @@ public final class PowerManagerService extends SystemService } } void setForceDisableWakelocksInternal(boolean force) { synchronized (mLock) { if (mFeatureFlags.isForceDisableWakelocksEnabled()) { mForceDisableWakelocks = force; updateWakeLockDisabledStatesLocked(); } } } @GuardedBy("mLock") private boolean doesIdleStateBlockWakeLocksLocked() { return mDeviceIdleMode || (mLightDeviceIdleMode && disableWakelocksInLightIdle()); Loading Loading @@ -4470,6 +4486,10 @@ public final class PowerManagerService extends SystemService } } } // Disable all PARTAIL_WAKE_LOCKS if mForceDisableWakelocks is true. if (mForceDisableWakelocks) { disabled = true; } return wakeLock.setDisabled(disabled); } else if (mDisableScreenWakeLocksWhileCached && isScreenLock(wakeLock)) { final int appid = UserHandle.getAppId(wakeLock.mOwnerUid); Loading Loading @@ -5511,6 +5531,13 @@ public final class PowerManagerService extends SystemService case MSG_PROCESS_FROZEN_STATE_CHANGED: handleProcessFrozenStateChange(msg.obj, msg.arg1); break; case MSG_FORCE_DISABLE_WAKELOCKS: if (msg.arg1 == 1) { setForceDisableWakelocksInternal(true); } else { setForceDisableWakelocksInternal(false); } break; } return true; Loading Loading @@ -7565,6 +7592,14 @@ public final class PowerManagerService extends SystemService updateSettingsLocked(); } } @Override public void setForceDisableWakelocks(boolean force) { Slog.i(TAG, (force ? "Starting" : "Stopping") + " to force disable partial wakelocks"); Message msg = mHandler.obtainMessage(MSG_FORCE_DISABLE_WAKELOCKS, force ? 1 : 0, 0 /*unused*/); mHandler.sendMessageAtTime(msg, mClock.uptimeMillis()); } } /** Loading
services/core/java/com/android/server/power/feature/PowerManagerFlags.java +11 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,9 @@ public class PowerManagerFlags { new FlagState(Flags.FLAG_DISABLE_FROZEN_PROCESS_WAKELOCKS, Flags::disableFrozenProcessWakelocks); private final FlagState mForceDisableWakelocks = new FlagState(Flags.FLAG_FORCE_DISABLE_WAKELOCKS, Flags::forceDisableWakelocks); private final FlagState mEnableAppWakelockDataSource = new FlagState(Flags.FLAG_ENABLE_APP_WAKELOCK_DATA_SOURCE, Flags::enableAppWakelockDataSource); Loading Loading @@ -125,6 +128,13 @@ public class PowerManagerFlags { return mDisableFrozenProcessWakelocks.isEnabled(); } /** * @return Whether the feature to force disable wakelocks is enabled */ public boolean isForceDisableWakelocksEnabled() { return mForceDisableWakelocks.isEnabled(); } /** * @return Whether the new Perfetto data source for tracing app wakelocks is enabled */ Loading @@ -144,6 +154,7 @@ public class PowerManagerFlags { pw.println(" " + mMoveWscLoggingToNotifier); pw.println(" " + mWakelockAttributionViaWorkchain); pw.println(" " + mDisableFrozenProcessWakelocks); pw.println(" " + mForceDisableWakelocks); pw.println(" " + mEnableAppWakelockDataSource); } Loading
services/core/java/com/android/server/power/feature/power_flags.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,13 @@ flag { bug: "291115867" } flag { name: "force_disable_wakelocks" namespace: "power" description: "Feature flag to force disable wakelocks" bug: "370557028" } flag { name: "enable_app_wakelock_data_source" namespace: "power" Loading
services/tests/powerservicetests/src/com/android/server/power/PowerManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -2991,6 +2991,26 @@ public class PowerManagerServiceTest { assertThat(wakeLock.mDisabled).isFalse(); } @Test @RequiresFlagsEnabled({Flags.FLAG_FORCE_DISABLE_WAKELOCKS}) public void testDisableWakelocks_whenForced() { createService(); startSystem(); WakeLock wakeLock = acquireWakeLock("forceDisableTestWakeLock", PowerManager.PARTIAL_WAKE_LOCK, Display.INVALID_DISPLAY); assertThat(wakeLock.mDisabled).isFalse(); advanceTime(1000); mService.setForceDisableWakelocksInternal(true); advanceTime(1000); assertThat(wakeLock.mDisabled).isTrue(); mService.setForceDisableWakelocksInternal(false); advanceTime(1000); assertThat(wakeLock.mDisabled).isFalse(); } @Test @RequiresFlagsEnabled({Flags.FLAG_DISABLE_FROZEN_PROCESS_WAKELOCKS}) public void testDisableWakelocks_whenFrozen() { Loading