diff options
| author | 2021-03-05 21:41:24 +0000 | |
|---|---|---|
| committer | 2021-03-05 21:41:24 +0000 | |
| commit | 3e651250c7a80f73e8aea3818fe6719d6f979b91 (patch) | |
| tree | 0ef04ff1cec50ab3d7c6119ab6d6637b2dd5cfb1 | |
| parent | 18a94794d616d2aa570b5bd28fc93e2e81b81696 (diff) | |
| parent | a7f8eaa1718e5493999f366d78168c8586e88c80 (diff) | |
Merge "callingUid needs to be passed from AMS to DeviceIdleController." into sc-dev
5 files changed, 31 insertions, 29 deletions
diff --git a/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java b/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java index 5e5717d11432..0dde546e85de 100644 --- a/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java +++ b/apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java @@ -32,12 +32,8 @@ public interface DeviceIdleInternal { void exitIdle(String reason); - // duration in milliseconds - void addPowerSaveTempWhitelistApp(int callingUid, String packageName, - long duration, int userId, boolean sync, String reason); - void addPowerSaveTempWhitelistApp(int callingUid, String packageName, - long duration, int userId, boolean sync, @ReasonCode int reasonCode, + long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); /** @@ -49,10 +45,11 @@ public interface DeviceIdleInternal { * @param sync * @param reasonCode one of {@link ReasonCode} * @param reason + * @param callingUid UID of app who added this temp-allowlist. */ void addPowerSaveTempWhitelistAppDirect(int uid, long duration, @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, - @Nullable String reason); + @Nullable String reason, int callingUid); // duration in milliseconds long getNotificationAllowlistDuration(); diff --git a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java index ac28e828eb2e..84fb39b273c4 100644 --- a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java +++ b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java @@ -1943,19 +1943,11 @@ public class DeviceIdleController extends SystemService } // duration in milliseconds - @Deprecated @Override public void addPowerSaveTempWhitelistApp(int callingUid, String packageName, - long duration, int userId, boolean sync, @Nullable String reason) { - addPowerSaveTempAllowlistAppInternal(callingUid, packageName, duration, - userId, sync, REASON_UNKNOWN, reason); - } - - @Override - public void addPowerSaveTempWhitelistApp(int callingUid, String packageName, - long duration, int userId, boolean sync, @ReasonCode int reasonCode, + long durationMs, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason) { - addPowerSaveTempAllowlistAppInternal(callingUid, packageName, duration, + addPowerSaveTempAllowlistAppInternal(callingUid, packageName, durationMs, userId, sync, reasonCode, reason); } @@ -1963,8 +1955,8 @@ public class DeviceIdleController extends SystemService @Override public void addPowerSaveTempWhitelistAppDirect(int uid, long duration, @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, - @Nullable String reason) { - addPowerSaveTempWhitelistAppDirectInternal(0, uid, duration, type, sync, + @Nullable String reason, int callingUid) { + addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration, type, sync, reasonCode, reason); } @@ -2741,6 +2733,16 @@ public class DeviceIdleController extends SystemService void addPowerSaveTempAllowlistAppInternal(int callingUid, String packageName, long duration, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason) { + synchronized (this) { + int callingAppId = UserHandle.getAppId(callingUid); + if (callingAppId >= Process.FIRST_APPLICATION_UID) { + if (!mPowerSaveWhitelistSystemAppIds.get(callingAppId)) { + throw new SecurityException( + "Calling app " + UserHandle.formatUid(callingUid) + + " is not on whitelist"); + } + } + } try { int uid = getContext().getPackageManager().getPackageUidAsUser(packageName, userId); addPowerSaveTempWhitelistAppDirectInternal(callingUid, uid, duration, @@ -2760,13 +2762,6 @@ public class DeviceIdleController extends SystemService boolean informWhitelistChanged = false; int appId = UserHandle.getAppId(uid); synchronized (this) { - int callingAppId = UserHandle.getAppId(callingUid); - if (callingAppId >= Process.FIRST_APPLICATION_UID) { - if (!mPowerSaveWhitelistSystemAppIds.get(callingAppId)) { - throw new SecurityException("Calling app " + UserHandle.formatUid(callingUid) - + " is not on whitelist"); - } - } duration = Math.min(duration, mConstants.MAX_TEMP_APP_ALLOWLIST_DURATION_MS); Pair<MutableLong, String> entry = mTempWhitelistAppIdEndTimes.get(appId); final boolean newEntry = entry == null; diff --git a/core/proto/android/server/activitymanagerservice.proto b/core/proto/android/server/activitymanagerservice.proto index ec41a47a8798..74a37cadc54c 100644 --- a/core/proto/android/server/activitymanagerservice.proto +++ b/core/proto/android/server/activitymanagerservice.proto @@ -628,6 +628,7 @@ message ActivityManagerServiceDumpProcessesProto { optional string tag = 3; optional int32 type = 4; optional int32 reason_code = 5; + optional int32 calling_uid = 6; } repeated PendingTempWhitelist pending_temp_whitelist = 26; diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index f409d713280a..3a3f4aca168a 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -50,7 +50,6 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.IServiceManager.DUMP_FLAG_PROTO; import static android.os.PowerWhitelistManager.REASON_SYSTEM_ALLOW_LISTED; -import static android.os.PowerWhitelistManager.REASON_UNKNOWN; import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import static android.os.Process.BLUETOOTH_UID; import static android.os.Process.FIRST_APPLICATION_UID; @@ -1178,14 +1177,16 @@ public class ActivityManagerService extends IActivityManager.Stub final String tag; final int type; final @ReasonCode int reasonCode; + final int callingUid; PendingTempAllowlist(int targetUid, long duration, @ReasonCode int reasonCode, String tag, - int type) { + int type, int callingUid) { this.targetUid = targetUid; this.duration = duration; this.tag = tag; this.type = type; this.reasonCode = reasonCode; + this.callingUid = callingUid; } void dumpDebug(ProtoOutputStream proto, long fieldId) { @@ -1198,6 +1199,8 @@ public class ActivityManagerService extends IActivityManager.Stub proto.write(ActivityManagerServiceDumpProcessesProto.PendingTempWhitelist.TYPE, type); proto.write(ActivityManagerServiceDumpProcessesProto.PendingTempWhitelist.REASON_CODE, reasonCode); + proto.write(ActivityManagerServiceDumpProcessesProto.PendingTempWhitelist.CALLING_UID, + callingUid); proto.end(token); } } @@ -9231,6 +9234,8 @@ public class ActivityManagerService extends IActivityManager.Stub pw.print(ptw.type); pw.print(" "); pw.print(ptw.reasonCode); + pw.print(" "); + pw.print(ptw.callingUid); } } } @@ -14510,7 +14515,8 @@ public class ActivityManagerService extends IActivityManager.Stub String reason, int type, int callingUid) { synchronized (mProcLock) { mPendingTempAllowlist.put(targetUid, - new PendingTempAllowlist(targetUid, duration, reasonCode, reason, type)); + new PendingTempAllowlist(targetUid, duration, reasonCode, reason, type, + callingUid)); setUidTempAllowlistStateLSP(targetUid, true); mUiHandler.obtainMessage(PUSH_TEMP_ALLOWLIST_UI_MSG).sendToTarget(); @@ -14541,7 +14547,8 @@ public class ActivityManagerService extends IActivityManager.Stub for (int i = 0; i < N; i++) { PendingTempAllowlist ptw = list[i]; mLocalDeviceIdleController.addPowerSaveTempWhitelistAppDirect(ptw.targetUid, - ptw.duration, ptw.type, true, ptw.reasonCode, ptw.tag); + ptw.duration, ptw.type, true, ptw.reasonCode, ptw.tag, + ptw.callingUid); } } diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java index 06cacc70a9b8..81c4c8605fb4 100644 --- a/services/core/java/com/android/server/am/BroadcastQueue.java +++ b/services/core/java/com/android/server/am/BroadcastQueue.java @@ -930,6 +930,8 @@ public final class BroadcastQueue { } else if (r.intent.getData() != null) { b.append(r.intent.getData()); } + b.append(",reason:"); + b.append(reason); if (DEBUG_BROADCAST) { Slog.v(TAG, "Broadcast temp allowlist uid=" + uid + " duration=" + duration + " type=" + type + " : " + b.toString()); |