Search in sources :

Example 71 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)

Example 72 with TelephonyManager

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

the class DataUsageController method getActiveSubscriberId.

private static String getActiveSubscriberId(Context context) {
    final TelephonyManager tele = TelephonyManager.from(context);
    final String actualSubscriberId = tele.getSubscriberId(SubscriptionManager.getDefaultDataSubscriptionId());
    return actualSubscriberId;
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 73 with TelephonyManager

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

the class TwoGToggle method getScreenOffAction.

protected Runnable getScreenOffAction() {
    return new Runnable() {

        @Override
        public void run() {
            TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
            Log.d(TAG, "2G = true");
            tm.toggle2G(true);
        }
    };
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 74 with TelephonyManager

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

the class SimSettings method onCreate.

@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);
    mContext = getActivity();
    mSubscriptionManager = SubscriptionManager.from(getActivity());
    final TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    mExtTelephony = IExtTelephony.Stub.asInterface(ServiceManager.getService("extphone"));
    addPreferencesFromResource(R.xml.sim_settings);
    mNoSims = (SwitchPreference) findPreference(SIM_EMPTY_SWITCH);
    mNumSlots = tm.getSimCount();
    mSimCards = (PreferenceCategory) findPreference(SIM_CARD_CATEGORY);
    mMobileNetwork = (PreferenceCategory) findPreference(MOBILE_NETWORK_CATEGORY);
    mAvailableSubInfos = new ArrayList<SubscriptionInfo>(mNumSlots);
    mSelectableSubInfos = new ArrayList<SubscriptionInfo>();
    SimSelectNotification.cancelNotification(getActivity());
    IntentFilter intentFilter = new IntentFilter(ACTION_UICC_MANUAL_PROVISION_STATUS_CHANGED);
    mContext.registerReceiver(mReceiver, intentFilter);
}
Also used : IntentFilter(android.content.IntentFilter) TelephonyManager(android.telephony.TelephonyManager) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 75 with TelephonyManager

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

the class SimSettings method onPause.

@Override
public void onPause() {
    super.onPause();
    mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
    final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    for (int i = 0; i < mPhoneCount; i++) {
        if (mPhoneStateListener[i] != null) {
            tm.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_NONE);
            mPhoneStateListener[i] = null;
        }
    }
    for (int i = 0; i < mSimCards.getPreferenceCount(); ++i) {
        Preference pref = mSimCards.getPreference(i);
        if (pref instanceof SimEnablerPreference) {
            // Calling cleanUp() here to dismiss/cleanup any pending dialog exists.
            ((SimEnablerPreference) pref).cleanUpPendingDialogs();
        }
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference)

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