Merge "Don't throw Exception when WakeLockListener throws DeadObject." into udc-dev am: 20c31b7b20

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

Change-Id: I2afb85a4d37e6e6a1bec17363305d30df4350c15
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Santos Cordon
2023-05-24 10:14:46 +00:00
committed by Automerger Merge Worker
2 changed files with 35 additions and 4 deletions

View File

@@ -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);
}
});
}

View File

@@ -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,