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

Commit 1f09c955 authored by Jeremy Goldman's avatar Jeremy Goldman Committed by Android (Google) Code Review
Browse files

Merge "Helper function to return the unique name for subscription info"

parents 844bfb36 67c75ac1
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -324,6 +324,23 @@ public class SubscriptionUtil {
        return displayNames.getOrDefault(subscriptionId, "");
    }

    /**
     * Return the display name for a subscription, which is guaranteed to be unique.
     * The logic to create this name has the following order of operations:
     * 1) If the original display name is not unique, the last four digits of the phone number
     *    will be appended.
     * 2) If the phone number is not visible or the last four digits are shared with another
     *    subscription, the subscription id will be appended to the original display name.
     * More details can be found at go/unique-sub-display-names.
     *
     * @return map of active subscription ids to diaplay names.
     */
    @VisibleForTesting
    public static CharSequence getUniqueSubscriptionDisplayName(
            SubscriptionInfo info, Context context) {
        return getUniqueSubscriptionDisplayName(info.getSubscriptionId(), context);
    }

    public static String getDisplayName(SubscriptionInfo info) {
        final CharSequence name = info.getDisplayName();
        if (name != null) {
+20 −0
Original line number Diff line number Diff line
@@ -360,6 +360,26 @@ public class SubscriptionUtilTest {
        assertTrue(TextUtils.isEmpty(name));
    }

    @Test
    public void getUniqueDisplayName_fullSubscriptionInfo_correctNameReturned() {
        // Each subscription's default display name is unique.
        final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
        when(info1.getSubscriptionId()).thenReturn(SUBID_1);
        when(info1.getDisplayName()).thenReturn(CARRIER_1);
        when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
                Arrays.asList(info1));

        TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
        when(sub1Telmgr.getLine1Number()).thenReturn("1112223333");
        when(mTelMgr.createForSubscriptionId(SUBID_1)).thenReturn(sub1Telmgr);

        final CharSequence name =
                SubscriptionUtil.getUniqueSubscriptionDisplayName(info1, mContext);

        assertThat(name).isNotNull();
        assertEquals(CARRIER_1, name);
    }

    @Test
    public void isInactiveInsertedPSim_nullSubInfo_doesNotCrash() {
        assertThat(SubscriptionUtil.isInactiveInsertedPSim(null)).isFalse();