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

Commit f6ec29f3 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "Add run-time feature flag for work profile."

parents e2efa686 267781f7
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -4830,8 +4830,7 @@ public class SubscriptionController extends ISub.Stub {
    public UserHandle getSubscriptionUserHandle(int subId) {
        enforceManageSubscriptionUserAssociation("getSubscriptionUserHandle");

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

@@ -4870,6 +4869,10 @@ public class SubscriptionController extends ISub.Stub {
            @NonNull UserHandle userHandle) {
        enforceManageSubscriptionUserAssociation("isSubscriptionAssociatedWithUser");

        if (!SubscriptionInfoUpdater.isWorkProfileTelephonyEnabled()) {
            return true;
        }

        long token = Binder.clearCallingIdentity();
        try {
            // Return true if there are no subscriptions on the device.
@@ -4924,6 +4927,10 @@ public class SubscriptionController extends ISub.Stub {
                return new ArrayList<>();
            }

            if (!SubscriptionInfoUpdater.isWorkProfileTelephonyEnabled()) {
                return subInfoList;
            }

            List<SubscriptionInfo> subscriptionsAssociatedWithUser = new ArrayList<>();
            List<SubscriptionInfo> subscriptionsWithNoAssociation = new ArrayList<>();
            for (SubscriptionInfo subInfo : subInfoList) {
+37 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.ParcelUuid;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.provider.DeviceConfig;
import android.service.carrier.CarrierIdentifier;
import android.service.euicc.EuiccProfileInfo;
import android.service.euicc.EuiccService;
@@ -93,6 +94,8 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final int EVENT_REFRESH_EMBEDDED_SUBSCRIPTIONS = 12;
    private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 13;
    private static final int EVENT_INACTIVE_SLOT_ICC_STATE_CHANGED = 14;
    /** Device config changed. */
    private static final int EVENT_DEVICE_CONFIG_CHANGED = 15;

    private static final String ICCID_STRING_FOR_NO_SIM = "";

@@ -115,6 +118,10 @@ public class SubscriptionInfoUpdater extends Handler {
    private SubscriptionManager mSubscriptionManager = null;
    private EuiccManager mEuiccManager;
    private Handler mBackgroundHandler;
    /** DeviceConfig key for whether work profile telephony feature is enabled. */
    private static final String KEY_ENABLE_WORK_PROFILE_TELEPHONY = "enable_work_profile_telephony";
    /** {@code true} if the work profile telephony feature is enabled otherwise {@code false}. */
    private static boolean mIsWorkProfileTelephonyEnabled = false;

    // The current foreground user ID.
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@@ -175,6 +182,16 @@ public class SubscriptionInfoUpdater extends Handler {

        PhoneConfigurationManager.registerForMultiSimConfigChange(
                this, EVENT_MULTI_SIM_CONFIG_CHANGED, null);

        mIsWorkProfileTelephonyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY,
                KEY_ENABLE_WORK_PROFILE_TELEPHONY, false);
        DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_TELEPHONY, this::post,
                properties -> {
                    if (TextUtils.equals(DeviceConfig.NAMESPACE_TELEPHONY,
                            properties.getNamespace())) {
                        sendEmptyMessage(EVENT_DEVICE_CONFIG_CHANGED);
                    }
                });
    }

    private void initializeCarrierApps() {
@@ -360,6 +377,18 @@ public class SubscriptionInfoUpdater extends Handler {
                onMultiSimConfigChanged();
                break;

            case EVENT_DEVICE_CONFIG_CHANGED:
                boolean isWorkProfileTelephonyEnabled = DeviceConfig.getBoolean(
                        DeviceConfig.NAMESPACE_TELEPHONY, KEY_ENABLE_WORK_PROFILE_TELEPHONY,
                        false);
                if (isWorkProfileTelephonyEnabled != mIsWorkProfileTelephonyEnabled) {
                    logd("EVENT_DEVICE_CONFIG_CHANGED: isWorkProfileTelephonyEnabled changed from "
                            + mIsWorkProfileTelephonyEnabled + " to "
                            + isWorkProfileTelephonyEnabled);
                    mIsWorkProfileTelephonyEnabled = isWorkProfileTelephonyEnabled;
                }
                break;

            default:
                logd("Unknown msg:" + msg.what);
        }
@@ -902,6 +931,14 @@ public class SubscriptionInfoUpdater extends Handler {
        return sIsSubInfoInitialized;
    }

    /**
     * Whether work profile telephony feature is enabled or not.
     * return {@code true} if work profile telephony feature is enabled.
     */
    public static boolean isWorkProfileTelephonyEnabled() {
        return mIsWorkProfileTelephonyEnabled;
    }

    /**
     * Updates the cached list of embedded subscription for the eUICC with the given list of card
     * IDs {@code cardIds}. The step of reading the embedded subscription list from eUICC card is
+49 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.TelephonyServiceManager;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Telephony.SimInfo;
import android.service.carrier.CarrierIdentifier;
@@ -370,6 +371,11 @@ public class SubscriptionManagerService extends ISub.Stub {
        public void onUiccApplicationsEnabled(int subId) {}
    }

    /** DeviceConfig key for whether work profile telephony feature is enabled. */
    private static final String KEY_ENABLE_WORK_PROFILE_TELEPHONY = "enable_work_profile_telephony";
    /** {@code true} if the work profile telephony feature is enabled otherwise {@code false}. */
    private boolean mIsWorkProfileTelephonyEnabled = false;

    /**
     * The constructor
     *
@@ -453,6 +459,15 @@ public class SubscriptionManagerService extends ISub.Stub {
        mSimState = new int[mTelephonyManager.getSupportedModemCount()];
        Arrays.fill(mSimState, TelephonyManager.SIM_STATE_UNKNOWN);

        mIsWorkProfileTelephonyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY,
                KEY_ENABLE_WORK_PROFILE_TELEPHONY, false);
        DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_TELEPHONY,
                mHandler::post, properties -> {
            if (TextUtils.equals(DeviceConfig.NAMESPACE_TELEPHONY, properties.getNamespace())) {
                onDeviceConfigChanged();
            }
        });

        // Create a separate thread for subscription database manager. The database will be updated
        // from a different thread.
        HandlerThread handlerThread = new HandlerThread(LOG_TAG);
@@ -751,6 +766,16 @@ public class SubscriptionManagerService extends ISub.Stub {
        return iccidList;
    }

    /**
     * Enable or disable work profile telephony feature.
     * @param isWorkProfileTelephonyEnabled - {@code true} if the work profile telephony feature
     *                                      is enabled otherwise {@code false}.
     */
    @VisibleForTesting
    public void setWorkProfileTelephonyEnabled(boolean isWorkProfileTelephonyEnabled) {
        mIsWorkProfileTelephonyEnabled = isWorkProfileTelephonyEnabled;
    }

    /**
     * Set the subscription carrier id.
     *
@@ -3409,8 +3434,7 @@ public class SubscriptionManagerService extends ISub.Stub {
        enforcePermissions("getSubscriptionUserHandle",
                Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);

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

@@ -3452,6 +3476,10 @@ public class SubscriptionManagerService extends ISub.Stub {
        enforcePermissions("isSubscriptionAssociatedWithUser",
                Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);

        if (!mIsWorkProfileTelephonyEnabled) {
            return true;
        }

        long token = Binder.clearCallingIdentity();
        try {
            // Return true if there are no subscriptions on the device.
@@ -3507,6 +3535,10 @@ public class SubscriptionManagerService extends ISub.Stub {
                return new ArrayList<>();
            }

            if (!mIsWorkProfileTelephonyEnabled) {
                return subInfoList;
            }

            List<SubscriptionInfo> subscriptionsAssociatedWithUser = new ArrayList<>();
            List<SubscriptionInfo> subscriptionsWithNoAssociation = new ArrayList<>();
            for (SubscriptionInfo subInfo : subInfoList) {
@@ -3650,6 +3682,21 @@ public class SubscriptionManagerService extends ISub.Stub {
        });
    }

    /**
     * Listener to update cached flag values from DeviceConfig.
     */
    private void onDeviceConfigChanged() {
        boolean isWorkProfileTelephonyEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_TELEPHONY, KEY_ENABLE_WORK_PROFILE_TELEPHONY,
                false);
        if (isWorkProfileTelephonyEnabled != mIsWorkProfileTelephonyEnabled) {
            log("onDeviceConfigChanged: isWorkProfileTelephonyEnabled "
                    + "changed from " + mIsWorkProfileTelephonyEnabled + " to "
                    + isWorkProfileTelephonyEnabled);
            mIsWorkProfileTelephonyEnabled = isWorkProfileTelephonyEnabled;
        }
    }

    /**
     * Get the calling package(s).
     *
+12 −25
Original line number Diff line number Diff line
@@ -144,6 +144,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
        replaceInstance(SubscriptionController.class, "sInstance", null, null);
        replaceInstance(MultiSimSettingController.class, "sInstance", null,
                mMultiSimSettingControllerMock);
        replaceInstance(SubscriptionInfoUpdater.class, "mIsWorkProfileTelephonyEnabled",
                null, true);

        mSubscriptionControllerUT = SubscriptionController.init(mContext);
        mCallingPackage = mContext.getOpPackageName();
@@ -2141,9 +2143,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void setSubscriptionUserHandle_withoutPermission() {
    public void setSubscriptionUserHandle_withoutPermission() throws Exception {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2156,9 +2157,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void setGetSubscriptionUserHandle_userHandleNull() {
    public void setGetSubscriptionUserHandle_userHandleNull() throws Exception {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2171,9 +2171,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

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

    public void setSubscriptionUserHandle_invalidSubId() throws Exception {
        assertThrows(IllegalArgumentException.class,
                () -> mSubscriptionControllerUT.setSubscriptionUserHandle(
                        UserHandle.of(UserHandle.USER_SYSTEM),
@@ -2181,9 +2179,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void setGetSubscriptionUserHandle_withValidUserHandleAndSubId() {
    public void setGetSubscriptionUserHandle_withValidUserHandleAndSubId() throws Exception {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2197,9 +2194,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void getSubscriptionUserHandle_withoutPermission() {
    public void getSubscriptionUserHandle_withoutPermission() throws Exception {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2211,9 +2207,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

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

    public void getSubscriptionUserHandle_invalidSubId() throws Exception {
        assertThrows(IllegalArgumentException.class,
                () -> mSubscriptionControllerUT.getSubscriptionUserHandle(
                        SubscriptionManager.DEFAULT_SUBSCRIPTION_ID));
@@ -2229,7 +2223,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void isSubscriptionAssociatedWithUser_noSubscription() {
    public void isSubscriptionAssociatedWithUser_noSubscription() throws Exception {
        // isSubscriptionAssociatedWithUser should return true if there are no active subscriptions.
        assertThat(mSubscriptionControllerUT.isSubscriptionAssociatedWithUser(1,
                UserHandle.of(UserHandle.USER_SYSTEM))).isEqualTo(true);
@@ -2248,7 +2242,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void isSubscriptionAssociatedWithUser_userAssociatedWithSubscription() {
    public void isSubscriptionAssociatedWithUser_userAssociatedWithSubscription() throws Exception {
        testInsertSim();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
@@ -2263,9 +2257,9 @@ public class SubscriptionControllerTest extends TelephonyTest {
    }

    @Test
    public void isSubscriptionAssociatedWithUser_userNotAssociatedWithSubscription() {
    public void isSubscriptionAssociatedWithUser_userNotAssociatedWithSubscription()
            throws Exception {
        testInsertSim();
        enableGetSubscriptionUserHandle();
        /* Get SUB ID */
        int[] subIds = mSubscriptionControllerUT.getActiveSubIdList(/*visibleOnly*/false);
        assertTrue(subIds != null && subIds.length != 0);
@@ -2294,11 +2288,4 @@ public class SubscriptionControllerTest extends TelephonyTest {
                .getSubscriptionInfoListAssociatedWithUser(UserHandle.of(UserHandle.USER_SYSTEM));
        assertThat(associatedSubInfoList.size()).isEqualTo(0);
    }

    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
+16 −1
Original line number Diff line number Diff line
@@ -939,14 +939,17 @@ public abstract class TelephonyTest {
        private static final String PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED =
                DeviceConfig.NAMESPACE_PRIVACY + "/"
                        + "device_identifier_access_restrictions_disabled";
        private HashMap<String, String> mFlags = new HashMap<>();

        @Override
        public Bundle call(String method, String arg, Bundle extras) {
            logd("FakeSettingsConfigProvider: call called,  method: " + method +
                    " request: " + arg + ", args=" + extras);
            Bundle bundle = new Bundle();
            switch (method) {
                case Settings.CALL_METHOD_GET_CONFIG: {
                    switch (arg) {
                        case PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED: {
                            Bundle bundle = new Bundle();
                            bundle.putString(
                                    PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED,
                                    "0");
@@ -958,6 +961,18 @@ public abstract class TelephonyTest {
                    }
                    break;
                }
                case Settings.CALL_METHOD_LIST_CONFIG:
                    logd("LIST_config: " + mFlags);
                    Bundle result = new Bundle();
                    result.putSerializable(Settings.NameValueTable.VALUE, mFlags);
                    return result;
                case Settings.CALL_METHOD_SET_ALL_CONFIG:
                    mFlags = (extras != null)
                            ? (HashMap) extras.getSerializable(Settings.CALL_METHOD_FLAGS_KEY)
                            : new HashMap<>();
                    bundle.putInt(Settings.KEY_CONFIG_SET_ALL_RETURN,
                            Settings.SET_ALL_RESULT_SUCCESS);
                    return bundle;
                default:
                    fail("Method not expected: " + method);
            }
Loading