am 9a1da68b: Expose a SystemApi method to prepare a VPN without consent.

* commit '9a1da68bf7980449a5ee5d6fa9d9686b04d667ff':
  Expose a SystemApi method to prepare a VPN without consent.
This commit is contained in:
Jeff Davidson
2014-11-17 22:58:12 +00:00
committed by Android Git Automerger
2 changed files with 31 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ package android.net;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.Service;
@@ -163,6 +164,32 @@ public class VpnService extends Service {
return VpnConfig.getIntentForConfirmation();
}
/**
* Version of {@link #prepare(Context)} which does not require user consent.
*
* <p>Requires {@link android.Manifest.permission#CONTROL_VPN} and should generally not be
* used. Only acceptable in situations where user consent has been obtained through other means.
*
* <p>Once this is run, future preparations may be done with the standard prepare method as this
* will authorize the package to prepare the VPN without consent in the future.
*
* @hide
*/
@SystemApi
public static void prepareAndAuthorize(Context context) {
IConnectivityManager cm = getService();
String packageName = context.getPackageName();
try {
// Only prepare if we're not already prepared.
if (!cm.prepareVpn(packageName, null)) {
cm.prepareVpn(null, packageName);
}
cm.setVpnPackageAuthorization(true);
} catch (RemoteException e) {
// ignore
}
}
/**
* Protect a socket from VPN connections. After protecting, data sent
* through this socket will go directly to the underlying network,

View File

@@ -2813,9 +2813,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
/**
* Prepare for a VPN application. This method is used by VpnDialogs
* and not available in ConnectivityManager. Permissions are checked
* in Vpn class.
* Prepare for a VPN application. This method is used by system-privileged apps.
* Permissions are checked in Vpn class.
* @hide
*/
@Override
@@ -2829,8 +2828,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
/**
* Set whether the current VPN package has the ability to launch VPNs without
* user intervention. This method is used by system UIs and not available
* in ConnectivityManager. Permissions are checked in Vpn class.
* user intervention. This method is used by system-privileged apps.
* Permissions are checked in Vpn class.
* @hide
*/
@Override