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

Commit e305baa0 authored by Wileen Chiu's avatar Wileen Chiu
Browse files

TelephonyRegistry: Avoid adding duplicate listener

- Currently, a new callback is created when a listener
  is passed in, so it is possible to create multiple
  callbacks for the same listener
- However, when removing the listener, only the latest
  entry is removed, which could result in improper cleanup
- If a listener is already in the map, do not add the listener
  with the new callback

Change-Id: I46f344eb55db38916224f7765cd838347ac8f0f2
Bug: 168886894
parent 7fb5deb7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -104,6 +104,10 @@ public class TelephonyRegistryManager {
    public void addOnSubscriptionsChangedListener(
            @NonNull SubscriptionManager.OnSubscriptionsChangedListener listener,
            @NonNull Executor executor) {
        if (mSubscriptionChangedListenerMap.get(listener) != null) {
            Log.d(TAG, "addOnSubscriptionsChangedListener listener already present");
            return;
        }
        IOnSubscriptionsChangedListener callback = new IOnSubscriptionsChangedListener.Stub() {
            @Override
            public void onSubscriptionsChanged () {
@@ -153,6 +157,10 @@ public class TelephonyRegistryManager {
    public void addOnOpportunisticSubscriptionsChangedListener(
            @NonNull SubscriptionManager.OnOpportunisticSubscriptionsChangedListener listener,
            @NonNull Executor executor) {
        if (mOpportunisticSubscriptionChangedListenerMap.get(listener) != null) {
            Log.d(TAG, "addOnOpportunisticSubscriptionsChangedListener listener already present");
            return;
        }
        /**
         * The callback methods need to be called on the executor thread where
         * this object was created.  If the binder did that for us it'd be nice.
@@ -188,6 +196,9 @@ public class TelephonyRegistryManager {
     */
    public void removeOnOpportunisticSubscriptionsChangedListener(
            @NonNull SubscriptionManager.OnOpportunisticSubscriptionsChangedListener listener) {
        if (mOpportunisticSubscriptionChangedListenerMap.get(listener) == null) {
            return;
        }
        try {
            sRegistry.removeOnSubscriptionsChangedListener(mContext.getOpPackageName(),
                    mOpportunisticSubscriptionChangedListenerMap.get(listener));