Merge "Don't allow core uids to be unfrozen due to deferrable broadcasts." into udc-qpr-dev am: 519a605745 am: 7b5dd4cc16

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

Change-Id: I048cd83f2e098440c7da36b77d8246abd368c617
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sudheer Shanka
2023-07-10 22:42:38 +00:00
committed by Automerger Merge Worker
2 changed files with 25 additions and 3 deletions

View File

@@ -1144,9 +1144,6 @@ class BroadcastProcessQueue {
} else if (mProcessPersistent) {
mRunnableAt = runnableAt + constants.DELAY_PERSISTENT_PROC_MILLIS;
mRunnableAtReason = REASON_PERSISTENT;
} else if (UserHandle.isCore(uid)) {
mRunnableAt = runnableAt;
mRunnableAtReason = REASON_CORE_UID;
} else if (mCountOrdered > 0) {
mRunnableAt = runnableAt;
mRunnableAtReason = REASON_CONTAINS_ORDERED;
@@ -1193,6 +1190,9 @@ class BroadcastProcessQueue {
// is already cached, they'll be deferred on the line above
mRunnableAt = runnableAt;
mRunnableAtReason = REASON_CONTAINS_RESULT_TO;
} else if (UserHandle.isCore(uid)) {
mRunnableAt = runnableAt;
mRunnableAtReason = REASON_CORE_UID;
} else {
mRunnableAt = runnableAt + constants.DELAY_NORMAL_MILLIS;
mRunnableAtReason = REASON_NORMAL;

View File

@@ -620,6 +620,28 @@ public final class BroadcastQueueModernImplTest {
assertEquals(BroadcastProcessQueue.REASON_CORE_UID, queue.getRunnableAtReason());
}
@Test
public void testRunnableAt_freezableCoreUid() {
final BroadcastProcessQueue queue = new BroadcastProcessQueue(mConstants,
"com.android.bluetooth", Process.BLUETOOTH_UID);
// Mark the process as freezable
queue.setProcessAndUidState(mProcess, false, true);
final Intent timeTick = new Intent(Intent.ACTION_TIME_TICK);
final BroadcastOptions options = BroadcastOptions.makeWithDeferUntilActive(true);
final BroadcastRecord timeTickRecord = makeBroadcastRecord(timeTick, options,
List.of(makeMockRegisteredReceiver()), false);
enqueueOrReplaceBroadcast(queue, timeTickRecord, 0);
assertEquals(Long.MAX_VALUE, queue.getRunnableAt());
assertEquals(BroadcastProcessQueue.REASON_CACHED_INFINITE_DEFER,
queue.getRunnableAtReason());
queue.setProcessAndUidState(mProcess, false, false);
assertThat(queue.getRunnableAt()).isEqualTo(timeTickRecord.enqueueTime);
assertEquals(BroadcastProcessQueue.REASON_CORE_UID, queue.getRunnableAtReason());
}
/**
* Verify that a cached process that would normally be delayed becomes
* immediately runnable when the given broadcast is enqueued.