summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-01-20 03:22:58 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-01-20 03:22:58 +0000
commit121f5679a863ccb301a05380e0061454fed3e123 (patch)
tree10dce1027eebb2b2c751e33a6598608b53f45f94
parentbd22adfb6c8bac804a9271fc705fe56bbae16ccf (diff)
parent2018e68d0b68ee62697d8d681a183405a94d71ab (diff)
Merge "Only throw IllegalStateException when the service is BG-FGS-launch restricted."
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 88bb1a012a12..5cc32743af34 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -1692,7 +1692,7 @@ public final class ActiveServices {
}
try {
- String ignoreForeground = null;
+ boolean ignoreForeground = false;
final int mode = mAm.getAppOpsManager().checkOpNoThrow(
AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName);
switch (mode) {
@@ -1702,9 +1702,9 @@ public final class ActiveServices {
break;
case AppOpsManager.MODE_IGNORED:
// Whoops, silently ignore this.
- ignoreForeground = "Service.startForeground() not allowed due to app op: "
- + "service " + r.shortInstanceName;
- Slog.w(TAG, ignoreForeground);
+ Slog.w(TAG, "Service.startForeground() not allowed due to app op: service "
+ + r.shortInstanceName);
+ ignoreForeground = true;
break;
default:
throw new SecurityException("Foreground not allowed as per app op");
@@ -1712,18 +1712,19 @@ public final class ActiveServices {
// Apps that are TOP or effectively similar may call startForeground() on
// their services even if they are restricted from doing that while in bg.
- if (ignoreForeground == null
+ if (!ignoreForeground
&& !appIsTopLocked(r.appInfo.uid)
&& appRestrictedAnyInBackground(r.appInfo.uid, r.packageName)) {
- ignoreForeground = "Service.startForeground() not allowed due to bg restriction"
- + ":service " + r.shortInstanceName;
- Slog.w(TAG, ignoreForeground);
+ Slog.w(TAG,
+ "Service.startForeground() not allowed due to bg restriction: service "
+ + r.shortInstanceName);
// Back off of any foreground expectations around this service, since we've
// just turned down its fg request.
updateServiceForegroundLocked(r.app, false);
+ ignoreForeground = true;
}
- if (ignoreForeground == null) {
+ if (!ignoreForeground) {
if (isFgsBgStart(r.mAllowStartForeground)) {
if (!r.mLoggedInfoAllowStartForeground) {
Slog.wtf(TAG, "Background started FGS "
@@ -1732,12 +1733,17 @@ public final class ActiveServices {
}
if (r.mAllowStartForeground == FGS_FEATURE_DENIED
&& isBgFgsRestrictionEnabled(r)) {
- ignoreForeground = "Service.startForeground() not allowed due to "
+ final String msg = "Service.startForeground() not allowed due to "
+ "mAllowStartForeground false: service "
+ r.shortInstanceName;
- Slog.w(TAG, ignoreForeground);
+ Slog.w(TAG, msg);
showFgsBgRestrictedNotificationLocked(r);
updateServiceForegroundLocked(r.app, true);
+ ignoreForeground = true;
+ if (CompatChanges.isChangeEnabled(FGS_START_EXCEPTION_CHANGE_ID,
+ r.appInfo.uid)) {
+ throw new IllegalStateException(msg);
+ }
}
}
}
@@ -1746,7 +1752,7 @@ public final class ActiveServices {
// services, so now that we've enforced the startForegroundService() contract
// we only do the machinery of making the service foreground when the app
// is not restricted.
- if (ignoreForeground == null) {
+ if (!ignoreForeground) {
if (r.foregroundId != id) {
cancelForegroundNotificationLocked(r);
r.foregroundId = id;
@@ -1808,10 +1814,6 @@ public final class ActiveServices {
if (DEBUG_FOREGROUND_SERVICE) {
Slog.d(TAG, "Suppressing startForeground() for FAS " + r);
}
- if (CompatChanges.isChangeEnabled(FGS_START_EXCEPTION_CHANGE_ID, r.appInfo.uid)
- && isBgFgsRestrictionEnabled(r)) {
- throw new IllegalStateException(ignoreForeground);
- }
}
} finally {
if (stopProcStatsOp) {