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);
}
}
}
}
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();
}
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();
}
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);
}
}
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;
}
}
Aggregations