summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Santos Cordon <santoscordon@google.com> 2023-05-24 09:55:29 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-05-24 09:55:29 +0000
commit20c31b7b209a1dde2de42ded6ff866d0798e76a1 (patch)
treec6a2cd75609663ccad7d8ebe446c97b12468b3d2
parent3b585fc1f965fcae7708c962ae90f021ccafe4a8 (diff)
parenta7ef27000839b0e7acf13c67ca5607f8c7005b90 (diff)
Merge "Don't throw Exception when WakeLockListener throws DeadObject." into udc-dev
-rw-r--r--services/core/java/com/android/server/power/Notifier.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/power/NotifierTest.java31
2 files changed, 35 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index 9bc0ee224ce0..a694e315ac29 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -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 {
@@ -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 {
@@ -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);
}
});
}
diff --git a/services/tests/servicestests/src/com/android/server/power/NotifierTest.java b/services/tests/servicestests/src/com/android/server/power/NotifierTest.java
index 849aae29aca0..2f039654ca7e 100644
--- a/services/tests/servicestests/src/com/android/server/power/NotifierTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/NotifierTest.java
@@ -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;
@@ -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,