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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListener.java

Issue 2701453002: android: Tell GSA whether Chrome can listen to account change broadcasts. (Closed)
Patch Set: . Created 3 years, 10 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 | chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java » ('j') | 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/gsa/GSAAccountChangeListener.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListener.java b/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListener.java
index a9fc2598699294baca4ef2313b02d2d142136208..12bc7c11df96c7988d4bbb083b2dcad0b253d896 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListener.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAAccountChangeListener.java
@@ -57,6 +57,17 @@ public class GSAAccountChangeListener {
return sInstance;
}
+ /**
+ * Returns whether the permission {@link ACCOUNT_UPDATE_BROADCAST_PERMISSION} is granted by the
+ * system.
+ */
+ static boolean holdsAccountUpdatePermission() {
+ Context context = ContextUtils.getApplicationContext();
+ int result = ApiCompatibilityUtils.checkPermission(
+ context, ACCOUNT_UPDATE_BROADCAST_PERMISSION, Process.myPid(), Process.myUid());
+ return result == PackageManager.PERMISSION_GRANTED;
+ }
+
private GSAAccountChangeListener(Context context) {
Context applicationContext = context.getApplicationContext();
BroadcastReceiver accountChangeReceiver = new BroadcastReceiver() {
@@ -123,12 +134,12 @@ public class GSAAccountChangeListener {
// is not the same one as GSA's, then the broadcasts will never arrive.
// Query the package manager to know whether the permission was granted, and
// only switch to the broadcast mechanism if that's the case.
- if (ApiCompatibilityUtils.checkPermission(context,
- ACCOUNT_UPDATE_BROADCAST_PERMISSION, Process.myPid(),
- Process.myUid())
- == PackageManager.PERMISSION_GRANTED) {
- notifyGsaBroadcastsAccountChanges();
- }
+ //
+ // Note that this is technically not required, since Chrome tells GSA whether
+ // it holds the permission when connecting to it in GSAServiceClient, but this
+ // extra bit of paranoia protects from old versions of GSA that don't check
+ // what Chrome sends.
+ if (holdsAccountUpdatePermission()) notifyGsaBroadcastsAccountChanges();
}
// If GSA doesn't support the broadcast, we connect several times to the service per
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/gsa/GSAServiceClient.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698