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

Commit c61d2f7c authored by Jack Yu's avatar Jack Yu
Browse files

Added getActiveSubInfoCount

Added getActiveSubInfoCount and migrated more modules
to use SubscrtipionManagerService.

Test: atest FrameworksTelephonyTests
Bug: 239607619
Change-Id: Iee6801573e4ad4ea08da7d725dd0c0292b7d96d2
parent c79fdc91
Loading
Loading
Loading
Loading
+90 −2
Original line number Original line Diff line number Diff line
@@ -943,6 +943,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    })
    })
    public SubscriptionInfo getActiveSubscriptionInfo(int subId, @NonNull String callingPackage,
    public SubscriptionInfo getActiveSubscriptionInfo(int subId, @NonNull String callingPackage,
            @Nullable String callingFeatureId) {
            @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId, callingPackage,
        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId, callingPackage,
                callingFeatureId, "getActiveSubscriptionInfo")) {
                callingFeatureId, "getActiveSubscriptionInfo")) {
            throw new SecurityException("Need READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or "
            throw new SecurityException("Need READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or "
@@ -975,6 +979,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    @Nullable
    @Nullable
    public SubscriptionInfo getActiveSubscriptionInfoForIccId(@NonNull String iccId,
    public SubscriptionInfo getActiveSubscriptionInfoForIccId(@NonNull String iccId,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return null;
        return null;
    }
    }


@@ -996,6 +1004,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    })
    })
    public SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex,
    public SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(int slotIndex,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        int subId = mSlotIndexToSubId.getOrDefault(slotIndex,
        int subId = mSlotIndexToSubId.getOrDefault(slotIndex,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);


@@ -1078,12 +1090,34 @@ public class SubscriptionManagerService extends ISub.Stub {
     *
     *
     * @param callingPackage The package making the call
     * @param callingPackage The package making the call
     * @param callingFeatureId The feature in the package
     * @param callingFeatureId The feature in the package
     * @return the number of active subscriptions
     *
     * @return the number of active subscriptions.
     */
     */
    @Override
    @Override
    @RequiresPermission(anyOf = {
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
            "carrier privileges",
    })
    public int getActiveSubInfoCount(@NonNull String callingPackage,
    public int getActiveSubInfoCount(@NonNull String callingPackage,
            @Nullable String callingFeatureId) {
            @Nullable String callingFeatureId) {
        return 0;
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        if (!TelephonyPermissions.checkReadPhoneStateOnAnyActiveSub(mContext,
                Binder.getCallingPid(), Binder.getCallingUid(), callingPackage, callingFeatureId,
                "getAllSubInfoList")) {
            throw new SecurityException("Need READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or "
                    + "carrier privilege");
        }

        final long token = Binder.clearCallingIdentity();
        try {
            return getActiveSubIdList(false).length;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
    }
    }


    /**
    /**
@@ -1139,6 +1173,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    @Override
    @Override
    public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(
    public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(
            @NonNull String callingPackage) {
            @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return null;
        return null;
    }
    }


@@ -1371,6 +1409,11 @@ public class SubscriptionManagerService extends ISub.Stub {
     */
     */
    @Override
    @Override
    public int setOpportunistic(boolean opportunistic, int subId, @NonNull String callingPackage) {
    public int setOpportunistic(boolean opportunistic, int subId, @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);


        return 0;
        return 0;
    }
    }


@@ -1392,6 +1435,11 @@ public class SubscriptionManagerService extends ISub.Stub {
     */
     */
    @Override
    @Override
    public ParcelUuid createSubscriptionGroup(int[] subIdList, @NonNull String callingPackage) {
    public ParcelUuid createSubscriptionGroup(int[] subIdList, @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);


        return null;
        return null;
    }
    }


@@ -1424,17 +1472,29 @@ public class SubscriptionManagerService extends ISub.Stub {
    @NonNull
    @NonNull
    public List<SubscriptionInfo> getOpportunisticSubscriptions(@NonNull String callingPackage,
    public List<SubscriptionInfo> getOpportunisticSubscriptions(@NonNull String callingPackage,
            @Nullable String callingFeatureId) {
            @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return Collections.emptyList();
        return Collections.emptyList();
    }
    }


    @Override
    @Override
    public void removeSubscriptionsFromGroup(int[] subIdList, @NonNull ParcelUuid groupUuid,
    public void removeSubscriptionsFromGroup(int[] subIdList, @NonNull ParcelUuid groupUuid,
            @NonNull String callingPackage) {
            @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

    }
    }


    @Override
    @Override
    public void addSubscriptionsIntoGroup(int[] subIdList, @NonNull ParcelUuid groupUuid,
    public void addSubscriptionsIntoGroup(int[] subIdList, @NonNull ParcelUuid groupUuid,
            @NonNull String callingPackage) {
            @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

    }
    }


    /**
    /**
@@ -1468,6 +1528,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    @NonNull
    @NonNull
    public List<SubscriptionInfo> getSubscriptionsInGroup(@NonNull ParcelUuid groupUuid,
    public List<SubscriptionInfo> getSubscriptionsInGroup(@NonNull ParcelUuid groupUuid,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        // If the calling app neither has carrier privileges nor READ_PHONE_STATE and access to
        // If the calling app neither has carrier privileges nor READ_PHONE_STATE and access to
        // device identifiers, it will throw a SecurityException.
        // device identifiers, it will throw a SecurityException.
        if (CompatChanges.isChangeEnabled(REQUIRE_DEVICE_IDENTIFIERS_FOR_GROUP_UUID,
        if (CompatChanges.isChangeEnabled(REQUIRE_DEVICE_IDENTIFIERS_FOR_GROUP_UUID,
@@ -1766,6 +1830,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    @Override
    @Override
    public String getSubscriptionProperty(int subId, @NonNull String propKey,
    public String getSubscriptionProperty(int subId, @NonNull String propKey,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return null;
        return null;
    }
    }


@@ -1806,6 +1874,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    })
    })
    public boolean isActiveSubId(int subId, @NonNull String callingPackage,
    public boolean isActiveSubId(int subId, @NonNull String callingPackage,
            @Nullable String callingFeatureId) {
            @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId, callingPackage,
        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId, callingPackage,
                callingFeatureId, "isActiveSubId")) {
                callingFeatureId, "isActiveSubId")) {
            throw new SecurityException("Need READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or "
            throw new SecurityException("Need READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or "
@@ -1896,6 +1968,10 @@ public class SubscriptionManagerService extends ISub.Stub {
    })
    })
    public String getPhoneNumber(int subId, @PhoneNumberSource int source,
    public String getPhoneNumber(int subId, @PhoneNumberSource int source,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(
        TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(
                mContext, subId, Binder.getCallingUid(), "getPhoneNumber",
                mContext, subId, Binder.getCallingUid(), "getPhoneNumber",
                Manifest.permission.READ_PHONE_NUMBERS,
                Manifest.permission.READ_PHONE_NUMBERS,
@@ -1934,12 +2010,20 @@ public class SubscriptionManagerService extends ISub.Stub {
    @Override
    @Override
    public String getPhoneNumberFromFirstAvailableSource(int subId,
    public String getPhoneNumberFromFirstAvailableSource(int subId,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return null;
        return null;
    }
    }


    @Override
    @Override
    public void setPhoneNumber(int subId, @PhoneNumberSource int source, @NonNull String number,
    public void setPhoneNumber(int subId, @PhoneNumberSource int source, @NonNull String number,
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
            @NonNull String callingPackage, @Nullable String callingFeatureId) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        if (source != SubscriptionManager.PHONE_NUMBER_SOURCE_CARRIER) {
        if (source != SubscriptionManager.PHONE_NUMBER_SOURCE_CARRIER) {
            throw new IllegalArgumentException("setPhoneNumber doesn't accept source "
            throw new IllegalArgumentException("setPhoneNumber doesn't accept source "
                    + SubscriptionManager.phoneNumberSourceToString(source));
                    + SubscriptionManager.phoneNumberSourceToString(source));
@@ -1970,6 +2054,10 @@ public class SubscriptionManagerService extends ISub.Stub {
     */
     */
    @Override
    @Override
    public int setUsageSetting(int usageSetting, int subId, @NonNull String callingPackage) {
    public int setUsageSetting(int usageSetting, int subId, @NonNull String callingPackage) {
        // Verify that the callingPackage belongs to the calling UID
        mContext.getSystemService(AppOpsManager.class)
                .checkPackage(Binder.getCallingUid(), callingPackage);

        return 0;
        return 0;
    }
    }


+15 −0
Original line number Original line Diff line number Diff line
@@ -797,4 +797,19 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1).getDisplayName())
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1).getDisplayName())
                .isEqualTo(FAKE_CARRIER_NAME2);
                .isEqualTo(FAKE_CARRIER_NAME2);
    }
    }

    @Test
    public void testGetActiveSubInfoCount() {
        doReturn(new int[]{1, 2}).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

        // Should fail without READ_PHONE_STATE
        assertThrows(SecurityException.class, () -> mSubscriptionManagerServiceUT
                .getActiveSubInfoCount(CALLING_PACKAGE, CALLING_FEATURE));

        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        assertThat(mSubscriptionManagerServiceUT.getActiveSubInfoCount(
                CALLING_PACKAGE, CALLING_FEATURE)).isEqualTo(2);
    }
}
}