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

Commit 480f21bd authored by Jeff Davidson's avatar Jeff Davidson
Browse files

Unregister pending listeners in UiccProfile#dispose.

When the profile is brought up, if the device is not provisioned or
the user is not unlocked, UiccProfile registers listeners for these
events. Once the event is received, the corresponding listener is
unregistered. However, it's possible that the profile is disposed
(e.g. the SIM removed) prior to the event occuring. In this case, the
listener would remain present; if a new SIM were inserted, it would be
re-registered, likely causing adverse behavior.

Ensure that any registered listeners are unregistered when a
UiccProfile is disposed, even if the event has not yet occurred.

Bug: 134530854
Test: Validated crash fix when removing SIM before unlock
Change-Id: I00a6735229b9b91a17f4dc4e9bb092e94b73304f
parent fa4ac334
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -141,18 +141,26 @@ public class UiccProfile extends IccCard {
            new ContentObserver(new Handler()) {
                @Override
                public void onChange(boolean selfChange) {
                    synchronized (mLock) {
                        mContext.getContentResolver().unregisterContentObserver(this);
                        mProvisionCompleteContentObserverRegistered = false;
                        showCarrierAppNotificationsIfPossible();
                    }
                }
            };
    private boolean mProvisionCompleteContentObserverRegistered;

    private final BroadcastReceiver mUserUnlockReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            synchronized (mLock) {
                mContext.unregisterReceiver(this);
                mUserUnlockReceiverRegistered = false;
                showCarrierAppNotificationsIfPossible();
            }
        }
    };
    private boolean mUserUnlockReceiverRegistered;

    private final BroadcastReceiver mCarrierConfigChangedReceiver = new BroadcastReceiver() {
        @Override
@@ -277,6 +285,17 @@ public class UiccProfile extends IccCard {
            unregisterAllAppEvents();
            unregisterCurrAppEvents();

            if (mProvisionCompleteContentObserverRegistered) {
                mContext.getContentResolver()
                        .unregisterContentObserver(mProvisionCompleteContentObserver);
                mProvisionCompleteContentObserverRegistered = false;
            }

            if (mUserUnlockReceiverRegistered) {
                mContext.unregisterReceiver(mUserUnlockReceiver);
                mUserUnlockReceiverRegistered = false;
            }

            InstallCarrierAppUtils.hideAllNotifications(mContext);
            InstallCarrierAppUtils.unregisterPackageInstallReceiver(mContext);

@@ -1212,10 +1231,12 @@ public class UiccProfile extends IccCard {
                            uri,
                            false,
                            mProvisionCompleteContentObserver);
                    mProvisionCompleteContentObserverRegistered = true;
                }
                if (!isUnlocked) {
                    mContext.registerReceiver(
                            mUserUnlockReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
                    mUserUnlockReceiverRegistered = true;
                }
            }
        }