Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with TelephonyManager

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

the class GlobalActions method setupAirplaneModeListeners.

/**
     * Since there are two ways of handling airplane mode (with telephony, we depend on the internal
     * device telephony state), and MSIM devices do not report phone state for missing SIMs, we
     * need to dynamically setup listeners based on subscription changes.
     *
     * So if there is _any_ active SIM in the device, we can depend on the phone state,
     * otherwise fall back to {@link Settings.Global#AIRPLANE_MODE_ON}.
     */
private void setupAirplaneModeListeners() {
    TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    for (PhoneStateListener listener : mPhoneStateListeners) {
        telephonyManager.listen(listener, PhoneStateListener.LISTEN_NONE);
    }
    mPhoneStateListeners.clear();
    final List<SubscriptionInfo> subInfoList = SubscriptionManager.from(mContext).getActiveSubscriptionInfoList();
    if (subInfoList != null) {
        mHasTelephony = true;
        mAirplaneModeBits = new BitSet(subInfoList.size());
        for (int i = 0; i < subInfoList.size(); i++) {
            final int finalI = i;
            PhoneStateListener subListener = new PhoneStateListener(subInfoList.get(finalI).getSubscriptionId()) {

                @Override
                public void onServiceStateChanged(ServiceState serviceState) {
                    final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
                    mAirplaneModeBits.set(finalI, inAirplaneMode);
                    // we're in airplane mode if _any_ of the subscriptions say we are
                    mAirplaneState = mAirplaneModeBits.cardinality() > 0 ? ToggleAction.State.On : ToggleAction.State.Off;
                    mAirplaneModeOn.updateState(mAirplaneState);
                    if (mAdapter != null) {
                        mAdapter.notifyDataSetChanged();
                    }
                }
            };
            mPhoneStateListeners.add(subListener);
            telephonyManager.listen(subListener, PhoneStateListener.LISTEN_SERVICE_STATE);
        }
    } else {
        mHasTelephony = false;
    }
    // Set the initial status of airplane mode toggle
    mAirplaneState = getUpdatedAirplaneToggleState();
}
Also used : ServiceState(android.telephony.ServiceState) TelephonyManager(android.telephony.TelephonyManager) PhoneStateListener(android.telephony.PhoneStateListener) BitSet(java.util.BitSet) SubscriptionInfo(android.telephony.SubscriptionInfo) Paint(android.graphics.Paint)

Aggregations

TelephonyManager (android.telephony.TelephonyManager)679 SubscriptionInfo (android.telephony.SubscriptionInfo)64 ConnectivityManager (android.net.ConnectivityManager)59 SubscriptionManager (android.telephony.SubscriptionManager)53 Context (android.content.Context)42 Method (java.lang.reflect.Method)40 Intent (android.content.Intent)34 IOException (java.io.IOException)30 SuppressLint (android.annotation.SuppressLint)29 ArrayList (java.util.ArrayList)26 PhoneAccountHandle (android.telecom.PhoneAccountHandle)24 NetworkTemplate (android.net.NetworkTemplate)22 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)20 PhoneAccount (android.telecom.PhoneAccount)19 Test (org.junit.Test)18 Preference (android.support.v7.preference.Preference)17 TelecomManager (android.telecom.TelecomManager)17 View (android.view.View)17 DialogInterface (android.content.DialogInterface)16 Resources (android.content.res.Resources)16