From cce24f573ba927b3e7f5b24f19b1d3ab06e73e0d Mon Sep 17 00:00:00 2001 From: Hui Yu Date: Tue, 20 Jul 2021 09:29:21 -0700 Subject: [PATCH] FGS PendingIntent also use BroadcastOptions' temp allowlist duration. For FGS PendingIntent, if the BroadcastOptions parameter passed in PendingIntentRecord.send() call has a non-zero temp allowlist duration, treat this duration the same as the FGS PendingIntent's temp allowlist duration. Previously only setExact() alarm's "broadcasts" are exempt from BG-FGS-start restriction using BroadcastOptions. This CL exempts setExact() alarm's "FGS PendingIntent" from BG-FGS-start restriction. BYPASS_INCLUSIVE_LANGUAGE_REASON=Pre-existing API Bug: 193011829 Test: b/193011829 POC app, with this fix, ForegroundServiceStartNotAllowedException is not seen. Change-Id: Ifb095a8bcc458ab27c9259ca4af4d759835f2e1c --- .../com/android/server/am/PendingIntentRecord.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java index f7c777e9cd6cd..dc924c11f867d 100644 --- a/services/core/java/com/android/server/am/PendingIntentRecord.java +++ b/services/core/java/com/android/server/am/PendingIntentRecord.java @@ -24,6 +24,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NA import android.annotation.Nullable; import android.app.ActivityManager; import android.app.ActivityOptions; +import android.app.BroadcastOptions; import android.app.PendingIntent; import android.content.IIntentReceiver; import android.content.IIntentSender; @@ -408,6 +409,18 @@ public final class PendingIntentRecord extends IIntentSender.Stub { } controller.mAmInternal.tempAllowlistForPendingIntent(callingPid, callingUid, uid, duration.duration, duration.type, duration.reasonCode, tag.toString()); + } else if (key.type == ActivityManager.INTENT_SENDER_FOREGROUND_SERVICE + && options != null) { + // If this is a getForegroundService() type pending intent, use its BroadcastOptions + // temp allowlist duration as its pending intent temp allowlist duration. + BroadcastOptions brOptions = new BroadcastOptions(options); + if (brOptions.getTemporaryAppAllowlistDuration() > 0) { + controller.mAmInternal.tempAllowlistForPendingIntent(callingPid, callingUid, + uid, brOptions.getTemporaryAppAllowlistDuration(), + brOptions.getTemporaryAppAllowlistType(), + brOptions.getTemporaryAppAllowlistReasonCode(), + brOptions.getTemporaryAppAllowlistReason()); + } } boolean sendFinish = finishedReceiver != null;