Search in sources :

Example 1 with SubscriptionManager

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

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

use of android.telephony.SubscriptionManager in project NetGuard by M66B.

the class ServiceSinkhole method onDestroy.

@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");
    commandLooper.quit();
    logLooper.quit();
    statsLooper.quit();
    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageChanged) {
        unregisterReceiver(packageChangedReceiver);
        registeredPackageChanged = false;
    }
    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }
    if (subscriptionsChangedListener != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener((SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }
    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    jni_done();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    super.onDestroy();
}
Also used : TelephonyManager(android.telephony.TelephonyManager) SharedPreferences(android.content.SharedPreferences) SubscriptionManager(android.telephony.SubscriptionManager)

Example 3 with SubscriptionManager

use of android.telephony.SubscriptionManager in project NetGuard by M66B.

the class Util method getSubscriptionInfo.

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";
    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);
    sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/').append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n");
    int dataid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        dataid = sm.getDefaultDataSubscriptionId();
    int voiceid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        voiceid = sm.getDefaultVoiceSubscriptionId();
    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions) sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId()).append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc()).append(' ').append(si.getCarrierName()).append(si.getSubscriptionId() == dataid ? " D" : "").append(si.getSubscriptionId() == voiceid ? " V" : "").append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "").append("\r\n");
    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);
    return sb.toString();
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) TargetApi(android.annotation.TargetApi)

Example 4 with SubscriptionManager

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

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

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

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