Don't throw Exception when WakeLockListener throws DeadObject.
Bug: 282428078 Test: atest Notifier, atest com.android.server.power Change-Id: I0f66aee547595dad35eb9eff2e5a5e3f8afba269
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user