Loading src/com/android/server/telecom/PhoneAccountRegistrar.java +47 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telephony.CarrierConfigManager; import android.telephony.PhoneNumberUtils; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; Loading Loading @@ -1413,7 +1414,7 @@ public class PhoneAccountRegistrar { public final UserHandle userHandle; public final PhoneAccountHandle phoneAccountHandle; public PhoneAccountHandle phoneAccountHandle; public final String groupId; Loading Loading @@ -1555,6 +1556,7 @@ public class PhoneAccountRegistrar { XmlPullParser parser = Xml.resolvePullParser(is); parser.nextTag(); mState = readFromXml(parser, mContext); migratePhoneAccountHandle(mState); versionChanged = mState.versionNumber < EXPECTED_STATE_VERSION; } catch (IOException | XmlPullParserException e) { Loading Loading @@ -1599,6 +1601,50 @@ public class PhoneAccountRegistrar { return s != null ? s : new State(); } /** * Try to migrate the ID of default phone account handle from IccId to SubId. */ @VisibleForTesting public void migratePhoneAccountHandle(State state) { if (mSubscriptionManager == null) { return; } // Use getAllSubscirptionInfoList() to get the mapping between iccId and subId // from the subscription database List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager .getAllSubscriptionInfoList(); Map<UserHandle, DefaultPhoneAccountHandle> defaultPhoneAccountHandles = state.defaultOutgoingAccountHandles; for (Map.Entry<UserHandle, DefaultPhoneAccountHandle> entry : defaultPhoneAccountHandles.entrySet()) { DefaultPhoneAccountHandle defaultPhoneAccountHandle = entry.getValue(); // Migrate Telephony PhoneAccountHandle only String telephonyComponentName = "com.android.phone/com.android.services.telephony.TelephonyConnectionService"; if (!defaultPhoneAccountHandle.phoneAccountHandle.getComponentName() .flattenToString().equals(telephonyComponentName)) { continue; } // Migrate from IccId to SubId for (SubscriptionInfo subscriptionInfo : subscriptionInfos) { String phoneAccountHandleId = defaultPhoneAccountHandle.phoneAccountHandle.getId(); // Some phone account handle would store phone account handle id with the IccId // string plus "F", and the getIccId() returns IccId string itself without "F", // so here need to use "startsWith" to match. if (phoneAccountHandleId != null && phoneAccountHandleId.startsWith( subscriptionInfo.getIccId())) { Log.i(this, "Found subscription ID to migrate: " + subscriptionInfo.getSubscriptionId()); defaultPhoneAccountHandle.phoneAccountHandle = new PhoneAccountHandle( defaultPhoneAccountHandle.phoneAccountHandle.getComponentName(), Integer.toString(subscriptionInfo.getSubscriptionId())); break; } } } } //////////////////////////////////////////////////////////////////////////////////////////////// // // XML serialization Loading tests/src/com/android/server/telecom/tests/ComponentContextFixture.java +5 −1 Original line number Diff line number Diff line Loading @@ -540,7 +540,7 @@ public class ComponentContextFixture implements TestFixture<Context> { private final NotificationManager mNotificationManager = mock(NotificationManager.class); private final UserManager mUserManager = mock(UserManager.class); private final StatusBarManager mStatusBarManager = mock(StatusBarManager.class); private final SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private final CarrierConfigManager mCarrierConfigManager = mock(CarrierConfigManager.class); private final CountryDetector mCountryDetector = mock(CountryDetector.class); private final Map<String, IContentProvider> mIContentProviderByUri = new HashMap<>(); Loading Loading @@ -735,6 +735,10 @@ public class ComponentContextFixture implements TestFixture<Context> { mTelecomManager = telecomManager; } public void setSubscriptionManager(SubscriptionManager subscriptionManager) { mSubscriptionManager = subscriptionManager; } public TelephonyManager getTelephonyManager() { return mTelephonyManager; } Loading tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.MediumTest; import android.util.Xml; Loading Loading @@ -83,6 +85,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; Loading @@ -98,6 +101,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { private final String COMPONENT_NAME = "com.android.server.telecom.tests.MockConnectionService"; private final TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { }; private PhoneAccountRegistrar mRegistrar; @Mock private SubscriptionManager mSubscriptionManager; @Mock private TelecomManager mTelecomManager; @Mock private DefaultDialerCache mDefaultDialerCache; @Mock private AppLabelProxy mAppLabelProxy; Loading @@ -108,6 +112,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { super.setUp(); MockitoAnnotations.initMocks(this); mComponentContextFixture.setTelecomManager(mTelecomManager); mComponentContextFixture.setSubscriptionManager(mSubscriptionManager); new File( mComponentContextFixture.getTestDouble().getApplicationContext().getFilesDir(), FILE_NAME) Loading Loading @@ -1226,6 +1231,29 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { clearInvocations(mComponentContextFixture.getTelephonyManager()); } /** * Test PhoneAccountHandle Migration Logic. */ @Test public void testPhoneAccountMigration() throws Exception { PhoneAccountRegistrar.State testState = makeQuickStateWithTelephonyPhoneAccountHandle(); final int mTestPhoneAccountHandleSubIdInt = 123; // Mock SubscriptionManager SubscriptionInfo subscriptionInfo = new SubscriptionInfo( mTestPhoneAccountHandleSubIdInt, "id0", 1, "a", "b", 1, 1, "test", 1, null, null, null, null, false, null, null); List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>(); subscriptionInfoList.add(subscriptionInfo); when(mSubscriptionManager.getAllSubscriptionInfoList()).thenReturn(subscriptionInfoList); mRegistrar.migratePhoneAccountHandle(testState); Collection<DefaultPhoneAccountHandle> defaultPhoneAccountHandles = testState.defaultOutgoingAccountHandles.values(); DefaultPhoneAccountHandle defaultPhoneAccountHandle = defaultPhoneAccountHandles.iterator().next(); assertEquals(Integer.toString(mTestPhoneAccountHandleSubIdInt), defaultPhoneAccountHandle.phoneAccountHandle.getId()); } private static ComponentName makeQuickConnectionServiceComponentName() { return new ComponentName( "com.android.server.telecom.tests", Loading Loading @@ -1447,6 +1475,25 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { } } private PhoneAccountRegistrar.State makeQuickStateWithTelephonyPhoneAccountHandle() { PhoneAccountRegistrar.State s = new PhoneAccountRegistrar.State(); s.accounts.add(makeQuickAccount("id0", 0)); s.accounts.add(makeQuickAccount("id1", 1)); s.accounts.add(makeQuickAccount("id2", 2)); PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new ComponentName( "com.android.phone", "com.android.services.telephony.TelephonyConnectionService"), "id0"); UserHandle userHandle = phoneAccountHandle.getUserHandle(); when(UserManager.get(mContext).getSerialNumberForUser(userHandle)) .thenReturn(0L); when(UserManager.get(mContext).getUserForSerialNumber(0L)) .thenReturn(userHandle); s.defaultOutgoingAccountHandles .put(userHandle, new DefaultPhoneAccountHandle(userHandle, phoneAccountHandle, "testGroup")); return s; } private PhoneAccountRegistrar.State makeQuickState() { PhoneAccountRegistrar.State s = new PhoneAccountRegistrar.State(); s.accounts.add(makeQuickAccount("id0", 0)); Loading Loading
src/com/android/server/telecom/PhoneAccountRegistrar.java +47 −1 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telephony.CarrierConfigManager; import android.telephony.PhoneNumberUtils; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; Loading Loading @@ -1413,7 +1414,7 @@ public class PhoneAccountRegistrar { public final UserHandle userHandle; public final PhoneAccountHandle phoneAccountHandle; public PhoneAccountHandle phoneAccountHandle; public final String groupId; Loading Loading @@ -1555,6 +1556,7 @@ public class PhoneAccountRegistrar { XmlPullParser parser = Xml.resolvePullParser(is); parser.nextTag(); mState = readFromXml(parser, mContext); migratePhoneAccountHandle(mState); versionChanged = mState.versionNumber < EXPECTED_STATE_VERSION; } catch (IOException | XmlPullParserException e) { Loading Loading @@ -1599,6 +1601,50 @@ public class PhoneAccountRegistrar { return s != null ? s : new State(); } /** * Try to migrate the ID of default phone account handle from IccId to SubId. */ @VisibleForTesting public void migratePhoneAccountHandle(State state) { if (mSubscriptionManager == null) { return; } // Use getAllSubscirptionInfoList() to get the mapping between iccId and subId // from the subscription database List<SubscriptionInfo> subscriptionInfos = mSubscriptionManager .getAllSubscriptionInfoList(); Map<UserHandle, DefaultPhoneAccountHandle> defaultPhoneAccountHandles = state.defaultOutgoingAccountHandles; for (Map.Entry<UserHandle, DefaultPhoneAccountHandle> entry : defaultPhoneAccountHandles.entrySet()) { DefaultPhoneAccountHandle defaultPhoneAccountHandle = entry.getValue(); // Migrate Telephony PhoneAccountHandle only String telephonyComponentName = "com.android.phone/com.android.services.telephony.TelephonyConnectionService"; if (!defaultPhoneAccountHandle.phoneAccountHandle.getComponentName() .flattenToString().equals(telephonyComponentName)) { continue; } // Migrate from IccId to SubId for (SubscriptionInfo subscriptionInfo : subscriptionInfos) { String phoneAccountHandleId = defaultPhoneAccountHandle.phoneAccountHandle.getId(); // Some phone account handle would store phone account handle id with the IccId // string plus "F", and the getIccId() returns IccId string itself without "F", // so here need to use "startsWith" to match. if (phoneAccountHandleId != null && phoneAccountHandleId.startsWith( subscriptionInfo.getIccId())) { Log.i(this, "Found subscription ID to migrate: " + subscriptionInfo.getSubscriptionId()); defaultPhoneAccountHandle.phoneAccountHandle = new PhoneAccountHandle( defaultPhoneAccountHandle.phoneAccountHandle.getComponentName(), Integer.toString(subscriptionInfo.getSubscriptionId())); break; } } } } //////////////////////////////////////////////////////////////////////////////////////////////// // // XML serialization Loading
tests/src/com/android/server/telecom/tests/ComponentContextFixture.java +5 −1 Original line number Diff line number Diff line Loading @@ -540,7 +540,7 @@ public class ComponentContextFixture implements TestFixture<Context> { private final NotificationManager mNotificationManager = mock(NotificationManager.class); private final UserManager mUserManager = mock(UserManager.class); private final StatusBarManager mStatusBarManager = mock(StatusBarManager.class); private final SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class); private final CarrierConfigManager mCarrierConfigManager = mock(CarrierConfigManager.class); private final CountryDetector mCountryDetector = mock(CountryDetector.class); private final Map<String, IContentProvider> mIContentProviderByUri = new HashMap<>(); Loading Loading @@ -735,6 +735,10 @@ public class ComponentContextFixture implements TestFixture<Context> { mTelecomManager = telecomManager; } public void setSubscriptionManager(SubscriptionManager subscriptionManager) { mSubscriptionManager = subscriptionManager; } public TelephonyManager getTelephonyManager() { return mTelephonyManager; } Loading
tests/src/com/android/server/telecom/tests/PhoneAccountRegistrarTest.java +47 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.MediumTest; import android.util.Xml; Loading Loading @@ -83,6 +85,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; Loading @@ -98,6 +101,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { private final String COMPONENT_NAME = "com.android.server.telecom.tests.MockConnectionService"; private final TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { }; private PhoneAccountRegistrar mRegistrar; @Mock private SubscriptionManager mSubscriptionManager; @Mock private TelecomManager mTelecomManager; @Mock private DefaultDialerCache mDefaultDialerCache; @Mock private AppLabelProxy mAppLabelProxy; Loading @@ -108,6 +112,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { super.setUp(); MockitoAnnotations.initMocks(this); mComponentContextFixture.setTelecomManager(mTelecomManager); mComponentContextFixture.setSubscriptionManager(mSubscriptionManager); new File( mComponentContextFixture.getTestDouble().getApplicationContext().getFilesDir(), FILE_NAME) Loading Loading @@ -1226,6 +1231,29 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { clearInvocations(mComponentContextFixture.getTelephonyManager()); } /** * Test PhoneAccountHandle Migration Logic. */ @Test public void testPhoneAccountMigration() throws Exception { PhoneAccountRegistrar.State testState = makeQuickStateWithTelephonyPhoneAccountHandle(); final int mTestPhoneAccountHandleSubIdInt = 123; // Mock SubscriptionManager SubscriptionInfo subscriptionInfo = new SubscriptionInfo( mTestPhoneAccountHandleSubIdInt, "id0", 1, "a", "b", 1, 1, "test", 1, null, null, null, null, false, null, null); List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>(); subscriptionInfoList.add(subscriptionInfo); when(mSubscriptionManager.getAllSubscriptionInfoList()).thenReturn(subscriptionInfoList); mRegistrar.migratePhoneAccountHandle(testState); Collection<DefaultPhoneAccountHandle> defaultPhoneAccountHandles = testState.defaultOutgoingAccountHandles.values(); DefaultPhoneAccountHandle defaultPhoneAccountHandle = defaultPhoneAccountHandles.iterator().next(); assertEquals(Integer.toString(mTestPhoneAccountHandleSubIdInt), defaultPhoneAccountHandle.phoneAccountHandle.getId()); } private static ComponentName makeQuickConnectionServiceComponentName() { return new ComponentName( "com.android.server.telecom.tests", Loading Loading @@ -1447,6 +1475,25 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase { } } private PhoneAccountRegistrar.State makeQuickStateWithTelephonyPhoneAccountHandle() { PhoneAccountRegistrar.State s = new PhoneAccountRegistrar.State(); s.accounts.add(makeQuickAccount("id0", 0)); s.accounts.add(makeQuickAccount("id1", 1)); s.accounts.add(makeQuickAccount("id2", 2)); PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new ComponentName( "com.android.phone", "com.android.services.telephony.TelephonyConnectionService"), "id0"); UserHandle userHandle = phoneAccountHandle.getUserHandle(); when(UserManager.get(mContext).getSerialNumberForUser(userHandle)) .thenReturn(0L); when(UserManager.get(mContext).getUserForSerialNumber(0L)) .thenReturn(userHandle); s.defaultOutgoingAccountHandles .put(userHandle, new DefaultPhoneAccountHandle(userHandle, phoneAccountHandle, "testGroup")); return s; } private PhoneAccountRegistrar.State makeQuickState() { PhoneAccountRegistrar.State s = new PhoneAccountRegistrar.State(); s.accounts.add(makeQuickAccount("id0", 0)); Loading