diff options
| author | 2021-03-08 19:54:05 +0000 | |
|---|---|---|
| committer | 2021-03-08 19:54:05 +0000 | |
| commit | f349d18f1797b8c6a88cff32f49dc526a75d2caf (patch) | |
| tree | aeee1e12af31da96e9af5eeedd2a976eeb81e1b7 | |
| parent | 6387cdfb91cebd2cf469f83e81c1c87e441091f9 (diff) | |
| parent | af6196d5d4679bc638f1501769baa33d82b74d71 (diff) | |
Merge "Do not allow FGS starts from sync" into sc-dev
3 files changed, 37 insertions, 15 deletions
diff --git a/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java b/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java index 0dde546e85de..9bd57a1109de 100644 --- a/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java +++ b/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java @@ -17,6 +17,7 @@ package com.android.server; import android.annotation.Nullable; +import android.os.PowerWhitelistManager; import android.os.PowerWhitelistManager.ReasonCode; import android.os.PowerWhitelistManager.TempAllowListType; @@ -32,11 +33,22 @@ public interface DeviceIdleInternal { void exitIdle(String reason); + /** + * Same as {@link #addPowerSaveTempWhitelistApp(int, String, long, int, boolean, int, String)} + * with {@link PowerWhitelistManager#TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED}. + */ void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); /** + * Put a package in the temp-allowlist. + */ + void addPowerSaveTempWhitelistApp(int callingUid, String packageName, + long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync, + @ReasonCode int reasonCode, @Nullable String reason); + + /** * Called by ActivityManagerService to directly add UID to DeviceIdleController's temp * allowlist. * @param uid diff --git a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java index 84fb39b273c4..119dcb63770d 100644 --- a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java +++ b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java @@ -1942,22 +1942,29 @@ public class DeviceIdleController extends SystemService exitIdleInternal(reason); } - // duration in milliseconds @Override public void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason) { addPowerSaveTempAllowlistAppInternal(callingUid, packageName, durationMs, + TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, userId, sync, reasonCode, reason); } - // duration in milliseconds @Override - public void addPowerSaveTempWhitelistAppDirect(int uid, long duration, - @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, + public void addPowerSaveTempWhitelistApp(int callingUid, String packageName, + long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync, + @ReasonCode int reasonCode, @Nullable String reason) { + addPowerSaveTempAllowlistAppInternal(callingUid, packageName, durationMs, + tempAllowListType, userId, sync, reasonCode, reason); + } + + @Override + public void addPowerSaveTempWhitelistAppDirect(int uid, long durationMs, + @TempAllowListType int tempAllowListType, boolean sync, @ReasonCode int reasonCode, @Nullable String reason, int callingUid) { - addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration, type, sync, - reasonCode, reason); + addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, durationMs, + tempAllowListType, sync, reasonCode, reason); } // duration in milliseconds @@ -2699,7 +2706,8 @@ public class DeviceIdleController extends SystemService final long token = Binder.clearCallingIdentity(); try { addPowerSaveTempAllowlistAppInternal(callingUid, - packageName, duration, userId, true, reasonCode, reason); + packageName, duration, TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, + userId, true, reasonCode, reason); } finally { Binder.restoreCallingIdentity(token); } @@ -2731,8 +2739,8 @@ public class DeviceIdleController extends SystemService * app an exemption to access network and acquire wakelocks. */ void addPowerSaveTempAllowlistAppInternal(int callingUid, String packageName, - long duration, int userId, boolean sync, @ReasonCode int reasonCode, - @Nullable String reason) { + long durationMs, @TempAllowListType int tempAllowListType, int userId, boolean sync, + @ReasonCode int reasonCode, @Nullable String reason) { synchronized (this) { int callingAppId = UserHandle.getAppId(callingUid); if (callingAppId >= Process.FIRST_APPLICATION_UID) { @@ -2745,8 +2753,8 @@ public class DeviceIdleController extends SystemService } try { int uid = getContext().getPackageManager().getPackageUidAsUser(packageName, userId); - addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration, - TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, sync, reasonCode, reason); + addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, durationMs, + tempAllowListType, sync, reasonCode, reason); } catch (NameNotFoundException e) { } } @@ -2756,8 +2764,8 @@ public class DeviceIdleController extends SystemService * app an exemption to access network and acquire wakelocks. */ void addPowerSaveTempWhitelistAppDirectInternal(int callingUid, int uid, - long duration, @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, - @Nullable String reason) { + long duration, @TempAllowListType int tempAllowListType, boolean sync, + @ReasonCode int reasonCode, @Nullable String reason) { final long timeNow = SystemClock.elapsedRealtime(); boolean informWhitelistChanged = false; int appId = UserHandle.getAppId(uid); @@ -2782,8 +2790,8 @@ public class DeviceIdleController extends SystemService } catch (RemoteException e) { } postTempActiveTimeoutMessage(uid, duration); - updateTempWhitelistAppIdsLocked(uid, true, duration, type, reasonCode, - reason, callingUid); + updateTempWhitelistAppIdsLocked(uid, true, duration, tempAllowListType, + reasonCode, reason, callingUid); if (sync) { informWhitelistChanged = true; } else { diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java index ae0e001e8417..df870125e253 100644 --- a/services/core/java/com/android/server/content/SyncManager.java +++ b/services/core/java/com/android/server/content/SyncManager.java @@ -17,6 +17,7 @@ package com.android.server.content; import static android.os.PowerWhitelistManager.REASON_SYNC_MANAGER; +import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED; import static com.android.server.content.SyncLogger.logSafe; @@ -1672,6 +1673,7 @@ public class SyncManager { dic.addPowerSaveTempWhitelistApp(Process.SYSTEM_UID, syncOperation.owningPackage, mConstants.getKeyExemptionTempWhitelistDurationInSeconds() * 1000, + TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED, UserHandle.getUserId(syncOperation.owningUid), /* sync=*/ false, REASON_SYNC_MANAGER, "sync by top app"); } |