Loading services/core/java/com/android/server/power/Notifier.java +4 −4 Original line number Diff line number Diff line Loading @@ -265,7 +265,7 @@ public class Notifier { + ", ownerUid=" + ownerUid + ", ownerPid=" + ownerPid + ", workSource=" + workSource); } notifyWakeLockListener(callback, true); notifyWakeLockListener(callback, tag, true); final int monitorType = getBatteryStatsWakeLockMonitorType(flags); if (monitorType >= 0) { try { Loading Loading @@ -392,7 +392,7 @@ public class Notifier { + ", ownerUid=" + ownerUid + ", ownerPid=" + ownerPid + ", workSource=" + workSource); } notifyWakeLockListener(callback, false); notifyWakeLockListener(callback, tag, false); final int monitorType = getBatteryStatsWakeLockMonitorType(flags); if (monitorType >= 0) { try { Loading Loading @@ -1011,13 +1011,13 @@ public class Notifier { return enabled && dndOff; } private void notifyWakeLockListener(IWakeLockCallback callback, boolean isEnabled) { private void notifyWakeLockListener(IWakeLockCallback callback, String tag, boolean isEnabled) { if (callback != null) { mHandler.post(() -> { try { callback.onStateChanged(isEnabled); } catch (RemoteException e) { throw new IllegalArgumentException("Wakelock.mCallback is already dead.", e); Slog.e(TAG, "Wakelock.mCallback [" + tag + "] is already dead.", e); } }); } Loading services/tests/servicestests/src/com/android/server/power/NotifierTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -34,7 +34,10 @@ import android.hardware.SensorManager; import android.hardware.display.AmbientDisplayConfiguration; import android.os.BatteryStats; import android.os.Handler; import android.os.IWakeLockCallback; import android.os.Looper; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.VibrationAttributes; import android.os.Vibrator; Loading Loading @@ -219,6 +222,34 @@ public class NotifierTest { verify(mStatusBarManagerInternal, never()).showChargingAnimation(anyInt()); } @Test public void testOnWakeLockListener_RemoteException_NoRethrow() { createNotifier(); IWakeLockCallback exceptingCallback = new IWakeLockCallback.Stub() { @Override public void onStateChanged(boolean enabled) throws RemoteException { throw new RemoteException("Just testing"); } }; final int uid = 1234; final int pid = 5678; mNotifier.onWakeLockReleased(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback); mNotifier.onWakeLockAcquired(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback); mNotifier.onWakeLockChanging(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback, PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* newWorkSource= */ null, /* newHistoryTag= */ null, exceptingCallback); mTestLooper.dispatchAll(); // If we didn't throw, we're good! } private final PowerManagerService.Injector mInjector = new PowerManagerService.Injector() { @Override Notifier createNotifier(Looper looper, Context context, IBatteryStats batteryStats, Loading Loading
services/core/java/com/android/server/power/Notifier.java +4 −4 Original line number Diff line number Diff line Loading @@ -265,7 +265,7 @@ public class Notifier { + ", ownerUid=" + ownerUid + ", ownerPid=" + ownerPid + ", workSource=" + workSource); } notifyWakeLockListener(callback, true); notifyWakeLockListener(callback, tag, true); final int monitorType = getBatteryStatsWakeLockMonitorType(flags); if (monitorType >= 0) { try { Loading Loading @@ -392,7 +392,7 @@ public class Notifier { + ", ownerUid=" + ownerUid + ", ownerPid=" + ownerPid + ", workSource=" + workSource); } notifyWakeLockListener(callback, false); notifyWakeLockListener(callback, tag, false); final int monitorType = getBatteryStatsWakeLockMonitorType(flags); if (monitorType >= 0) { try { Loading Loading @@ -1011,13 +1011,13 @@ public class Notifier { return enabled && dndOff; } private void notifyWakeLockListener(IWakeLockCallback callback, boolean isEnabled) { private void notifyWakeLockListener(IWakeLockCallback callback, String tag, boolean isEnabled) { if (callback != null) { mHandler.post(() -> { try { callback.onStateChanged(isEnabled); } catch (RemoteException e) { throw new IllegalArgumentException("Wakelock.mCallback is already dead.", e); Slog.e(TAG, "Wakelock.mCallback [" + tag + "] is already dead.", e); } }); } Loading
services/tests/servicestests/src/com/android/server/power/NotifierTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -34,7 +34,10 @@ import android.hardware.SensorManager; import android.hardware.display.AmbientDisplayConfiguration; import android.os.BatteryStats; import android.os.Handler; import android.os.IWakeLockCallback; import android.os.Looper; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; import android.os.VibrationAttributes; import android.os.Vibrator; Loading Loading @@ -219,6 +222,34 @@ public class NotifierTest { verify(mStatusBarManagerInternal, never()).showChargingAnimation(anyInt()); } @Test public void testOnWakeLockListener_RemoteException_NoRethrow() { createNotifier(); IWakeLockCallback exceptingCallback = new IWakeLockCallback.Stub() { @Override public void onStateChanged(boolean enabled) throws RemoteException { throw new RemoteException("Just testing"); } }; final int uid = 1234; final int pid = 5678; mNotifier.onWakeLockReleased(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback); mNotifier.onWakeLockAcquired(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback); mNotifier.onWakeLockChanging(PowerManager.PARTIAL_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* workSource= */ null, /* historyTag= */ null, exceptingCallback, PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "wakelockTag", "my.package.name", uid, pid, /* newWorkSource= */ null, /* newHistoryTag= */ null, exceptingCallback); mTestLooper.dispatchAll(); // If we didn't throw, we're good! } private final PowerManagerService.Injector mInjector = new PowerManagerService.Injector() { @Override Notifier createNotifier(Looper looper, Context context, IBatteryStats batteryStats, Loading