Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1045)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java

Issue 2415573002: customtabs: Add paranoia to isCallerForegroundOrSelf() due to NPEs in the wild. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
index f2f39fb49b0eba90b2c5c08507bc2bd95bcd8cab..435a0b84c95df0fc6a63638915b75c61ad2702f9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java
@@ -662,16 +662,24 @@ public class CustomTabsConnection {
// processes. We use a workaround in this case.
boolean useWorkaround = true;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
- ActivityManager am =
- (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
- List<ActivityManager.RunningAppProcessInfo> running = am.getRunningAppProcesses();
- for (ActivityManager.RunningAppProcessInfo rpi : running) {
- boolean matchingUid = rpi.uid == uid;
- boolean isForeground = rpi.importance
- == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
- useWorkaround &= !matchingUid;
- if (matchingUid && isForeground) return true;
- }
+ do {
+ ActivityManager am =
+ (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
+ // Extra paranoia here and below, some L 5.0.x devices seem to throw NPE somewhere
+ // in this code.
+ // See https://crbug.com/654705.
+ if (am == null) break;
+ List<ActivityManager.RunningAppProcessInfo> running = am.getRunningAppProcesses();
+ if (running == null) break;
+ for (ActivityManager.RunningAppProcessInfo rpi : running) {
+ if (rpi == null) continue;
+ boolean matchingUid = rpi.uid == uid;
+ boolean isForeground = rpi.importance
+ == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
+ useWorkaround &= !matchingUid;
+ if (matchingUid && isForeground) return true;
+ }
+ } while (false);
}
return useWorkaround ? !isBackgroundProcess(Binder.getCallingPid()) : false;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698