Merge "Switch SystemUI from IConnectivityManager to VpnManager."
This commit is contained in:
@@ -27,12 +27,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.ConnectivityManager.NetworkCallback;
|
import android.net.ConnectivityManager.NetworkCallback;
|
||||||
import android.net.IConnectivityManager;
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
|
import android.net.VpnManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.security.KeyChain;
|
import android.security.KeyChain;
|
||||||
@@ -75,7 +74,7 @@ public class SecurityControllerImpl extends CurrentUserTracker implements Securi
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
private final IConnectivityManager mConnectivityManagerService;
|
private final VpnManager mVpnManager;
|
||||||
private final DevicePolicyManager mDevicePolicyManager;
|
private final DevicePolicyManager mDevicePolicyManager;
|
||||||
private final PackageManager mPackageManager;
|
private final PackageManager mPackageManager;
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
@@ -107,8 +106,7 @@ public class SecurityControllerImpl extends CurrentUserTracker implements Securi
|
|||||||
context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
mConnectivityManager = (ConnectivityManager)
|
mConnectivityManager = (ConnectivityManager)
|
||||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mConnectivityManagerService = IConnectivityManager.Stub.asInterface(
|
mVpnManager = context.getSystemService(VpnManager.class);
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
mBgExecutor = bgExecutor;
|
mBgExecutor = bgExecutor;
|
||||||
@@ -346,25 +344,19 @@ public class SecurityControllerImpl extends CurrentUserTracker implements Securi
|
|||||||
private void updateState() {
|
private void updateState() {
|
||||||
// Find all users with an active VPN
|
// Find all users with an active VPN
|
||||||
SparseArray<VpnConfig> vpns = new SparseArray<>();
|
SparseArray<VpnConfig> vpns = new SparseArray<>();
|
||||||
try {
|
for (UserInfo user : mUserManager.getUsers()) {
|
||||||
for (UserInfo user : mUserManager.getUsers()) {
|
VpnConfig cfg = mVpnManager.getVpnConfig(user.id);
|
||||||
VpnConfig cfg = mConnectivityManagerService.getVpnConfig(user.id);
|
if (cfg == null) {
|
||||||
if (cfg == null) {
|
continue;
|
||||||
|
} else if (cfg.legacy) {
|
||||||
|
// Legacy VPNs should do nothing if the network is disconnected. Third-party
|
||||||
|
// VPN warnings need to continue as traffic can still go to the app.
|
||||||
|
LegacyVpnInfo legacyVpn = mVpnManager.getLegacyVpnInfo(user.id);
|
||||||
|
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
|
||||||
continue;
|
continue;
|
||||||
} else if (cfg.legacy) {
|
|
||||||
// Legacy VPNs should do nothing if the network is disconnected. Third-party
|
|
||||||
// VPN warnings need to continue as traffic can still go to the app.
|
|
||||||
LegacyVpnInfo legacyVpn = mConnectivityManagerService.getLegacyVpnInfo(user.id);
|
|
||||||
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vpns.put(user.id, cfg);
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException rme) {
|
vpns.put(user.id, cfg);
|
||||||
// Roll back to previous state
|
|
||||||
Log.e(TAG, "Unable to list active VPNs", rme);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
mCurrentVpns = vpns;
|
mCurrentVpns = vpns;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user