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

Commit 0a842957 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge changes from topics "GET_USER_HANDLE_FLAG", "subscription_apis"

* changes:
  Exposed getAllSubscriptionInfoList and getSubscriptionId
  Added resource overlay flag to enable/disable getSubscriptionUserHandle api.
parents 836658dd 9e69a8cc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4814,9 +4814,15 @@ public class SubscriptionController extends ISub.Stub {
     * @throws IllegalArgumentException if subId is invalid.
     */
    @Override
    @Nullable
    public UserHandle getSubscriptionUserHandle(int subId) {
        enforceManageSubscriptionUserAssociation("getSubscriptionUserHandle");

        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_enable_get_subscription_user_handle)) {
            return null;
        }

        long token = Binder.clearCallingIdentity();
        try {
            String userHandleStr = getSubscriptionProperty(subId, SubscriptionManager.USER_HANDLE);
+13 −9
Original line number Diff line number Diff line
@@ -986,7 +986,7 @@ public class SubscriptionManagerService extends ISub.Stub {
    }

    /**
     * Get all subscription info records from SIMs that are inserted now or were inserted before.
     * Get all subscription info records from SIMs that are inserted now or previously inserted.
     *
     * <p>
     * If the caller does not have {@link Manifest.permission#READ_PHONE_NUMBERS} permission,
@@ -996,19 +996,17 @@ public class SubscriptionManagerService extends ISub.Stub {
     * empty string, and {@link SubscriptionInfo#getGroupUuid()} will return {@code null}.
     *
     * <p>
     * The carrier app will always have full {@link SubscriptionInfo} for the subscriptions
     * that it has carrier privilege. Subscriptions that the carrier app has no privilege will be
     * excluded from the list.
     *
     * @return List of all {@link SubscriptionInfo} records from SIMs that are inserted or
     * inserted before. Sorted by {@link SubscriptionInfo#getSimSlotIndex()}, then
     * {@link SubscriptionInfo#getSubscriptionId()}.
     * The carrier app will only get the list of subscriptions that it has carrier privilege on,
     * but will have non-stripped {@link SubscriptionInfo} in the list.
     *
     * @param callingPackage The package making the call.
     * @param callingFeatureId The feature in the package.
     *
     * @throws SecurityException if the caller does not have required permissions.
     * @return List of all {@link SubscriptionInfo} records from SIMs that are inserted or
     * previously inserted. Sorted by {@link SubscriptionInfo#getSimSlotIndex()}, then
     * {@link SubscriptionInfo#getSubscriptionId()}.
     *
     * @throws SecurityException if callers do not hold the required permission.
     */
    @Override
    @NonNull
@@ -2988,11 +2986,17 @@ public class SubscriptionManagerService extends ISub.Stub {
     * @throws IllegalArgumentException if {@code subId} is invalid.
     */
    @Override
    @Nullable
    @RequiresPermission(Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION)
    public UserHandle getSubscriptionUserHandle(int subId) {
        enforcePermissions("getSubscriptionUserHandle",
                Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);

        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_enable_get_subscription_user_handle)) {
            return null;
        }

        long token = Binder.clearCallingIdentity();
        try {
            SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager
+16 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -2140,6 +2141,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    @Test
    public void setSubscriptionUserHandle_withoutPermission() {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2154,6 +2156,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    @Test
    public void setGetSubscriptionUserHandle_userHandleNull() {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2167,6 +2170,8 @@ public class SubscriptionControllerTest extends TelephonyTest {

    @Test
    public void setSubscriptionUserHandle_invalidSubId() {
        enableGetSubscriptionUserHandle();

        assertThrows(IllegalArgumentException.class,
                () -> mSubscriptionControllerUT.setSubscriptionUserHandle(
                        UserHandle.of(UserHandle.USER_SYSTEM),
@@ -2176,6 +2181,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    @Test
    public void setGetSubscriptionUserHandle_withValidUserHandleAndSubId() {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2191,6 +2197,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    @Test
    public void getSubscriptionUserHandle_withoutPermission() {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2203,8 +2210,17 @@ public class SubscriptionControllerTest extends TelephonyTest {

    @Test
    public void getSubscriptionUserHandle_invalidSubId() {
        enableGetSubscriptionUserHandle();

        assertThrows(IllegalArgumentException.class,
                () -> mSubscriptionControllerUT.getSubscriptionUserHandle(
                        SubscriptionManager.DEFAULT_SUBSCRIPTION_ID));
    }

    private void enableGetSubscriptionUserHandle() {
        Resources mResources = mock(Resources.class);
        doReturn(true).when(mResources).getBoolean(
                eq(com.android.internal.R.bool.config_enable_get_subscription_user_handle));
        doReturn(mResources).when(mContext).getResources();
    }
}
 No newline at end of file
+6 −1
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import android.app.PropertyInvalidatedCache;
import android.compat.testing.PlatformCompatChangeRule;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
@@ -916,8 +917,12 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
    @Test
    public void testSetGetSubscriptionUserHandle() {
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        Resources mResources = Mockito.mock(Resources.class);
        doReturn(true).when(mResources).getBoolean(
                eq(com.android.internal.R.bool.config_enable_get_subscription_user_handle));
        doReturn(mResources).when(mContext).getResources();

        // Should fail without MODIFY_PHONE_STATE
        // Should fail without MANAGE_SUBSCRIPTION_USER_ASSOCIATION
        assertThrows(SecurityException.class, () -> mSubscriptionManagerServiceUT
                .setSubscriptionUserHandle(new UserHandle(12), 1));