Merge "Add VPN app into power saver whitelist for a while to start its service" am: df656e6141 am: 1457cc5d4d am: 24b65ea22a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2114435

Change-Id: I21f629431b5c931ce91ebea67923f2d5863f499c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Benedict Wong
2022-06-03 06:40:38 +00:00
committed by Automerger Merge Worker
2 changed files with 18 additions and 0 deletions

View File

@@ -100,6 +100,12 @@ public class VpnManager {
/**
* Action sent in {@link android.content.Intent}s to VpnManager clients when an event occurred.
*
* <p>If the provisioning application declares a service handling this intent action, but is not
* already running, it will be started. Upon starting, the application is granted a short grace
* period to run in the background even while the device is idle to handle any potential
* failures. Applications requiring long-running actions triggered by one of these events should
* declare a foreground service to prevent being killed once the grace period expires.
*
* This action will have a category of either {@link #CATEGORY_EVENT_IKE_ERROR},
* {@link #CATEGORY_EVENT_NETWORK_ERROR}, or {@link #CATEGORY_EVENT_DEACTIVATED_BY_USER},
* that the app can use to filter events it's interested in reacting to.

View File

@@ -192,6 +192,10 @@ public class Vpn {
// the device idle allowlist during service launch and VPN bootstrap.
private static final long VPN_LAUNCH_IDLE_ALLOWLIST_DURATION_MS = 60 * 1000;
// Length of time (in milliseconds) that an app registered for VpnManager events is placed on
// the device idle allowlist each time the a VpnManager event is fired.
private static final long VPN_MANAGER_EVENT_ALLOWLIST_DURATION_MS = 30 * 1000;
private static final String LOCKDOWN_ALLOWLIST_SETTING_NAME =
Settings.Secure.ALWAYS_ON_VPN_LOCKDOWN_WHITELIST;
/**
@@ -720,6 +724,14 @@ public class Vpn {
intent.putExtra(VpnManager.EXTRA_ERROR_CLASS, errorClass);
intent.putExtra(VpnManager.EXTRA_ERROR_CODE, errorCode);
}
// Allow VpnManager app to temporarily run background services to handle this error.
// If an app requires anything beyond this grace period, they MUST either declare
// themselves as a foreground service, or schedule a job/workitem.
DeviceIdleInternal idleController = mDeps.getDeviceIdleInternal();
idleController.addPowerSaveTempWhitelistApp(Process.myUid(), packageName,
VPN_MANAGER_EVENT_ALLOWLIST_DURATION_MS, mUserId, false, REASON_VPN,
"VpnManager event");
try {
return mUserIdContext.startService(intent) != null;
} catch (RuntimeException e) {