diff options
| author | 2022-08-29 03:25:28 +0000 | |
|---|---|---|
| committer | 2022-08-29 03:25:28 +0000 | |
| commit | e07cecf6363a70ce5b267acbbc9a82eb72510eb5 (patch) | |
| tree | 4c0b69261d71aca83e421a5a4abdb8c50dc1c459 | |
| parent | 5e5e10f1b41f579142c054d12ce1e97293fe08d8 (diff) | |
| parent | e3325d736a14d8aa1e89d987b0bdcf567ae50672 (diff) | |
Merge "Have a method to stop VPN and send event to VPN app" am: 4e08dae7d2 am: e3325d736a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2194337
Change-Id: I08276ff4885f12e9273bb4ef310ec32c26c53409
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | services/core/java/com/android/server/connectivity/Vpn.java | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index b4e91b586b40..481c5db559cf 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -1196,25 +1196,7 @@ public class Vpn { mContext.unbindService(mConnection); cleanupVpnStateLocked(); } else if (mVpnRunner != null) { - // Build intent first because the sessionKey will be reset after performing - // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in - // VpnRunner.exit() to prevent design being changed in the future. - // TODO(b/230548427): Remove SDK check once VPN related stuff are decoupled from - // ConnectivityServiceTest. - final int ownerUid = mOwnerUID; - Intent intent = null; - if (SdkLevel.isAtLeastT() && isVpnApp(mPackage)) { - intent = buildVpnManagerEventIntent( - VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER, - -1 /* errorClass */, -1 /* errorCode*/, mPackage, - getSessionKeyLocked(), makeVpnProfileStateLocked(), - null /* underlyingNetwork */, null /* nc */, null /* lp */); - } - // cleanupVpnStateLocked() is called from mVpnRunner.exit() - mVpnRunner.exit(); - if (intent != null && isVpnApp(mPackage)) { - notifyVpnManagerVpnStopped(mPackage, ownerUid, intent); - } + stopVpnRunnerAndNotifyAppLocked(mPackage); } try { @@ -4068,6 +4050,29 @@ public class Vpn { } } + @GuardedBy("this") + private void stopVpnRunnerAndNotifyAppLocked(@NonNull String packageName) { + // Build intent first because the sessionKey will be reset after performing + // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in + // VpnRunner.exit() to prevent design being changed in the future. + // TODO(b/230548427): Remove SDK check once VPN related stuff are decoupled from + // ConnectivityServiceTest. + final int ownerUid = mOwnerUID; + Intent intent = null; + if (SdkLevel.isAtLeastT() && isVpnApp(packageName)) { + intent = buildVpnManagerEventIntent( + VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER, + -1 /* errorClass */, -1 /* errorCode*/, packageName, + getSessionKeyLocked(), makeVpnProfileStateLocked(), + null /* underlyingNetwork */, null /* nc */, null /* lp */); + } + // cleanupVpnStateLocked() is called from mVpnRunner.exit() + mVpnRunner.exit(); + if (intent != null && isVpnApp(packageName)) { + notifyVpnManagerVpnStopped(packageName, ownerUid, intent); + } + } + /** * Stops an already running VPN Profile for the given package. * @@ -4084,18 +4089,7 @@ public class Vpn { // To stop the VPN profile, the caller must be the current prepared package and must be // running an Ikev2VpnProfile. if (isCurrentIkev2VpnLocked(packageName)) { - // Build intent first because the sessionKey will be reset after performing - // VpnRunner.exit(). Also, cache mOwnerUID even if ownerUID will not be changed in - // VpnRunner.exit() to prevent design being changed in the future. - final int ownerUid = mOwnerUID; - final Intent intent = buildVpnManagerEventIntent( - VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER, - -1 /* errorClass */, -1 /* errorCode*/, packageName, - getSessionKeyLocked(), makeVpnProfileStateLocked(), - null /* underlyingNetwork */, null /* nc */, null /* lp */); - - mVpnRunner.exit(); - notifyVpnManagerVpnStopped(packageName, ownerUid, intent); + stopVpnRunnerAndNotifyAppLocked(packageName); } } |