Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d751ad2 authored by Santos Cordon's avatar Santos Cordon Committed by Automerger Merge Worker
Browse files

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

parents ea5c0e32 20c31b7b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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);
                }
            });
        }
+31 −0
Original line number Diff line number Diff line
@@ -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,