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

Commit b4da4f36 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Unlink listener death recipient on alarms

Stopped using BinderDeathDispatcher as deduping is no longer required.
If an app sets the same listener, it is first removed internally which
will result in a call to unlink before the subsequent call to set.

Test: Manually using a test app that cancels and sets an alarm with a
new listener instance in a loop.
atest CtsAlarmManagerTestCases:BasicApiTests

Bug: 189091551
Change-Id: I390d9bba37a4040b7e789e0ae04f9980fbed5c12
parent 4c50f57a
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsService;
import com.android.internal.os.BinderDeathDispatcher;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.LocalLog;
@@ -206,8 +205,6 @@ public class AlarmManagerService extends SystemService {
                    .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
                            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);

    private static final BinderDeathDispatcher<IAlarmListener> sListenerDeathDispatcher =
            new BinderDeathDispatcher<>();
    final LocalLog mLog = new LocalLog(TAG);

    AppOpsManager mAppOps;
@@ -1837,8 +1834,9 @@ public class AlarmManagerService extends SystemService {
        }

        if (directReceiver != null) {
            if (sListenerDeathDispatcher.linkToDeath(directReceiver, mListenerDeathRecipient)
                    <= 0) {
            try {
                directReceiver.asBinder().linkToDeath(mListenerDeathRecipient, 0);
            } catch (RemoteException e) {
                Slog.w(TAG, "Dropping unreachable alarm listener " + listenerTag);
                return;
            }
@@ -2851,12 +2849,6 @@ public class AlarmManagerService extends SystemService {
                pw.println();
            }

            pw.println("Listener death dispatcher state:");
            pw.increaseIndent();
            sListenerDeathDispatcher.dump(pw);
            pw.println();
            pw.decreaseIndent();

            if (mLog.dump(pw, "Recent problems:")) {
                pw.println();
            }
@@ -3448,6 +3440,9 @@ public class AlarmManagerService extends SystemService {

        for (final Alarm removed : removedAlarms) {
            decrementAlarmCount(removed.uid, 1);
            if (removed.listener != null) {
                removed.listener.asBinder().unlinkToDeath(mListenerDeathRecipient, 0);
            }
            if (!RemovedAlarm.isLoggable(reason)) {
                continue;
            }
@@ -4701,6 +4696,8 @@ public class AlarmManagerService extends SystemService {
                    // Direct listener callback alarm
                    mListenerCount++;

                    alarm.listener.asBinder().unlinkToDeath(mListenerDeathRecipient, 0);

                    if (RECORD_ALARMS_IN_HISTORY) {
                        if (alarm.listener == mTimeTickTrigger) {
                            mTickHistory[mNextTickHistory++] = nowELAPSED;