Search in sources :

Example 26 with SubscriptionManager

use of android.telephony.SubscriptionManager in project android_frameworks_base by ResurrectionRemix.

the class NetworkPolicyManagerService method setNetworkTemplateEnabled.

/**
     * Proactively disable networks that match the given
     * {@link NetworkTemplate}.
     */
private void setNetworkTemplateEnabled(NetworkTemplate template, boolean enabled) {
    if (template.getMatchRule() == MATCH_MOBILE_ALL) {
        // If mobile data usage hits the limit or if the user resumes the data, we need to
        // notify telephony.
        final SubscriptionManager sm = SubscriptionManager.from(mContext);
        final TelephonyManager tm = TelephonyManager.from(mContext);
        final int[] subIds = sm.getActiveSubscriptionIdList();
        for (int subId : subIds) {
            final String subscriberId = tm.getSubscriberId(subId);
            final NetworkIdentity probeIdent = new NetworkIdentity(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false, true);
            // Template is matched when subscriber id matches.
            if (template.matches(probeIdent)) {
                tm.setPolicyDataEnabled(enabled, subId);
            }
        }
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity) TelephonyManager(android.telephony.TelephonyManager) SubscriptionManager(android.telephony.SubscriptionManager) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Example 27 with SubscriptionManager

use of android.telephony.SubscriptionManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SecuritySettings method createPreferenceHierarchy.

/**
     * Important!
     *
     * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
     * logic or adding/removing preferences here.
     */
private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();
    // Add options for lock/unlock screen
    final int resid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, MY_USER_ID);
    addPreferencesFromResource(resid);
    // DO or PO installed in the user may disallow to change password.
    disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
    mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
    if (mProfileChallengeUserId != UserHandle.USER_NULL && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
        addPreferencesFromResource(R.xml.security_settings_profile);
        addPreferencesFromResource(R.xml.security_settings_unification);
        final int profileResid = getResIdForLockUnlockScreen(getActivity(), mLockPatternUtils, mManagedPasswordProvider, mProfileChallengeUserId);
        addPreferencesFromResource(profileResid);
        maybeAddFingerprintPreference(root, mProfileChallengeUserId);
        if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
            final Preference lockPreference = root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
            final String summary = getContext().getString(R.string.lock_settings_profile_unified_summary);
            lockPreference.setSummary(summary);
            lockPreference.setEnabled(false);
            // PO may disallow to change password for the profile, but screen lock and managed
            // profile's lock is the same. Disable main "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
        } else {
            // PO may disallow to change profile password, and the profile's password is
            // separated from screen lock password. Disable profile specific "Screen lock" menu.
            disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE, mProfileChallengeUserId);
        }
    }
    Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
    if (unlockSetOrChange instanceof GearPreference) {
        ((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
    }
    // Add options for device encryption
    mIsAdmin = mUm.isAdminUser();
    if (mIsAdmin) {
        if (LockPatternUtils.isDeviceEncryptionEnabled()) {
            // The device is currently encrypted.
            addPreferencesFromResource(R.xml.security_settings_encrypted);
        } else {
            // This device supports encryption but isn't encrypted.
            addPreferencesFromResource(R.xml.security_settings_unencrypted);
        }
    }
    // Fingerprint and trust agents
    PreferenceGroup securityCategory = (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
    if (securityCategory != null) {
        maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
        addTrustAgentSettings(securityCategory);
    }
    mVisiblePatternProfile = (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
    mUnifyProfile = (SwitchPreference) root.findPreference(KEY_UNIFICATION);
    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);
    // Do not display SIM lock for devices without an Icc card
    CarrierConfigManager cfgMgr = (CarrierConfigManager) getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
    PersistableBundle b = cfgMgr.getConfig();
    PreferenceGroup iccLockGroup = (PreferenceGroup) root.findPreference(KEY_SIM_LOCK);
    Preference iccLock = root.findPreference(KEY_SIM_LOCK_SETTINGS);
    if (!mIsAdmin || b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
        root.removePreference(iccLockGroup);
    } else {
        SubscriptionManager subMgr = SubscriptionManager.from(getActivity());
        TelephonyManager tm = TelephonyManager.getDefault();
        int numPhones = tm.getPhoneCount();
        boolean hasAnySim = false;
        for (int i = 0; i < numPhones; i++) {
            final Preference pref;
            if (numPhones > 1) {
                SubscriptionInfo sir = subMgr.getActiveSubscriptionInfoForSimSlotIndex(i);
                if (sir == null) {
                    continue;
                }
                pref = new Preference(getActivity());
                pref.setOrder(iccLock.getOrder());
                pref.setTitle(getString(R.string.sim_card_lock_settings_title, i + 1));
                pref.setSummary(sir.getDisplayName());
                Intent intent = new Intent(getActivity(), com.android.settings.Settings.IccLockSettingsActivity.class);
                intent.putExtra(IccLockSettings.EXTRA_SUB_ID, sir.getSubscriptionId());
                intent.putExtra(IccLockSettings.EXTRA_SUB_DISPLAY_NAME, sir.getDisplayName());
                intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
                pref.setIntent(intent);
                iccLockGroup.addPreference(pref);
            } else {
                pref = iccLock;
            }
            // Do not display SIM lock for devices without an Icc card
            hasAnySim |= tm.hasIccCard(i);
            int simState = tm.getSimState(i);
            boolean simPresent = simState != TelephonyManager.SIM_STATE_ABSENT && simState != TelephonyManager.SIM_STATE_UNKNOWN && simState != TelephonyManager.SIM_STATE_CARD_IO_ERROR;
            if (!simPresent) {
                pref.setEnabled(false);
            }
        }
        if (!hasAnySim) {
            root.removePreference(iccLockGroup);
        } else if (numPhones > 1) {
            iccLockGroup.removePreference(iccLock);
        }
    }
    if (Settings.System.getInt(getContentResolver(), Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
        root.findPreference(KEY_SCREEN_PINNING).setSummary(getResources().getString(R.string.switch_on_text));
    }
    // Show password
    mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
    mResetCredentials = (RestrictedPreference) root.findPreference(KEY_RESET_CREDENTIALS);
    // Credential storage
    final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
    // needs to be initialized for onResume()
    mKeyStore = KeyStore.getInstance();
    if (!RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_CONFIG_CREDENTIALS, MY_USER_ID)) {
        RestrictedPreference userCredentials = (RestrictedPreference) root.findPreference(KEY_USER_CREDENTIALS);
        userCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference credentialStorageType = (RestrictedPreference) root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE);
        credentialStorageType.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        RestrictedPreference installCredentials = (RestrictedPreference) root.findPreference(KEY_CREDENTIALS_INSTALL);
        installCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        mResetCredentials.checkRestrictionAndSetDisabled(UserManager.DISALLOW_CONFIG_CREDENTIALS);
        final int storageSummaryRes = mKeyStore.isHardwareBacked() ? R.string.credential_storage_type_hardware : R.string.credential_storage_type_software;
        credentialStorageType.setSummary(storageSummaryRes);
    } else {
        PreferenceGroup credentialsManager = (PreferenceGroup) root.findPreference(KEY_CREDENTIALS_MANAGER);
        credentialsManager.removePreference(root.findPreference(KEY_RESET_CREDENTIALS));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIALS_INSTALL));
        credentialsManager.removePreference(root.findPreference(KEY_CREDENTIAL_STORAGE_TYPE));
        credentialsManager.removePreference(root.findPreference(KEY_USER_CREDENTIALS));
    }
    // Application install
    PreferenceGroup deviceAdminCategory = (PreferenceGroup) root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
    mToggleAppInstallation = (RestrictedSwitchPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
    // Side loading of apps.
    // Disable for restricted profiles. For others, check if policy disallows it.
    mToggleAppInstallation.setEnabled(!um.getUserInfo(MY_USER_ID).isRestricted());
    if (RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, MY_USER_ID) || RestrictedLockUtils.hasBaseUserRestriction(getActivity(), UserManager.DISALLOW_INSTALL_APPS, MY_USER_ID)) {
        mToggleAppInstallation.setEnabled(false);
    }
    if (mToggleAppInstallation.isEnabled()) {
        mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
        if (!mToggleAppInstallation.isDisabledByAdmin()) {
            mToggleAppInstallation.checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_APPS);
        }
    }
    // Advanced Security features
    PreferenceGroup advancedCategory = (PreferenceGroup) root.findPreference(KEY_ADVANCED_SECURITY);
    if (advancedCategory != null) {
        Preference manageAgents = advancedCategory.findPreference(KEY_MANAGE_TRUST_AGENTS);
        if (manageAgents != null && !mLockPatternUtils.isSecure(MY_USER_ID)) {
            manageAgents.setEnabled(false);
            manageAgents.setSummary(R.string.disabled_because_no_backup_security);
        }
    }
    // The above preferences come and go based on security state, so we need to update
    // the index. This call is expected to be fairly cheap, but we may want to do something
    // smarter in the future.
    Index.getInstance(getActivity()).updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
    for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
        final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
        if (pref != null)
            pref.setOnPreferenceChangeListener(this);
    }
    return root;
}
Also used : CarrierConfigManager(android.telephony.CarrierConfigManager) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent) SubscriptionManager(android.telephony.SubscriptionManager) PersistableBundle(android.os.PersistableBundle) RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) TelephonyManager(android.telephony.TelephonyManager) UserManager(android.os.UserManager) PreferenceGroup(android.support.v7.preference.PreferenceGroup) FingerprintSettings(com.android.settings.fingerprint.FingerprintSettings) CMSettings(cyanogenmod.providers.CMSettings) Settings(android.provider.Settings)

