Search in sources :

Example 66 with TelephonyManager

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

the class DeviceInfoUtils method getFormattedPhoneNumbers.

public static String getFormattedPhoneNumbers(Context context, List<SubscriptionInfo> subscriptionInfo) {
    StringBuilder sb = new StringBuilder();
    if (subscriptionInfo != null) {
        final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
        final int count = subscriptionInfo.size();
        for (int i = 0; i < count; i++) {
            final String rawNumber = telephonyManager.getLine1Number(subscriptionInfo.get(i).getSubscriptionId());
            if (!TextUtils.isEmpty(rawNumber)) {
                sb.append(PhoneNumberUtils.formatNumber(rawNumber));
                if (i < count - 1) {
                    sb.append("\n");
                }
            }
        }
    }
    return sb.toString();
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 67 with TelephonyManager

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

the class GnssLocationProvider method subscriptionOrSimChanged.

private void subscriptionOrSimChanged(Context context) {
    if (DEBUG)
        Log.d(TAG, "received SIM related action: ");
    TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    String mccMnc = phone.getSimOperator();
    String imsi = phone.getSubscriberId();
    String groupId = phone.getGroupIdLevel1();
    if (!TextUtils.isEmpty(mccMnc)) {
        if (DEBUG)
            Log.d(TAG, "SIM MCC/MNC is available: " + mccMnc);
        synchronized (mLock) {
            if (isVerizon(mccMnc, imsi, groupId)) {
                // load current properties for carrier VZW
                loadPropertiesFromResource(context, mProperties);
                String lpp_profile = mProperties.getProperty("LPP_PROFILE");
                // set the persist property LPP_PROFILE for VZW
                SystemProperties.set(LPP_PROFILE, lpp_profile);
            } else {
                // reset the persist property for Non VZW
                SystemProperties.set(LPP_PROFILE, "");
            }
            reloadGpsProperties(context, mProperties);
            mNIHandler.setSuplEsEnabled(mSuplEsEnabled);
        }
    } else {
        if (DEBUG)
            Log.d(TAG, "SIM MCC/MNC is still not available");
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 68 with TelephonyManager

use of android.telephony.TelephonyManager 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 69 with TelephonyManager

use of android.telephony.TelephonyManager 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)

Example 70 with TelephonyManager

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

the class NetworkStatsAccess method checkAccessLevel.

/** Returns the {@link NetworkStatsAccess.Level} for the given caller. */
@NetworkStatsAccess.Level
public static int checkAccessLevel(Context context, int callingUid, String callingPackage) {
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(DevicePolicyManagerInternal.class);
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    boolean hasCarrierPrivileges = tm != null && tm.checkCarrierPrivilegesForPackage(callingPackage) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
    boolean isDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (hasCarrierPrivileges || isDeviceOwner || UserHandle.getAppId(callingUid) == android.os.Process.SYSTEM_UID) {
        // all apps on the device.
        return NetworkStatsAccess.Level.DEVICE;
    }
    boolean hasAppOpsPermission = hasAppOpsPermission(context, callingUid, callingPackage);
    if (hasAppOpsPermission || context.checkCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY) == PackageManager.PERMISSION_GRANTED) {
        return NetworkStatsAccess.Level.DEVICESUMMARY;
    }
    boolean isProfileOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    if (isProfileOwner) {
        // permission can access data usage for all apps in this user/profile.
        return NetworkStatsAccess.Level.USER;
    }
    // Everyone else gets default access (only to their own UID).
    return NetworkStatsAccess.Level.DEFAULT;
}
Also used : DevicePolicyManagerInternal(android.app.admin.DevicePolicyManagerInternal) TelephonyManager(android.telephony.TelephonyManager)

Aggregations

TelephonyManager (android.telephony.TelephonyManager)294 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)20 SubscriptionManager (android.telephony.SubscriptionManager)20 Test (org.junit.Test)15 ConnectivityManager (android.net.ConnectivityManager)14 Context (android.content.Context)11 Intent (android.content.Intent)11 NetworkIdentity (android.net.NetworkIdentity)11 Method (java.lang.reflect.Method)11 GsmCellLocation (android.telephony.gsm.GsmCellLocation)10 PackageManager (android.content.pm.PackageManager)9 SubscriptionInfo (android.telephony.SubscriptionInfo)9 IntentFilter (android.content.IntentFilter)8 IOException (java.io.IOException)8 PackageInfo (android.content.pm.PackageInfo)7 ServiceState (android.telephony.ServiceState)7 NetworkPolicy (android.net.NetworkPolicy)6 WifiManager (android.net.wifi.WifiManager)6 DevicePolicyManagerInternal (android.app.admin.DevicePolicyManagerInternal)5 SharedPreferences (android.content.SharedPreferences)5