diff options
| -rw-r--r-- | core/api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/net/IVpnManager.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/net/VpnManager.java | 15 | ||||
| -rw-r--r-- | services/core/java/com/android/server/VpnManagerService.java | 19 | ||||
| -rw-r--r-- | services/core/java/com/android/server/connectivity/Vpn.java | 40 |
5 files changed, 77 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 9133df9cbc68..1a5f7a78ebb3 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -25507,6 +25507,7 @@ package android.net { public class VpnManager { method public void deleteProvisionedVpnProfile(); + method @Nullable public android.net.VpnProfileState getProvisionedVpnProfileState(); method @Nullable public android.content.Intent provisionVpnProfile(@NonNull android.net.PlatformVpnProfile); method @Deprecated public void startProvisionedVpnProfile(); method @NonNull public String startProvisionedVpnProfileSession(); diff --git a/core/java/android/net/IVpnManager.aidl b/core/java/android/net/IVpnManager.aidl index 070efa363cc0..b4647cabe1bc 100644 --- a/core/java/android/net/IVpnManager.aidl +++ b/core/java/android/net/IVpnManager.aidl @@ -17,6 +17,7 @@ package android.net; import android.net.Network; +import android.net.VpnProfileState; import com.android.internal.net.LegacyVpnInfo; import com.android.internal.net.VpnConfig; @@ -40,6 +41,7 @@ interface IVpnManager { void deleteVpnProfile(String packageName); String startVpnProfile(String packageName); void stopVpnProfile(String packageName); + VpnProfileState getProvisionedVpnProfileState(String packageName); /** Always-on VPN APIs */ boolean isAlwaysOnVpnPackageSupported(int userId, String packageName); diff --git a/core/java/android/net/VpnManager.java b/core/java/android/net/VpnManager.java index 7ffff1a69b06..ae7d91f92cb7 100644 --- a/core/java/android/net/VpnManager.java +++ b/core/java/android/net/VpnManager.java @@ -420,6 +420,21 @@ public class VpnManager { } /** + * Retrieve the VpnProfileState for the profile provisioned by the calling package. + * + * @return the VpnProfileState with current information, or null if there was no profile + * provisioned by the calling package. + */ + @Nullable + public VpnProfileState getProvisionedVpnProfileState() { + try { + return mService.getProvisionedVpnProfileState(mContext.getOpPackageName()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Resets all VPN settings back to factory defaults. * @hide */ diff --git a/services/core/java/com/android/server/VpnManagerService.java b/services/core/java/com/android/server/VpnManagerService.java index 7b8cce54c8a7..c1d8e7bf3dc0 100644 --- a/services/core/java/com/android/server/VpnManagerService.java +++ b/services/core/java/com/android/server/VpnManagerService.java @@ -37,6 +37,7 @@ import android.net.NetworkStack; import android.net.UnderlyingNetworkInfo; import android.net.Uri; import android.net.VpnManager; +import android.net.VpnProfileState; import android.net.VpnService; import android.net.util.NetdService; import android.os.Binder; @@ -374,6 +375,24 @@ public class VpnManagerService extends IVpnManager.Stub { } /** + * Retrieve the VpnProfileState for the profile provisioned by the given package. + * + * @return the VpnProfileState with current information, or null if there was no profile + * provisioned by the given package. + * @hide + */ + @Override + @Nullable + public VpnProfileState getProvisionedVpnProfileState(@NonNull String packageName) { + final int callingUid = Binder.getCallingUid(); + verifyCallingUidAndPackage(packageName, callingUid); + final int user = UserHandle.getUserId(callingUid); + synchronized (mVpns) { + return mVpns.get(user).getProvisionedVpnProfileState(packageName); + } + } + + /** * Start legacy VPN, controlling native daemons as needed. Creates a * secondary thread to perform connection work, returning quickly. * diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index c0df095c3289..a6da4a6a4260 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -75,6 +75,7 @@ import android.net.RouteInfo; import android.net.UidRangeParcel; import android.net.UnderlyingNetworkInfo; import android.net.VpnManager; +import android.net.VpnProfileState; import android.net.VpnService; import android.net.VpnTransportInfo; import android.net.ipsec.ike.ChildSessionCallback; @@ -3438,6 +3439,45 @@ public class Vpn { } } + private @VpnProfileState.State int getStateFromLegacyState(int legacyState) { + switch (legacyState) { + case LegacyVpnInfo.STATE_CONNECTING: + return VpnProfileState.STATE_CONNECTING; + case LegacyVpnInfo.STATE_CONNECTED: + return VpnProfileState.STATE_CONNECTED; + case LegacyVpnInfo.STATE_DISCONNECTED: + return VpnProfileState.STATE_DISCONNECTED; + case LegacyVpnInfo.STATE_FAILED: + return VpnProfileState.STATE_FAILED; + default: + Log.wtf(TAG, "Unhandled state " + legacyState + + ", treat it as STATE_DISCONNECTED"); + return VpnProfileState.STATE_DISCONNECTED; + } + } + + private VpnProfileState makeVpnProfileState() { + // TODO: mSessionKey will be moved to Ikev2VpnRunner once aosp/2007077 is merged, so after + // merging aosp/2007077, here should check Ikev2VpnRunner is null or not. Session key will + // be null if Ikev2VpnRunner is null. + return new VpnProfileState(getStateFromLegacyState(mLegacyState), mSessionKey, mAlwaysOn, + mLockdown); + } + + /** + * Retrieve the VpnProfileState for the profile provisioned by the given package. + * + * @return the VpnProfileState with current information, or null if there was no profile + * provisioned by the given package. + */ + @Nullable + public synchronized VpnProfileState getProvisionedVpnProfileState( + @NonNull String packageName) { + requireNonNull(packageName, "No package name provided"); + enforceNotRestrictedUser(); + return isCurrentIkev2VpnLocked(packageName) ? makeVpnProfileState() : null; + } + /** * Proxy to allow testing * |