Example 28 with SubscriptionManager

use of android.telephony.SubscriptionManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SimDialogActivity method createDialog.

public Dialog createDialog(final Context context, final int id) {
    final ArrayList<String> list = new ArrayList<String>();
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    final int selectableSubInfoLength = subInfoList == null ? 0 : subInfoList.size();
    final DialogInterface.OnClickListener selectionListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int value) {
            final SubscriptionInfo sir;
            switch(id) {
                case DATA_PICK:
                    sir = subInfoList.get(value);
                    setDefaultDataSubId(context, sir.getSubscriptionId());
                    break;
                case CALLS_PICK:
                    final TelecomManager telecomManager = TelecomManager.from(context);
                    final List<PhoneAccountHandle> phoneAccountsList = telecomManager.getCallCapablePhoneAccounts();
                    setUserSelectedOutgoingPhoneAccount(value < 1 ? null : phoneAccountsList.get(value - 1));
                    break;
                case SMS_PICK:
                    sir = subInfoList.get(value);
                    setDefaultSmsSubId(context, sir.getSubscriptionId());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
            }
            finish();
        }
    };
    Dialog.OnKeyListener keyListener = new Dialog.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                finish();
            }
            return true;
        }
    };
    ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
    if (id == CALLS_PICK) {
        final TelecomManager telecomManager = TelecomManager.from(context);
        final TelephonyManager telephonyManager = TelephonyManager.from(context);
        final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
        list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
        callsSubInfoList.add(null);
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccounts.next());
            list.add((String) phoneAccount.getLabel());
            int subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount);
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                final SubscriptionInfo sir = SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
                callsSubInfoList.add(sir);
            } else {
                callsSubInfoList.add(null);
            }
        }
    } else {
        for (int i = 0; i < selectableSubInfoLength; ++i) {
            final SubscriptionInfo sir = subInfoList.get(i);
            CharSequence displayName = sir.getDisplayName();
            if (displayName == null) {
                displayName = "";
            }
            list.add(displayName.toString());
        }
    }
    String[] arr = list.toArray(new String[0]);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    ListAdapter adapter = new SelectAccountListAdapter(id == CALLS_PICK ? callsSubInfoList : subInfoList, builder.getContext(), R.layout.select_account_list_item, arr, id);
    switch(id) {
        case DATA_PICK:
            builder.setTitle(R.string.select_sim_for_data);
            break;
        case CALLS_PICK:
            builder.setTitle(R.string.select_sim_for_calls);
            break;
        case SMS_PICK:
            builder.setTitle(R.string.sim_card_select_title);
            break;
        default:
            throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
    }
    Dialog dialog = builder.setAdapter(adapter, selectionListener).create();
    dialog.setOnKeyListener(keyListener);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            finish();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) KeyEvent(android.view.KeyEvent) TelephonyManager(android.telephony.TelephonyManager) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ListAdapter(android.widget.ListAdapter) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager) PhoneAccount(android.telecom.PhoneAccount)

