Search in sources :

Example 61 with TelephonyManager

use of android.telephony.TelephonyManager in project XobotOS by xamarin.

the class DefaultPhoneNotifier method doNotifyDataConnection.

private void doNotifyDataConnection(Phone sender, String reason, String apnType, Phone.DataState state) {
    // TODO
    // use apnType as the key to which connection we're talking about.
    // pass apnType back up to fetch particular for this one.
    TelephonyManager telephony = TelephonyManager.getDefault();
    LinkProperties linkProperties = null;
    LinkCapabilities linkCapabilities = null;
    boolean roaming = false;
    if (state == Phone.DataState.CONNECTED) {
        linkProperties = sender.getLinkProperties(apnType);
        linkCapabilities = sender.getLinkCapabilities(apnType);
    }
    ServiceState ss = sender.getServiceState();
    if (ss != null)
        roaming = ss.getRoaming();
    try {
        mRegistry.notifyDataConnection(convertDataState(state), sender.isDataConnectivityPossible(apnType), reason, sender.getActiveApnHost(apnType), apnType, linkProperties, linkCapabilities, ((telephony != null) ? telephony.getNetworkType() : TelephonyManager.NETWORK_TYPE_UNKNOWN), roaming);
    } catch (RemoteException ex) {
    // system process is dead
    }
}
Also used : ServiceState(android.telephony.ServiceState) TelephonyManager(android.telephony.TelephonyManager) RemoteException(android.os.RemoteException) LinkProperties(android.net.LinkProperties) LinkCapabilities(android.net.LinkCapabilities)

Example 62 with TelephonyManager

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

the class KeyguardUpdateMonitor method refreshSimState.

/**
     * @return true if and only if the state has changed for the specified {@code slotId}
     */
private boolean refreshSimState(int subId, int slotId) {
    // This is awful. It exists because there are two APIs for getting the SIM status
    // that don't return the complete set of values and have different types. In Keyguard we
    // need IccCardConstants, but TelephonyManager would only give us
    // TelephonyManager.SIM_STATE*, so we retrieve it manually.
    final TelephonyManager tele = TelephonyManager.from(mContext);
    int simState = tele.getSimState(slotId);
    State state;
    try {
        state = State.intToState(simState);
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Unknown sim state: " + simState);
        state = State.UNKNOWN;
    }
    SimData data = mSimDatas.get(subId);
    final boolean changed;
    if (data == null) {
        data = new SimData(state, slotId, subId);
        mSimDatas.put(subId, data);
        // no data yet; force update
        changed = true;
    } else {
        changed = data.simState != state;
        data.simState = state;
    }
    return changed;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) State(com.android.internal.telephony.IccCardConstants.State) ServiceState(android.telephony.ServiceState) Fingerprint(android.hardware.fingerprint.Fingerprint)

Example 63 with TelephonyManager

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

the class UsageStatsService method fetchCarrierPrivilegedAppsLocked.

private void fetchCarrierPrivilegedAppsLocked() {
    TelephonyManager telephonyManager = getContext().getSystemService(TelephonyManager.class);
    mCarrierPrivilegedApps = telephonyManager.getPackagesWithCarrierPrivileges();
    mHaveCarrierPrivilegedApps = true;
    if (DEBUG) {
        Slog.d(TAG, "apps with carrier privilege " + mCarrierPrivilegedApps);
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager)

Example 64 with TelephonyManager

use of android.telephony.TelephonyManager in project ride-read-android by Ride-Read.

the class NetworkUtils method getDataEnabled.

/**
     * 判断网络是否可用
     * <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
     *
     * @return {@code true}: 可用<br>{@code false}: 不可用
    //     */
//    public static boolean isAvailableByPing() {
//        ShellUtils.CommandResult result = ShellUtils.execCmd("ping -c 1 -w 1 223.5.5.5", false);
//        boolean ret = result.result == 0;
//        if (result.errorMsg != null) {
//            LogUtils.d("isAvailableByPing errorMsg", result.errorMsg);
//        }
//        if (result.successMsg != null) {
//            LogUtils.d("isAvailableByPing successMsg", result.successMsg);
//        }
//        return ret;
//    }
/**
     * 判断移动数据是否打开
     *
     * @return {@code true}: 是<br>{@code false}: 否
     */
public static boolean getDataEnabled() {
    try {
        TelephonyManager tm = (TelephonyManager) Utils.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
        Method getMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("getDataEnabled");
        if (null != getMobileDataEnabledMethod) {
            return (boolean) getMobileDataEnabledMethod.invoke(tm);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) Method(java.lang.reflect.Method)

Example 65 with TelephonyManager

use of android.telephony.TelephonyManager in project ride-read-android by Ride-Read.

the class NetworkUtils method setDataEnabled.

/**
     * 打开或关闭移动数据
     * <p>需系统应用 需添加权限{@code <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>}</p>
     *
     * @param enabled {@code true}: 打开<br>{@code false}: 关闭
     */
public static void setDataEnabled(boolean enabled) {
    try {
        TelephonyManager tm = (TelephonyManager) Utils.getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
        Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
        if (null != setMobileDataEnabledMethod) {
            setMobileDataEnabledMethod.invoke(tm, enabled);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) Method(java.lang.reflect.Method)

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