BroadcastQueue: DISPATCH_SENDING_BROADCAST_EVENT.
Consistently send this event from both legacy and modern stack, and refactor to hide the DISPATCH_SENDING_BROADCAST_EVENT message as an implementation detail inside AMS. Tests to verify that we always deliver expected "finished" events. Bug: 257038590 Test: atest FrameworksMockingServicesTests:BroadcastRecordTest Test: atest FrameworksMockingServicesTests:BroadcastQueueTest Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest Change-Id: Ib5c0b78ede454a11cac75cec06deebc6adbb8a40
This commit is contained in:
@@ -14723,6 +14723,15 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
mCurBroadcastStats.addBackgroundCheckViolation(action, targetPackage);
|
||||
}
|
||||
|
||||
final void notifyBroadcastFinishedLocked(@NonNull BroadcastRecord original) {
|
||||
final ApplicationInfo info = original.callerApp != null ? original.callerApp.info : null;
|
||||
final String callerPackage = info != null ? info.packageName : original.callerPackage;
|
||||
if (callerPackage != null) {
|
||||
mHandler.obtainMessage(ActivityManagerService.DISPATCH_SENDING_BROADCAST_EVENT,
|
||||
original.callingUid, 0, callerPackage).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
final Intent verifyBroadcastLocked(Intent intent) {
|
||||
// Refuse possible leaked file descriptors
|
||||
if (intent != null && intent.hasFileDescriptors() == true) {
|
||||
|
||||
@@ -1690,13 +1690,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
|
||||
System.identityHashCode(original));
|
||||
}
|
||||
|
||||
final ApplicationInfo info = original.callerApp != null ? original.callerApp.info : null;
|
||||
final String callerPackage = info != null ? info.packageName : original.callerPackage;
|
||||
if (callerPackage != null) {
|
||||
mService.mHandler.obtainMessage(ActivityManagerService.DISPATCH_SENDING_BROADCAST_EVENT,
|
||||
original.callingUid, 0, callerPackage).sendToTarget();
|
||||
}
|
||||
|
||||
mService.notifyBroadcastFinishedLocked(original);
|
||||
mHistory.addBroadcastToHistoryLocked(original);
|
||||
}
|
||||
|
||||
|
||||
@@ -1403,6 +1403,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
|
||||
|
||||
final boolean recordFinished = (r.terminalCount == r.receivers.size());
|
||||
if (recordFinished) {
|
||||
mService.notifyBroadcastFinishedLocked(r);
|
||||
mHistory.addBroadcastToHistoryLocked(r);
|
||||
|
||||
r.finishTime = SystemClock.uptimeMillis();
|
||||
|
||||
@@ -1639,4 +1639,22 @@ public class BroadcastQueueTest {
|
||||
waitForIdle();
|
||||
verify(mAms, never()).enqueueOomAdjTargetLocked(any());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that expected events are triggered when a broadcast is finished.
|
||||
*/
|
||||
@Test
|
||||
public void testNotifyFinished() throws Exception {
|
||||
final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED);
|
||||
|
||||
final Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
final BroadcastRecord record = makeBroadcastRecord(intent, callerApp,
|
||||
List.of(makeManifestReceiver(PACKAGE_GREEN, CLASS_GREEN)));
|
||||
enqueueBroadcast(record);
|
||||
|
||||
waitForIdle();
|
||||
verify(mAms).notifyBroadcastFinishedLocked(eq(record));
|
||||
verify(mAms).addBroadcastStatLocked(eq(Intent.ACTION_TIMEZONE_CHANGED), eq(PACKAGE_RED),
|
||||
eq(1), eq(0), anyLong());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user