Example 29 with SubscriptionManager

use of android.telephony.SubscriptionManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SimSelectNotification method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final int numSlots = telephonyManager.getSimCount();
    // or User selection of fallback user preference is disabled.
    if (numSlots < 2 || !Utils.isDeviceProvisioned(context) || !SystemProperties.getBoolean("persist.radio.aosp_usr_pref_sel", false)) {
        Log.d(TAG, " no of slots " + numSlots + " provision = " + Utils.isDeviceProvisioned(context));
        return;
    }
    // Cancel any previous notifications
    cancelNotification(context);
    // If sim state is not ABSENT or LOADED then ignore
    String simStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
    if (!(IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus) || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus))) {
        Log.d(TAG, "sim state is not Absent or Loaded");
        return;
    } else {
        Log.d(TAG, "simstatus = " + simStatus);
    }
    int state;
    for (int i = 0; i < numSlots; i++) {
        state = telephonyManager.getSimState(i);
        if (!(state == TelephonyManager.SIM_STATE_ABSENT || state == TelephonyManager.SIM_STATE_READY || state == TelephonyManager.SIM_STATE_UNKNOWN)) {
            Log.d(TAG, "All sims not in valid state yet");
            return;
        }
    }
    List<SubscriptionInfo> sil = subscriptionManager.getActiveSubscriptionInfoList();
    if (sil == null || sil.size() < 1) {
        Log.d(TAG, "Subscription list is empty");
        return;
    }
    // Clear defaults for any subscriptions which no longer exist
    subscriptionManager.clearDefaultsForInactiveSubIds();
    boolean dataSelected = SubscriptionManager.isUsableSubIdValue(SubscriptionManager.getDefaultDataSubscriptionId());
    boolean smsSelected = SubscriptionManager.isUsableSubIdValue(SubscriptionManager.getDefaultSmsSubscriptionId());
    // If data and sms defaults are selected, dont show notification (Calls default is optional)
    if (dataSelected && smsSelected) {
        Log.d(TAG, "Data & SMS default sims are selected. No notification");
        return;
    }
    // Create a notification to tell the user that some defaults are missing
    createNotification(context);
    if (sil.size() == 1) {
        // If there is only one subscription, ask if user wants to use if for everything
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
        newIntent.putExtra(SimDialogActivity.PREFERRED_SIM, sil.get(0).getSimSlotIndex());
        context.startActivity(newIntent);
    } else if (!dataSelected) {
        // If there are mulitple, ensure they pick default data
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK);
        context.startActivity(newIntent);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SubscriptionInfo(android.telephony.SubscriptionInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SubscriptionManager(android.telephony.SubscriptionManager)

Example 30 with SubscriptionManager

use of android.telephony.SubscriptionManager in project android_frameworks_base by crdroidandroid.

the class UserRestrictionsUtils method applyUserRestriction.

/**
     * Apply each user restriction.
     *
     * <p>See also {@link
     * com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser},
     * which should be in sync with this method.
     */
private static void applyUserRestriction(Context context, int userId, String key, boolean newValue) {
    if (UserManagerService.DBG) {
        Log.d(TAG, "Applying user restriction: userId=" + userId + " key=" + key + " value=" + newValue);
    }
    // When certain restrictions are cleared, we don't update the system settings,
    // because these settings are changeable on the Settings UI and we don't know the original
    // value -- for example LOCATION_MODE might have been off already when the restriction was
    // set, and in that case even if the restriction is lifted, changing it to ON would be
    // wrong.  So just don't do anything in such a case.  If the user hopes to enable location
    // later, they can do it on the Settings UI.
    // WARNING: Remember that Settings.Global and Settings.Secure are changeable via adb.
    // To prevent this from happening for a given user restriction, you have to add a check to
    // SettingsProvider.isGlobalOrSecureSettingRestrictedForUser.
    final ContentResolver cr = context.getContentResolver();
    final long id = Binder.clearCallingIdentity();
    try {
        switch(key) {
            case UserManager.DISALLOW_CONFIG_WIFI:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
                }
                break;
            case UserManager.DISALLOW_DATA_ROAMING:
                if (newValue) {
                    // DISALLOW_DATA_ROAMING user restriction is set.
                    // Multi sim device.
                    SubscriptionManager subscriptionManager = new SubscriptionManager(context);
                    final List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
                    if (subscriptionInfoList != null) {
                        for (SubscriptionInfo subInfo : subscriptionInfoList) {
                            android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING + subInfo.getSubscriptionId(), "0", userId);
                        }
                    }
                    // Single sim device.
                    android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING, "0", userId);
                }
                break;
            case UserManager.DISALLOW_SHARE_LOCATION:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF, userId);
                }
                break;
            case UserManager.DISALLOW_DEBUGGING_FEATURES:
                if (newValue) {
                    // TODO: should this be admin user?
                    if (userId == UserHandle.USER_SYSTEM) {
                        android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.ADB_ENABLED, "0", userId);
                    }
                }
                break;
            case UserManager.ENSURE_VERIFY_APPS:
                if (newValue) {
                    android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1", userId);
                    android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1", userId);
                }
                break;
            case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES:
                if (newValue) {
                    android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0, userId);
                }
                break;
            case UserManager.DISALLOW_RUN_IN_BACKGROUND:
                if (newValue) {
                    int currentUser = ActivityManager.getCurrentUser();
                    if (currentUser != userId && userId != UserHandle.USER_SYSTEM) {
                        try {
                            ActivityManagerNative.getDefault().stopUser(userId, false, null);
                        } catch (RemoteException e) {
                            throw e.rethrowAsRuntimeException();
                        }
                    }
                }
                break;
            case UserManager.DISALLOW_SAFE_BOOT:
                // Unlike with the other restrictions, we want to propagate the new value to
                // the system settings even if it is false. The other restrictions modify
                // settings which could be manually changed by the user from the Settings app
                // after the policies enforcing these restrictions have been revoked, so we
                // leave re-setting of those settings to the user.
                android.provider.Settings.Global.putInt(context.getContentResolver(), android.provider.Settings.Global.SAFE_BOOT_DISALLOWED, newValue ? 1 : 0);
                break;
            case UserManager.DISALLOW_FACTORY_RESET:
            case UserManager.DISALLOW_OEM_UNLOCK:
                if (newValue) {
                    PersistentDataBlockManager manager = (PersistentDataBlockManager) context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
                    if (manager != null && manager.getOemUnlockEnabled() && manager.getFlashLockState() != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
                        // Only disable OEM unlock if the bootloader is locked. If it's already
                        // unlocked, setting the OEM unlock enabled flag to false has no effect
                        // (the bootloader would remain unlocked).
                        manager.setOemUnlockEnabled(false);
                    }
                }
                break;
        }
    } finally {
        Binder.restoreCallingIdentity(id);
    }
}
Also used : PersistentDataBlockManager(android.service.persistentdata.PersistentDataBlockManager) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver)

Aggregations

SubscriptionManager (android.telephony.SubscriptionManager)32 TelephonyManager (android.telephony.TelephonyManager)20 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SubscriptionInfo (android.telephony.SubscriptionInfo)13 NetworkIdentity (android.net.NetworkIdentity)10 ContentResolver (android.content.ContentResolver)4 Intent (android.content.Intent)4 RemoteException (android.os.RemoteException)4 PersistentDataBlockManager (android.service.persistentdata.PersistentDataBlockManager)4 TargetApi (android.annotation.TargetApi)2 Preference (android.support.v7.preference.Preference)2 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkTemplate (android.net.NetworkTemplate)1