Search in sources :

Example 61 with ConnectivityManager

use of android.net.ConnectivityManager in project platform_frameworks_base by android.

the class ProvisionObserver method onStartJob.

@Override
public boolean onStartJob(JobParameters jobParameters) {
    switch(jobParameters.getJobId()) {
        case PROVISION_OBSERVER_REEVALUATION_JOB_ID:
            if (isProvisioned(this)) {
                Log.d(TAG, "device provisioned, force network re-evaluation");
                final ConnectivityManager connMgr = ConnectivityManager.from(this);
                Network[] info = connMgr.getAllNetworks();
                for (Network nw : info) {
                    final NetworkCapabilities nc = connMgr.getNetworkCapabilities(nw);
                    if (nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) && nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
                        // force connectivity re-evaluation to assume skipped carrier actions.
                        // one of the following calls will match the last evaluation.
                        connMgr.reportNetworkConnectivity(nw, true);
                        connMgr.reportNetworkConnectivity(nw, false);
                        break;
                    }
                }
            }
        default:
            break;
    }
    return false;
}
Also used : ConnectivityManager(android.net.ConnectivityManager) Network(android.net.Network) NetworkCapabilities(android.net.NetworkCapabilities)

Example 62 with ConnectivityManager

use of android.net.ConnectivityManager in project platform_frameworks_base by android.

the class AirplaneModeTile method setEnabled.

private void setEnabled(boolean enabled) {
    final ConnectivityManager mgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    mgr.setAirplaneMode(enabled);
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 63 with ConnectivityManager

use of android.net.ConnectivityManager in project platform_frameworks_base by android.

the class DevicePolicyManagerService method setAlwaysOnVpnPackage.

/**
     * @return {@code true} if the package is installed and set as always-on, {@code false} if it is
     * not installed and therefore not available.
     *
     * @throws SecurityException if the caller is not a profile or device owner.
     * @throws UnsupportedOperationException if the package does not support being set as always-on.
     */
@Override
public boolean setAlwaysOnVpnPackage(ComponentName admin, String vpnPackage, boolean lockdown) throws SecurityException {
    synchronized (this) {
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    }
    final int userId = mInjector.userHandleGetCallingUserId();
    final long token = mInjector.binderClearCallingIdentity();
    try {
        if (vpnPackage != null && !isPackageInstalledForUser(vpnPackage, userId)) {
            return false;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (!connectivityManager.setAlwaysOnVpnPackageForUser(userId, vpnPackage, lockdown)) {
            throw new UnsupportedOperationException();
        }
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
    return true;
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 64 with ConnectivityManager

use of android.net.ConnectivityManager in project platform_frameworks_base by android.

the class DevicePolicyManagerService method getAlwaysOnVpnPackage.

@Override
public String getAlwaysOnVpnPackage(ComponentName admin) throws SecurityException {
    synchronized (this) {
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
    }
    final int userId = mInjector.userHandleGetCallingUserId();
    final long token = mInjector.binderClearCallingIdentity();
    try {
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        return connectivityManager.getAlwaysOnVpnPackageForUser(userId);
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 65 with ConnectivityManager

use of android.net.ConnectivityManager in project Android-CleanArchitecture by android10.

the class AutoLoadImageView method isThereInternetConnection.

/**
   * Checks if the device has any active internet connection.
   *
   * @return true device with internet connection, otherwise false.
   */
private boolean isThereInternetConnection() {
    boolean isConnected;
    final ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());
    return isConnected;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)361 NetworkInfo (android.net.NetworkInfo)258 Context (android.content.Context)15 TelephonyManager (android.telephony.TelephonyManager)13 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 Intent (android.content.Intent)10 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 UserManager (android.os.UserManager)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5