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:
Lorenzo Colitti
2021-02-08 14:51:09 +00:00
committed by Automerger Merge Worker
3 changed files with 19 additions and 56 deletions

View File

@@ -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.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.IConnectivityManager; import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@@ -45,7 +42,7 @@ public class AlwaysOnDisconnectedDialog extends AlertActivity
private static final String TAG = "VpnDisconnected"; private static final String TAG = "VpnDisconnected";
private IConnectivityManager mService; private ConnectivityManager mService;
private int mUserId; private int mUserId;
private String mVpnPackage; private String mVpnPackage;
@@ -53,10 +50,9 @@ public class AlwaysOnDisconnectedDialog extends AlertActivity
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
mUserId = UserHandle.myUserId(); mUserId = UserHandle.myUserId();
mVpnPackage = getAlwaysOnVpnPackage(); final ConnectivityManager cm = getSystemService(ConnectivityManager.class);
mVpnPackage = cm.getAlwaysOnVpnPackageForUser(mUserId);
if (mVpnPackage == null) { if (mVpnPackage == null) {
finish(); finish();
return; 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() { private CharSequence getVpnLabel() {
try { try {
return VpnConfig.getVpnLabel(this, mVpnPackage); return VpnConfig.getVpnLabel(this, mVpnPackage);

View File

@@ -18,15 +18,12 @@ package com.android.vpndialogs;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.IConnectivityManager; import android.net.ConnectivityManager;
import android.net.VpnManager; import android.net.VpnManager;
import android.os.Bundle; import android.os.Bundle;
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.text.Html; import android.text.Html;
@@ -48,7 +45,8 @@ public class ConfirmDialog extends AlertActivity
private String mPackage; private String mPackage;
private IConnectivityManager mService; private ConnectivityManager mCm; // TODO: switch entirely to VpnManager once VPN code moves
private VpnManager mVm;
public ConfirmDialog() { public ConfirmDialog() {
this(VpnManager.TYPE_VPN_SERVICE); this(VpnManager.TYPE_VPN_SERVICE);
@@ -62,10 +60,10 @@ public class ConfirmDialog extends AlertActivity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mPackage = getCallingPackage(); mPackage = getCallingPackage();
mService = IConnectivityManager.Stub.asInterface( mCm = getSystemService(ConnectivityManager.class);
ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); mVm = getSystemService(VpnManager.class);
if (prepareVpn()) { if (mVm.prepareVpn(mPackage, null, UserHandle.myUserId())) {
setResult(RESULT_OK); setResult(RESULT_OK);
finish(); finish();
return; return;
@@ -74,7 +72,7 @@ public class ConfirmDialog extends AlertActivity
finish(); finish();
return; return;
} }
final String alwaysOnVpnPackage = getAlwaysOnVpnPackage(); final String alwaysOnVpnPackage = mCm.getAlwaysOnVpnPackageForUser(UserHandle.myUserId());
// Can't prepare new vpn app when another vpn is always-on // Can't prepare new vpn app when another vpn is always-on
if (alwaysOnVpnPackage != null && !alwaysOnVpnPackage.equals(mPackage)) { if (alwaysOnVpnPackage != null && !alwaysOnVpnPackage.equals(mPackage)) {
finish(); finish();
@@ -97,24 +95,6 @@ public class ConfirmDialog extends AlertActivity
button.setFilterTouchesWhenObscured(true); 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() { private CharSequence getVpnLabel() {
try { try {
return VpnConfig.getVpnLabel(this, mPackage); return VpnConfig.getVpnLabel(this, mPackage);
@@ -146,10 +126,10 @@ public class ConfirmDialog extends AlertActivity
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
try { 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 // Authorize this app to initiate VPN connections in the future without user
// intervention. // intervention.
mService.setVpnPackageAuthorization(mPackage, UserHandle.myUserId(), mVpnType); mVm.setVpnPackageAuthorization(mPackage, UserHandle.myUserId(), mVpnType);
setResult(RESULT_OK); setResult(RESULT_OK);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@@ -16,13 +16,11 @@
package com.android.vpndialogs; package com.android.vpndialogs;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.net.IConnectivityManager; import android.net.VpnManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Log; import android.util.Log;
@@ -41,7 +39,7 @@ public class ManageDialog extends AlertActivity implements
private VpnConfig mConfig; private VpnConfig mConfig;
private IConnectivityManager mService; private VpnManager mVm;
private TextView mDuration; private TextView mDuration;
private TextView mDataTransmitted; private TextView mDataTransmitted;
@@ -55,11 +53,9 @@ public class ManageDialog extends AlertActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
try { try {
mVm = getSystemService(VpnManager.class);
mService = IConnectivityManager.Stub.asInterface( mConfig = mVm.getVpnConfig(UserHandle.myUserId());
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
mConfig = mService.getVpnConfig(UserHandle.myUserId());
// mConfig can be null if we are a restricted user, in that case don't show this dialog // mConfig can be null if we are a restricted user, in that case don't show this dialog
if (mConfig == null) { if (mConfig == null) {
@@ -118,9 +114,9 @@ public class ManageDialog extends AlertActivity implements
} else if (which == DialogInterface.BUTTON_NEUTRAL) { } else if (which == DialogInterface.BUTTON_NEUTRAL) {
final int myUserId = UserHandle.myUserId(); final int myUserId = UserHandle.myUserId();
if (mConfig.legacy) { if (mConfig.legacy) {
mService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN, myUserId); mVm.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN, myUserId);
} else { } else {
mService.prepareVpn(mConfig.user, VpnConfig.LEGACY_VPN, myUserId); mVm.prepareVpn(mConfig.user, VpnConfig.LEGACY_VPN, myUserId);
} }
} }
} catch (Exception e) { } catch (Exception e) {