VpnDialogs: prepare for the usages of legacy VPN.
- Use PendingIntent to start activities. - Handle configs without package names. - Switch to system UID. Change-Id: Ia78112a97e3628b603d9e059705e32694ebe142b
This commit is contained in:
@@ -58,7 +58,7 @@ public class VpnConfig implements Parcelable {
|
||||
public String packageName;
|
||||
public String sessionName;
|
||||
public String interfaceName;
|
||||
public String configureActivity;
|
||||
public PendingIntent configureIntent;
|
||||
public int mtu = -1;
|
||||
public String addresses;
|
||||
public String routes;
|
||||
@@ -75,7 +75,7 @@ public class VpnConfig implements Parcelable {
|
||||
out.writeString(packageName);
|
||||
out.writeString(sessionName);
|
||||
out.writeString(interfaceName);
|
||||
out.writeString(configureActivity);
|
||||
out.writeParcelable(configureIntent, flags);
|
||||
out.writeInt(mtu);
|
||||
out.writeString(addresses);
|
||||
out.writeString(routes);
|
||||
@@ -91,7 +91,7 @@ public class VpnConfig implements Parcelable {
|
||||
config.packageName = in.readString();
|
||||
config.sessionName = in.readString();
|
||||
config.interfaceName = in.readString();
|
||||
config.configureActivity = in.readString();
|
||||
config.configureIntent = in.readParcelable(null);
|
||||
config.mtu = in.readInt();
|
||||
config.addresses = in.readString();
|
||||
config.routes = in.readString();
|
||||
|
||||
@@ -20,6 +20,8 @@ include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := VpnDialogs
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.vpndialogs">
|
||||
package="com.android.vpndialogs"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<application android:label="VpnDialogs">
|
||||
<activity android:name=".ConfirmDialog"
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
<string name="accept">I trust this application.</string>
|
||||
|
||||
<string name="legacy_title">VPN is connected</string>
|
||||
<string name="configure">Configure</string>
|
||||
<string name="disconnect">Disconnect</string>
|
||||
|
||||
|
||||
@@ -64,9 +64,6 @@ public class ManageDialog extends Activity implements Handler.Callback,
|
||||
mService = IConnectivityManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
||||
|
||||
PackageManager pm = getPackageManager();
|
||||
ApplicationInfo app = pm.getApplicationInfo(mConfig.packageName, 0);
|
||||
|
||||
View view = View.inflate(this, R.layout.manage, null);
|
||||
if (mConfig.sessionName != null) {
|
||||
((TextView) view.findViewById(R.id.session)).setText(mConfig.sessionName);
|
||||
@@ -75,15 +72,29 @@ public class ManageDialog extends Activity implements Handler.Callback,
|
||||
mDataTransmitted = (TextView) view.findViewById(R.id.data_transmitted);
|
||||
mDataReceived = (TextView) view.findViewById(R.id.data_received);
|
||||
|
||||
mDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(app.loadIcon(pm))
|
||||
.setTitle(app.loadLabel(pm))
|
||||
.setView(view)
|
||||
.setNeutralButton(R.string.disconnect, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create();
|
||||
if (mConfig.packageName == null) {
|
||||
// Legacy VPN does not have a package name.
|
||||
mDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.setTitle(R.string.legacy_title)
|
||||
.setView(view)
|
||||
.setNeutralButton(R.string.disconnect, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create();
|
||||
} else {
|
||||
PackageManager pm = getPackageManager();
|
||||
ApplicationInfo app = pm.getApplicationInfo(mConfig.packageName, 0);
|
||||
|
||||
if (mConfig.configureActivity != null) {
|
||||
mDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(app.loadIcon(pm))
|
||||
.setTitle(app.loadLabel(pm))
|
||||
.setView(view)
|
||||
.setNeutralButton(R.string.disconnect, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create();
|
||||
}
|
||||
|
||||
if (mConfig.configureIntent != null) {
|
||||
mDialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||
getText(R.string.configure), this);
|
||||
}
|
||||
@@ -113,9 +124,7 @@ public class ManageDialog extends Activity implements Handler.Callback,
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
if (which == AlertDialog.BUTTON_POSITIVE) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(mConfig.packageName, mConfig.configureActivity);
|
||||
startActivity(intent);
|
||||
mConfig.configureIntent.send();
|
||||
} else if (which == AlertDialog.BUTTON_NEUTRAL) {
|
||||
mService.prepareVpn("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user