From d016285dd1a368f7eec532fb82c01dcee0c4bcf1 Mon Sep 17 00:00:00 2001 From: Michal Karpinski Date: Tue, 15 Jan 2019 16:05:25 +0000 Subject: [PATCH] Add a logcat message for aborted background activity starts Previously we just showed a toast and didn't log anything. This needs to change as we start getting more and more bug reports from early dogfooders, and more and more people will want to figure out what's going on. Bug: 110956953 Test: atest WmTests:ActivityStarterTests Test: adb logcat | grep "Blocking background activity start" Change-Id: I48483d33b28cbb18c633666b990c58144e54bde1 --- .../android/server/wm/ActivityStarter.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index ef3c8d5257fbb..916baa08fcbc9 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -749,7 +749,7 @@ class ActivityStarter { if (!abort) { abort |= shouldAbortBackgroundActivityStart(callingUid, callingPid, callingPackage, realCallingUid, callerApp, originatingPendingIntent, - allowBackgroundActivityStart); + allowBackgroundActivityStart, intent); } // Merge the two options bundles, while realCallerOptions takes precedence. @@ -898,7 +898,8 @@ class ActivityStarter { private boolean shouldAbortBackgroundActivityStart(int callingUid, int callingPid, final String callingPackage, int realCallingUid, WindowProcessController callerApp, - PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart) { + PendingIntentRecord originatingPendingIntent, boolean allowBackgroundActivityStart, + Intent intent) { if (mService.isBackgroundActivityStartsEnabled()) { return false; } @@ -911,19 +912,24 @@ class ActivityStarter { return false; } // don't abort if the callingUid is in the foreground or is a persistent system process - if (isUidForeground(callingUid) || isUidPersistentSystemProcess(callingUid)) { + final boolean isCallingUidForeground = isUidForeground(callingUid); + final boolean isCallingUidPersistentSystemProcess = isUidPersistentSystemProcess( + callingUid); + if (isCallingUidForeground || isCallingUidPersistentSystemProcess) { return false; } // take realCallingUid into consideration + final boolean isRealCallingUidForeground = isUidForeground(realCallingUid); + final boolean isRealCallingUidPersistentSystemProcess = isUidPersistentSystemProcess( + realCallingUid); if (realCallingUid != callingUid) { // don't abort if the realCallingUid is in the foreground and callingUid isn't - if (isUidForeground(realCallingUid)) { + if (isRealCallingUidForeground) { return false; } // if the realCallingUid is a persistent system process, abort if the IntentSender // wasn't whitelisted to start an activity - if (isUidPersistentSystemProcess(realCallingUid) && (originatingPendingIntent != null) - && allowBackgroundActivityStart) { + if (isRealCallingUidPersistentSystemProcess && allowBackgroundActivityStart) { return false; } } @@ -941,6 +947,18 @@ class ActivityStarter { return false; } // anything that has fallen through will currently be aborted + Slog.w(TAG, "Blocking background activity start [callingPackage: " + callingPackage + + "; callingUid: " + callingUid + + "; isCallingUidForeground: " + isCallingUidForeground + + "; isCallingUidPersistentSystemProcess: " + isCallingUidPersistentSystemProcess + + "; realCallingUid: " + realCallingUid + + "; isRealCallingUidForeground: " + isRealCallingUidForeground + + "; isRealCallingUidPersistentSystemProcess: " + + isRealCallingUidPersistentSystemProcess + + "; originatingPendingIntent: " + originatingPendingIntent + + "; isBgStartWhitelisted: " + allowBackgroundActivityStart + + "; intent: " + intent + + "]"); // TODO: remove this toast after feature development is done mService.mUiHandler.post(() -> { Toast.makeText(mService.mContext,