Loading src/java/com/android/internal/telephony/MultiSimSettingController.java +36 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID; import android.annotation.IntDef; import android.annotation.NonNull; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -40,6 +41,7 @@ import android.provider.Settings.SettingNotFoundException; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccManager; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -261,6 +263,7 @@ public class MultiSimSettingController extends Handler { mSubInfoInitialized = true; updateDefaults(/*init*/ true); disableDataForNonDefaultNonOpportunisticSubscriptions(); deactivateGroupedOpportunisticSubscriptionIfNeeded(); } /** Loading @@ -273,6 +276,7 @@ public class MultiSimSettingController extends Handler { if (!mSubInfoInitialized) return; updateDefaults(/*init*/ false); disableDataForNonDefaultNonOpportunisticSubscriptions(); deactivateGroupedOpportunisticSubscriptionIfNeeded(); } /** Loading Loading @@ -654,6 +658,38 @@ public class MultiSimSettingController extends Handler { return SubscriptionManager.isValidSubscriptionId(newValue); } // When a primary and its grouped opportunistic subscriptions were active, and the primary // subscription gets deactivated or removed, we need to automatically disable the grouped // opportunistic subscription, which will be marked isGroupDisabled as true by SubController. private void deactivateGroupedOpportunisticSubscriptionIfNeeded() { if (!SubscriptionInfoUpdater.isSubInfoInitialized()) return; List<SubscriptionInfo> opptSubList = mSubController.getOpportunisticSubscriptions( mContext.getOpPackageName()); if (ArrayUtils.isEmpty(opptSubList)) return; for (SubscriptionInfo info : opptSubList) { if (info.isGroupDisabled() && mSubController.isActiveSubId(info.getSubscriptionId())) { log("[deactivateGroupedOpptSubIfNeeded] " + "Deactivating grouped opportunistic subscription " + info.getSubscriptionId()); deactivateSubscription(info); } } } private void deactivateSubscription(SubscriptionInfo info) { // TODO: b/133379187 have a way to deactivate pSIM. if (info.isEmbedded()) { log("[deactivateSubscription] eSIM profile " + info.getSubscriptionId()); EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); euiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, PendingIntent.getService(mContext, 0, new Intent(), 0)); } } private void log(String msg) { Log.d(LOG_TAG, msg); } Loading src/java/com/android/internal/telephony/SubscriptionController.java +11 −26 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; /** Loading Loading @@ -114,6 +115,7 @@ public class SubscriptionController extends ISub.Stub { /* Similar to mCacheActiveSubInfoList but only caching opportunistic subscriptions. */ private List<SubscriptionInfo> mCacheOpportunisticSubInfoList = new ArrayList<>(); private AtomicBoolean mOpptSubInfoListChangedDirtyBit = new AtomicBoolean(); private static final Comparator<SubscriptionInfo> SUBSCRIPTION_INFO_COMPARATOR = (arg0, arg1) -> { Loading Loading @@ -303,6 +305,10 @@ public class SubscriptionController extends ISub.Stub { synchronized (mSubInfoListLock) { subInfos = new ArrayList<>(mCacheActiveSubInfoList); } if (mOpptSubInfoListChangedDirtyBit.getAndSet(false)) { notifyOpportunisticSubscriptionInfoChanged(); } metrics.updateActiveSubscriptionInfoList(subInfos); } Loading Loading @@ -717,7 +723,7 @@ public class SubscriptionController extends ISub.Stub { } // Refresh cached opportunistic sub list and detect whether it's changed. opptSubListChanged = refreshCachedOpportunisticSubscriptionInfoList(); refreshCachedOpportunisticSubscriptionInfoList(); if (DBG_CACHE) { if (!mCacheActiveSubInfoList.isEmpty()) { Loading @@ -730,11 +736,6 @@ public class SubscriptionController extends ISub.Stub { } } } // Send notification outside synchronization. if (opptSubListChanged) { notifyOpportunisticSubscriptionInfoChanged(); } } /** Loading Loading @@ -3612,7 +3613,7 @@ public class SubscriptionController extends ISub.Stub { } } private boolean refreshCachedOpportunisticSubscriptionInfoList() { private void refreshCachedOpportunisticSubscriptionInfoList() { synchronized (mSubInfoListLock) { List<SubscriptionInfo> oldOpptCachedList = mCacheOpportunisticSubInfoList; Loading @@ -3632,13 +3633,6 @@ public class SubscriptionController extends ISub.Stub { for (SubscriptionInfo info : mCacheOpportunisticSubInfoList) { if (shouldDisableSubGroup(info.getGroupUuid())) { info.setGroupDisabled(true); // TODO: move it to ONS. if (isActiveSubId(info.getSubscriptionId()) && isSubInfoReady()) { logd("[refreshCachedOpportunisticSubscriptionInfoList] " + "Deactivating grouped opportunistic subscription " + info.getSubscriptionId()); deactivateSubscription(info); } } } Loading @@ -3653,7 +3647,9 @@ public class SubscriptionController extends ISub.Stub { } } return !oldOpptCachedList.equals(mCacheOpportunisticSubInfoList); if (!oldOpptCachedList.equals(mCacheOpportunisticSubInfoList)) { mOpptSubInfoListChangedDirtyBit.set(true); } } } Loading @@ -3669,17 +3665,6 @@ public class SubscriptionController extends ISub.Stub { return true; } private void deactivateSubscription(SubscriptionInfo info) { // TODO: b/120439488 deactivate pSIM. if (info.isEmbedded()) { logd("[deactivateSubscription] eSIM profile " + info.getSubscriptionId()); EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); euiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, PendingIntent.getService(mContext, 0, new Intent(), 0)); } } // TODO: This method should belong to Telephony manager like other data enabled settings and // override APIs. Remove this once TelephonyManager API is added. @Override Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -814,6 +814,7 @@ public class SubscriptionControllerTest extends TelephonyTest { mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 2, null); mSubscriptionControllerUT.refreshCachedActiveSubscriptionInfoList(); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(1)) .notifyOpportunisticSubscriptionInfoChanged(); Loading @@ -824,6 +825,7 @@ public class SubscriptionControllerTest extends TelephonyTest { subIdList, mContext.getOpPackageName()); assertNotEquals(null, groupId); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(2)) .notifyOpportunisticSubscriptionInfoChanged(); List<SubscriptionInfo> opptSubList = mSubscriptionControllerUT Loading @@ -838,6 +840,7 @@ public class SubscriptionControllerTest extends TelephonyTest { mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 1, null); mSubscriptionControllerUT.refreshCachedActiveSubscriptionInfoList(); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(3)) .notifyOpportunisticSubscriptionInfoChanged(); Loading Loading
src/java/com/android/internal/telephony/MultiSimSettingController.java +36 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID; import android.annotation.IntDef; import android.annotation.NonNull; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -40,6 +41,7 @@ import android.provider.Settings.SettingNotFoundException; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.euicc.EuiccManager; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -261,6 +263,7 @@ public class MultiSimSettingController extends Handler { mSubInfoInitialized = true; updateDefaults(/*init*/ true); disableDataForNonDefaultNonOpportunisticSubscriptions(); deactivateGroupedOpportunisticSubscriptionIfNeeded(); } /** Loading @@ -273,6 +276,7 @@ public class MultiSimSettingController extends Handler { if (!mSubInfoInitialized) return; updateDefaults(/*init*/ false); disableDataForNonDefaultNonOpportunisticSubscriptions(); deactivateGroupedOpportunisticSubscriptionIfNeeded(); } /** Loading Loading @@ -654,6 +658,38 @@ public class MultiSimSettingController extends Handler { return SubscriptionManager.isValidSubscriptionId(newValue); } // When a primary and its grouped opportunistic subscriptions were active, and the primary // subscription gets deactivated or removed, we need to automatically disable the grouped // opportunistic subscription, which will be marked isGroupDisabled as true by SubController. private void deactivateGroupedOpportunisticSubscriptionIfNeeded() { if (!SubscriptionInfoUpdater.isSubInfoInitialized()) return; List<SubscriptionInfo> opptSubList = mSubController.getOpportunisticSubscriptions( mContext.getOpPackageName()); if (ArrayUtils.isEmpty(opptSubList)) return; for (SubscriptionInfo info : opptSubList) { if (info.isGroupDisabled() && mSubController.isActiveSubId(info.getSubscriptionId())) { log("[deactivateGroupedOpptSubIfNeeded] " + "Deactivating grouped opportunistic subscription " + info.getSubscriptionId()); deactivateSubscription(info); } } } private void deactivateSubscription(SubscriptionInfo info) { // TODO: b/133379187 have a way to deactivate pSIM. if (info.isEmbedded()) { log("[deactivateSubscription] eSIM profile " + info.getSubscriptionId()); EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); euiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, PendingIntent.getService(mContext, 0, new Intent(), 0)); } } private void log(String msg) { Log.d(LOG_TAG, msg); } Loading
src/java/com/android/internal/telephony/SubscriptionController.java +11 −26 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; /** Loading Loading @@ -114,6 +115,7 @@ public class SubscriptionController extends ISub.Stub { /* Similar to mCacheActiveSubInfoList but only caching opportunistic subscriptions. */ private List<SubscriptionInfo> mCacheOpportunisticSubInfoList = new ArrayList<>(); private AtomicBoolean mOpptSubInfoListChangedDirtyBit = new AtomicBoolean(); private static final Comparator<SubscriptionInfo> SUBSCRIPTION_INFO_COMPARATOR = (arg0, arg1) -> { Loading Loading @@ -303,6 +305,10 @@ public class SubscriptionController extends ISub.Stub { synchronized (mSubInfoListLock) { subInfos = new ArrayList<>(mCacheActiveSubInfoList); } if (mOpptSubInfoListChangedDirtyBit.getAndSet(false)) { notifyOpportunisticSubscriptionInfoChanged(); } metrics.updateActiveSubscriptionInfoList(subInfos); } Loading Loading @@ -717,7 +723,7 @@ public class SubscriptionController extends ISub.Stub { } // Refresh cached opportunistic sub list and detect whether it's changed. opptSubListChanged = refreshCachedOpportunisticSubscriptionInfoList(); refreshCachedOpportunisticSubscriptionInfoList(); if (DBG_CACHE) { if (!mCacheActiveSubInfoList.isEmpty()) { Loading @@ -730,11 +736,6 @@ public class SubscriptionController extends ISub.Stub { } } } // Send notification outside synchronization. if (opptSubListChanged) { notifyOpportunisticSubscriptionInfoChanged(); } } /** Loading Loading @@ -3612,7 +3613,7 @@ public class SubscriptionController extends ISub.Stub { } } private boolean refreshCachedOpportunisticSubscriptionInfoList() { private void refreshCachedOpportunisticSubscriptionInfoList() { synchronized (mSubInfoListLock) { List<SubscriptionInfo> oldOpptCachedList = mCacheOpportunisticSubInfoList; Loading @@ -3632,13 +3633,6 @@ public class SubscriptionController extends ISub.Stub { for (SubscriptionInfo info : mCacheOpportunisticSubInfoList) { if (shouldDisableSubGroup(info.getGroupUuid())) { info.setGroupDisabled(true); // TODO: move it to ONS. if (isActiveSubId(info.getSubscriptionId()) && isSubInfoReady()) { logd("[refreshCachedOpportunisticSubscriptionInfoList] " + "Deactivating grouped opportunistic subscription " + info.getSubscriptionId()); deactivateSubscription(info); } } } Loading @@ -3653,7 +3647,9 @@ public class SubscriptionController extends ISub.Stub { } } return !oldOpptCachedList.equals(mCacheOpportunisticSubInfoList); if (!oldOpptCachedList.equals(mCacheOpportunisticSubInfoList)) { mOpptSubInfoListChangedDirtyBit.set(true); } } } Loading @@ -3669,17 +3665,6 @@ public class SubscriptionController extends ISub.Stub { return true; } private void deactivateSubscription(SubscriptionInfo info) { // TODO: b/120439488 deactivate pSIM. if (info.isEmbedded()) { logd("[deactivateSubscription] eSIM profile " + info.getSubscriptionId()); EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); euiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, PendingIntent.getService(mContext, 0, new Intent(), 0)); } } // TODO: This method should belong to Telephony manager like other data enabled settings and // override APIs. Remove this once TelephonyManager API is added. @Override Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -814,6 +814,7 @@ public class SubscriptionControllerTest extends TelephonyTest { mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 2, null); mSubscriptionControllerUT.refreshCachedActiveSubscriptionInfoList(); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(1)) .notifyOpportunisticSubscriptionInfoChanged(); Loading @@ -824,6 +825,7 @@ public class SubscriptionControllerTest extends TelephonyTest { subIdList, mContext.getOpPackageName()); assertNotEquals(null, groupId); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(2)) .notifyOpportunisticSubscriptionInfoChanged(); List<SubscriptionInfo> opptSubList = mSubscriptionControllerUT Loading @@ -838,6 +840,7 @@ public class SubscriptionControllerTest extends TelephonyTest { mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values, SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 1, null); mSubscriptionControllerUT.refreshCachedActiveSubscriptionInfoList(); mSubscriptionControllerUT.notifySubscriptionInfoChanged(); verify(mTelephonyRegisteryMock, times(3)) .notifyOpportunisticSubscriptionInfoChanged(); Loading