OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import android.app.ActivityManager; | 7 import android.app.ActivityManager; |
8 import android.app.Application; | 8 import android.app.Application; |
9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 * @return true when inside a Binder transaction and the caller is in the | 655 * @return true when inside a Binder transaction and the caller is in the |
656 * foreground or self. Don't use outside a Binder transaction. | 656 * foreground or self. Don't use outside a Binder transaction. |
657 */ | 657 */ |
658 private boolean isCallerForegroundOrSelf() { | 658 private boolean isCallerForegroundOrSelf() { |
659 int uid = Binder.getCallingUid(); | 659 int uid = Binder.getCallingUid(); |
660 if (uid == Process.myUid()) return true; | 660 if (uid == Process.myUid()) return true; |
661 // Starting with L MR1, AM.getRunningAppProcesses doesn't return all the | 661 // Starting with L MR1, AM.getRunningAppProcesses doesn't return all the |
662 // processes. We use a workaround in this case. | 662 // processes. We use a workaround in this case. |
663 boolean useWorkaround = true; | 663 boolean useWorkaround = true; |
664 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { | 664 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { |
665 ActivityManager am = | 665 do { |
666 (ActivityManager) mApplication.getSystemService(Context.ACTI
VITY_SERVICE); | 666 ActivityManager am = |
667 List<ActivityManager.RunningAppProcessInfo> running = am.getRunningA
ppProcesses(); | 667 (ActivityManager) mApplication.getSystemService(Context.
ACTIVITY_SERVICE); |
668 for (ActivityManager.RunningAppProcessInfo rpi : running) { | 668 // Extra paranoia here and below, some L 5.0.x devices seem to t
hrow NPE somewhere |
669 boolean matchingUid = rpi.uid == uid; | 669 // in this code. |
670 boolean isForeground = rpi.importance | 670 // See https://crbug.com/654705. |
671 == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FORE
GROUND; | 671 if (am == null) break; |
672 useWorkaround &= !matchingUid; | 672 List<ActivityManager.RunningAppProcessInfo> running = am.getRunn
ingAppProcesses(); |
673 if (matchingUid && isForeground) return true; | 673 if (running == null) break; |
674 } | 674 for (ActivityManager.RunningAppProcessInfo rpi : running) { |
| 675 if (rpi == null) continue; |
| 676 boolean matchingUid = rpi.uid == uid; |
| 677 boolean isForeground = rpi.importance |
| 678 == ActivityManager.RunningAppProcessInfo.IMPORTANCE_
FOREGROUND; |
| 679 useWorkaround &= !matchingUid; |
| 680 if (matchingUid && isForeground) return true; |
| 681 } |
| 682 } while (false); |
675 } | 683 } |
676 return useWorkaround ? !isBackgroundProcess(Binder.getCallingPid()) : fa
lse; | 684 return useWorkaround ? !isBackgroundProcess(Binder.getCallingPid()) : fa
lse; |
677 } | 685 } |
678 | 686 |
679 @VisibleForTesting | 687 @VisibleForTesting |
680 void cleanupAll() { | 688 void cleanupAll() { |
681 ThreadUtils.assertOnUiThread(); | 689 ThreadUtils.assertOnUiThread(); |
682 mClientManager.cleanupAll(); | 690 mClientManager.cleanupAll(); |
683 } | 691 } |
684 | 692 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 @VisibleForTesting | 781 @VisibleForTesting |
774 void resetThrottling(Context context, int uid) { | 782 void resetThrottling(Context context, int uid) { |
775 mClientManager.resetThrottling(uid); | 783 mClientManager.resetThrottling(uid); |
776 } | 784 } |
777 | 785 |
778 @VisibleForTesting | 786 @VisibleForTesting |
779 void ban(Context context, int uid) { | 787 void ban(Context context, int uid) { |
780 mClientManager.ban(uid); | 788 mClientManager.ban(uid); |
781 } | 789 } |
782 } | 790 } |
OLD | NEW |