Search in sources :

Example 31 with SubscriptionManager

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

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

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

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)

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