Make sure to call the original reply-to receiver when...

replacing a queued broadcast.

- Also don't replace a broadcast for a different user.

Test: Manual test with the following test code:

Intent intent = new Intent(Intent.ACTION_PROVIDER_CHANGED)
        .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
AlarmManager alm = this.getSystemService(AlarmManager.class);
long time = SystemClock.elapsedRealtime() + 5 * 1000;
for (int i = 0; i < 5; i++) {
    alm.setExact(AlarmManager.ELAPSED_REALTIME, time,
            PendingIntent.getBroadcast(this, i, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}

Without this CL, after the alarm fires, AlarmManagerService.mBroadcastRefCount
is left > 0 and the wake lock is held forever.

With this CL, mBroadcastRefCount eventually gets back to 0.

Bug: 35779096
Change-Id: I4e21c94b08f25f9ca1242182670ff4a69f8bd9f2
3 files changed