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

Commit 8ea004e8 authored by joonhunshin's avatar joonhunshin Committed by Joonhun Shin
Browse files

Notify SIM removed event

Notify SIM removed event from Ims framework to ImsService.
ImsService transfers the event to ImsConfigImplbase for reset the cached data.
Bug: 221080692
Bug: 205746476
Test: atest ImsResolverTest, ImsServiceControllerTest
Test: manual
1. Turn on a device and wifi connected with fake SIM
2. Remove fake SIM
3. Insert VZW US SIM
4. Remove VZW US SIM
5. Insert fake SIM
6. Check if phone crash on logs

Change-Id: Ic5e4d846cdff82eeb27ab51897654428da1b5023
parent e41cd54b
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -490,6 +490,9 @@ public class ImsService extends Service {
    }

    private void removeImsFeature(int slotId, int featureType) {
        // clear cached data
        notifySubscriptionRemoved(slotId);

        synchronized (mFeaturesBySlot) {
            // get ImsFeature associated with the slot/feature
            SparseArray<ImsFeature> features = mFeaturesBySlot.get(slotId);
@@ -507,7 +510,6 @@ public class ImsService extends Service {
            f.onFeatureRemoved();
            features.remove(featureType);
        }

    }

    /**
@@ -628,6 +630,24 @@ public class ImsService extends Service {
        disableIms(slotId);
    }

    /**
     * The subscription has removed. The ImsService should notify ImsRegistrationImplBase and
     * ImsConfigImplBase the SIM state was changed.
     * @param slotId The slot ID which has removed.
     */
    private void notifySubscriptionRemoved(int slotId) {
        ImsRegistrationImplBase registrationImplBase =
                getRegistration(slotId);
        if (registrationImplBase != null) {
            registrationImplBase.clearRegistrationCache();
        }

        ImsConfigImplBase imsConfigImplBase = getConfig(slotId);
        if (imsConfigImplBase != null) {
            imsConfigImplBase.clearConfigurationCache();
        }
    }

    /**
     * The framework has enabled IMS for the slot specified, the ImsService should register for IMS
     * and perform all appropriate initialization to bring up all ImsFeatures.
+51 −11
Original line number Diff line number Diff line
@@ -481,6 +481,17 @@ public class ImsConfigImplBase {
            }
        }

        /**
         * Clear cached configuration value.
         */
        public void clearCachedValue() {
            Log.i(TAG, "clearCachedValue");
            synchronized (mLock) {
                mProvisionedIntValue.clear();
                mProvisionedStringValue.clear();
            }
        }

        // Call the methods with a clean calling identity on the executor and wait indefinitely for
        // the future to return.
        private void executeMethodAsync(Runnable r, String errorLogName) throws RemoteException {
@@ -538,6 +549,7 @@ public class ImsConfigImplBase {
    private final RemoteCallbackListExt<IRcsConfigCallback> mRcsCallbacks =
            new RemoteCallbackListExt<>();
    private byte[] mRcsConfigData;
    private final Object mRcsConfigDataLock = new Object();
    ImsConfigStub mImsConfigStub;

    /**
@@ -616,14 +628,22 @@ public class ImsConfigImplBase {

    private void addRcsConfigCallback(IRcsConfigCallback c) {
        mRcsCallbacks.register(c);
        if (mRcsConfigData != null) {

        // This is used to avoid calling the binder out of the synchronized scope.
        byte[] cloneRcsConfigData;
        synchronized (mRcsConfigDataLock) {
            if (mRcsConfigData == null) {
                return;
            }
            cloneRcsConfigData = mRcsConfigData.clone();
        }

        try {
                c.onConfigurationChanged(mRcsConfigData);
            c.onConfigurationChanged(cloneRcsConfigData);
        } catch (RemoteException e) {
            Log.w(TAG, "dead binder to call onConfigurationChanged, skipping.");
        }
    }
    }

    private void removeRcsConfigCallback(IRcsConfigCallback c) {
        mRcsCallbacks.unregister(c);
@@ -631,18 +651,23 @@ public class ImsConfigImplBase {

    private void onNotifyRcsAutoConfigurationReceived(byte[] config, boolean isCompressed) {
        // cache uncompressed config
        config = isCompressed ? RcsConfig.decompressGzip(config) : config;
        final byte[] rcsConfigData = isCompressed ? RcsConfig.decompressGzip(config) : config;

        synchronized (mRcsConfigDataLock) {
            if (Arrays.equals(mRcsConfigData, config)) {
                return;
            }
        mRcsConfigData = config;
            mRcsConfigData = rcsConfigData;
        }

        // can be null in testing
        if (mRcsCallbacks != null) {
            synchronized (mRcsCallbacks) {
                mRcsCallbacks.broadcastAction(c -> {
                    try {
                        c.onConfigurationChanged(mRcsConfigData);
                        // config is cloned here so modifications to the config passed to the
                        // vendor do not accidentally modify the cache.
                        c.onConfigurationChanged(rcsConfigData.clone());
                    } catch (RemoteException e) {
                        Log.w(TAG, "dead binder in notifyRcsAutoConfigurationReceived, skipping.");
                    }
@@ -653,7 +678,9 @@ public class ImsConfigImplBase {
    }

    private void onNotifyRcsAutoConfigurationRemoved() {
        synchronized (mRcsConfigDataLock) {
            mRcsConfigData = null;
        }
        if (mRcsCallbacks != null) {
            synchronized (mRcsCallbacks) {
                mRcsCallbacks.broadcastAction(c -> {
@@ -857,4 +884,17 @@ public class ImsConfigImplBase {
            mImsConfigStub.mExecutor = executor;
        }
    }

    /**
     * Clear all cached config data. This will be called when the config data is no longer valid
     * such as when the SIM was removed.
     * @hide
     */
    public final void clearConfigurationCache() {
        mImsConfigStub.clearCachedValue();

        synchronized (mRcsConfigDataLock) {
            mRcsConfigData = null;
        }
    }
}