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;
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations