From 5a5daafbcab55d051b0e241eb8adfacde2155e36 Mon Sep 17 00:00:00 2001 From: Hui Yu Date: Tue, 25 Feb 2020 12:03:26 -0800 Subject: [PATCH] Pass START_ACTIVITIES_FROM_BACKGROUND permission to instrumentation test. So the instrumentation can have the same permssion as app and it can skip the FGS background start while-in-use restriction. Also reuse the ProcessRecord.mAllowBackgroundActivityStartsTokens flag. Bug: 136219221 Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java Change-Id: I7d8708945ffe79b83825f8edb688078706c46770 --- .../java/com/android/server/am/ActiveServices.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 211da0a3e9dc3..f408fe749eb41 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -4869,6 +4869,19 @@ public final class ActiveServices { return true; } + if (r.app != null) { + ActiveInstrumentation instr = r.app.getActiveInstrumentation(); + if (instr != null && instr.mHasBackgroundActivityStartsPermission) { + return true; + } + } + + final boolean hasAllowBackgroundActivityStartsToken = r.app != null + ? !r.app.mAllowBackgroundActivityStartsTokens.isEmpty() : false; + if (hasAllowBackgroundActivityStartsToken) { + return true; + } + if (mAm.checkPermission(START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid) == PERMISSION_GRANTED) { return true;