Merge "Switch VpnDialogs from IConnectivityManager to IVpnManager." am: dbe68e90d7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1574868 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Iaa46f6685b840a5993f86e1856f1e35c5726f0fd
This commit is contained in:
@@ -20,14 +20,11 @@ import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.IConnectivityManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.SpannableStringBuilder;
|
||||
@@ -45,7 +42,7 @@ public class AlwaysOnDisconnectedDialog extends AlertActivity
|
||||
|
||||
private static final String TAG = "VpnDisconnected";
|
||||
|
||||
private IConnectivityManager mService;
|
||||
private ConnectivityManager mService;
|
||||
private int mUserId;
|
||||
private String mVpnPackage;
|
||||
|
||||
@@ -53,10 +50,9 @@ public class AlwaysOnDisconnectedDialog extends AlertActivity
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mService = IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
mUserId = UserHandle.myUserId();
|
||||
mVpnPackage = getAlwaysOnVpnPackage();
|
||||
final ConnectivityManager cm = getSystemService(ConnectivityManager.class);
|
||||
mVpnPackage = cm.getAlwaysOnVpnPackageForUser(mUserId);
|
||||
if (mVpnPackage == null) {
|
||||
finish();
|
||||
return;
|
||||
@@ -102,15 +98,6 @@ public class AlwaysOnDisconnectedDialog extends AlertActivity
|
||||
}
|
||||
}
|
||||
|
||||
private String getAlwaysOnVpnPackage() {
|
||||
try {
|
||||
return mService.getAlwaysOnVpnPackage(mUserId);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Can't getAlwaysOnVpnPackage()", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getVpnLabel() {
|
||||
try {
|
||||
return VpnConfig.getVpnLabel(this, mVpnPackage);
|
||||
|
||||
@@ -18,15 +18,12 @@ package com.android.vpndialogs;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.IConnectivityManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.VpnManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.Html;
|
||||
@@ -48,7 +45,8 @@ public class ConfirmDialog extends AlertActivity
|
||||
|
||||
private String mPackage;
|
||||
|
||||
private IConnectivityManager mService;
|
||||
private ConnectivityManager mCm; // TODO: switch entirely to VpnManager once VPN code moves
|
||||
private VpnManager mVm;
|
||||
|
||||
public ConfirmDialog() {
|
||||
this(VpnManager.TYPE_VPN_SERVICE);
|
||||
@@ -62,10 +60,10 @@ public class ConfirmDialog extends AlertActivity
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPackage = getCallingPackage();
|
||||
mService = IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
mCm = getSystemService(ConnectivityManager.class);
|
||||
mVm = getSystemService(VpnManager.class);
|
||||
|
||||
if (prepareVpn()) {
|
||||
if (mVm.prepareVpn(mPackage, null, UserHandle.myUserId())) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
return;
|
||||
@@ -74,7 +72,7 @@ public class ConfirmDialog extends AlertActivity
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
final String alwaysOnVpnPackage = getAlwaysOnVpnPackage();
|
||||
final String alwaysOnVpnPackage = mCm.getAlwaysOnVpnPackageForUser(UserHandle.myUserId());
|
||||
// Can't prepare new vpn app when another vpn is always-on
|
||||
if (alwaysOnVpnPackage != null && !alwaysOnVpnPackage.equals(mPackage)) {
|
||||
finish();
|
||||
@@ -97,24 +95,6 @@ public class ConfirmDialog extends AlertActivity
|
||||
button.setFilterTouchesWhenObscured(true);
|
||||
}
|
||||
|
||||
private String getAlwaysOnVpnPackage() {
|
||||
try {
|
||||
return mService.getAlwaysOnVpnPackage(UserHandle.myUserId());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "fail to call getAlwaysOnVpnPackage", e);
|
||||
// Fallback to null to show the dialog
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean prepareVpn() {
|
||||
try {
|
||||
return mService.prepareVpn(mPackage, null, UserHandle.myUserId());
|
||||
} catch (RemoteException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getVpnLabel() {
|
||||
try {
|
||||
return VpnConfig.getVpnLabel(this, mPackage);
|
||||
@@ -146,10 +126,10 @@ public class ConfirmDialog extends AlertActivity
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
if (mService.prepareVpn(null, mPackage, UserHandle.myUserId())) {
|
||||
if (mVm.prepareVpn(null, mPackage, UserHandle.myUserId())) {
|
||||
// Authorize this app to initiate VPN connections in the future without user
|
||||
// intervention.
|
||||
mService.setVpnPackageAuthorization(mPackage, UserHandle.myUserId(), mVpnType);
|
||||
mVm.setVpnPackageAuthorization(mPackage, UserHandle.myUserId(), mVpnType);
|
||||
setResult(RESULT_OK);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package com.android.vpndialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.IConnectivityManager;
|
||||
import android.net.VpnManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
@@ -41,7 +39,7 @@ public class ManageDialog extends AlertActivity implements
|
||||
|
||||
private VpnConfig mConfig;
|
||||
|
||||
private IConnectivityManager mService;
|
||||
private VpnManager mVm;
|
||||
|
||||
private TextView mDuration;
|
||||
private TextView mDataTransmitted;
|
||||
@@ -55,11 +53,9 @@ public class ManageDialog extends AlertActivity implements
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
try {
|
||||
mVm = getSystemService(VpnManager.class);
|
||||
|
||||
mService = IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
|
||||
mConfig = mService.getVpnConfig(UserHandle.myUserId());
|
||||
mConfig = mVm.getVpnConfig(UserHandle.myUserId());
|
||||
|
||||
// mConfig can be null if we are a restricted user, in that case don't show this dialog
|
||||
if (mConfig == null) {
|
||||
@@ -118,9 +114,9 @@ public class ManageDialog extends AlertActivity implements
|
||||
} else if (which == DialogInterface.BUTTON_NEUTRAL) {
|
||||
final int myUserId = UserHandle.myUserId();
|
||||
if (mConfig.legacy) {
|
||||
mService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN, myUserId);
|
||||
mVm.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN, myUserId);
|
||||
} else {
|
||||
mService.prepareVpn(mConfig.user, VpnConfig.LEGACY_VPN, myUserId);
|
||||
mVm.prepareVpn(mConfig.user, VpnConfig.LEGACY_VPN, myUserId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user