Search in sources :

Example 21 with SubscriptionManager

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

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 22 with SubscriptionManager

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

the class NetworkPolicyManagerService method ensureActiveMobilePolicyNL.

/**
     * Once any {@link #mNetworkPolicy} are loaded from disk, ensure that we
     * have at least a default mobile policy defined.
     */
private void ensureActiveMobilePolicyNL() {
    if (LOGV)
        Slog.v(TAG, "ensureActiveMobilePolicyNL()");
    if (mSuppressDefaultPolicy)
        return;
    final TelephonyManager tele = TelephonyManager.from(mContext);
    final SubscriptionManager sub = SubscriptionManager.from(mContext);
    final int[] subIds = sub.getActiveSubscriptionIdList();
    for (int subId : subIds) {
        final String subscriberId = tele.getSubscriberId(subId);
        ensureActiveMobilePolicyNL(subscriberId);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SubscriptionManager(android.telephony.SubscriptionManager) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Example 23 with SubscriptionManager

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

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)

Example 24 with SubscriptionManager

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

the class NetworkPolicyManagerService method isTemplateRelevant.

/**
     * Test if given {@link NetworkTemplate} is relevant to user based on
     * current device state, such as when
     * {@link TelephonyManager#getSubscriberId()} matches. This is regardless of
     * data connection status.
     */
private boolean isTemplateRelevant(NetworkTemplate template) {
    if (template.isMatchRuleMobile()) {
        final TelephonyManager tele = TelephonyManager.from(mContext);
        final SubscriptionManager sub = SubscriptionManager.from(mContext);
        // Mobile template is relevant when any active subscriber matches
        final int[] subIds = sub.getActiveSubscriptionIdList();
        for (int subId : subIds) {
            final String subscriberId = tele.getSubscriberId(subId);
            final NetworkIdentity probeIdent = new NetworkIdentity(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false, true);
            if (template.matches(probeIdent)) {
                return true;
            }
        }
        return false;
    } else {
        return true;
    }
}
Also used : NetworkIdentity(android.net.NetworkIdentity) TelephonyManager(android.telephony.TelephonyManager) SubscriptionManager(android.telephony.SubscriptionManager) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

Example 25 with SubscriptionManager

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

the class NetworkPolicyManagerService method ensureActiveMobilePolicyNL.

/**
     * Once any {@link #mNetworkPolicy} are loaded from disk, ensure that we
     * have at least a default mobile policy defined.
     */
private void ensureActiveMobilePolicyNL() {
    if (LOGV)
        Slog.v(TAG, "ensureActiveMobilePolicyNL()");
    if (mSuppressDefaultPolicy)
        return;
    final TelephonyManager tele = TelephonyManager.from(mContext);
    final SubscriptionManager sub = SubscriptionManager.from(mContext);
    final int[] subIds = sub.getActiveSubscriptionIdList();
    for (int subId : subIds) {
        final String subscriberId = tele.getSubscriberId(subId);
        ensureActiveMobilePolicyNL(subscriberId);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SubscriptionManager(android.telephony.SubscriptionManager) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString)

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