Commit d34cd2c9 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[FCM] Store laziness information in a separate SharedPreferences

Lazy sunbscription information were stored in the default
SharedPreferences file.
However, the plan now is to store the queued FCM messages in
SharedPrefernces as well. Therefore, it makes sense to use their own
SharedPrefences file for that.

Bug: 882887
Change-Id: Id78642f5c849c1458db04fdae8b85ceaf328fff6
Reviewed-on: https://chromium-review.googlesource.com/c/1264206Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599233}
parent eaa5cc8d
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.components.gcm_driver.instance_id; package org.chromium.components.gcm_driver.instance_id;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
...@@ -26,6 +27,7 @@ import java.util.concurrent.ExecutionException; ...@@ -26,6 +27,7 @@ import java.util.concurrent.ExecutionException;
@JNINamespace("instance_id") @JNINamespace("instance_id")
public class InstanceIDBridge { public class InstanceIDBridge {
private static final String FCM_LAZY_SUBSCRIPTIONS = "fcm_lazy_subscriptions"; private static final String FCM_LAZY_SUBSCRIPTIONS = "fcm_lazy_subscriptions";
private static final String PREF_PACKAGE = "org.chromium.components.gcm_driver.instance_id";
private final String mSubtype; private final String mSubtype;
private long mNativeInstanceIDAndroid; private long mNativeInstanceIDAndroid;
/** /**
...@@ -47,7 +49,9 @@ public class InstanceIDBridge { ...@@ -47,7 +49,9 @@ public class InstanceIDBridge {
@VisibleForTesting @VisibleForTesting
public void storeLazinessInformation(final String authorizedEntity, boolean isLazy) { public void storeLazinessInformation(final String authorizedEntity, boolean isLazy) {
if (isLazy) { if (isLazy) {
SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); Context context = ContextUtils.getApplicationContext();
SharedPreferences sharedPrefs =
context.getSharedPreferences(PREF_PACKAGE, Context.MODE_PRIVATE);
Set<String> lazyIds = new HashSet<>( Set<String> lazyIds = new HashSet<>(
sharedPrefs.getStringSet(FCM_LAZY_SUBSCRIPTIONS, Collections.emptySet())); sharedPrefs.getStringSet(FCM_LAZY_SUBSCRIPTIONS, Collections.emptySet()));
lazyIds.add(buildSubscriptionUniqueId(mSubtype, authorizedEntity)); lazyIds.add(buildSubscriptionUniqueId(mSubtype, authorizedEntity));
...@@ -62,7 +66,9 @@ public class InstanceIDBridge { ...@@ -62,7 +66,9 @@ public class InstanceIDBridge {
* Returns whether the subscription with the |appId| and |senderId| is lazy. * Returns whether the subscription with the |appId| and |senderId| is lazy.
*/ */
public static boolean isSubscriptionLazy(final String appId, final String senderId) { public static boolean isSubscriptionLazy(final String appId, final String senderId) {
SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); Context context = ContextUtils.getApplicationContext();
SharedPreferences sharedPrefs =
context.getSharedPreferences(PREF_PACKAGE, Context.MODE_PRIVATE);
Set<String> lazyIds = new HashSet<>( Set<String> lazyIds = new HashSet<>(
sharedPrefs.getStringSet(FCM_LAZY_SUBSCRIPTIONS, Collections.emptySet())); sharedPrefs.getStringSet(FCM_LAZY_SUBSCRIPTIONS, Collections.emptySet()));
return lazyIds.contains(buildSubscriptionUniqueId(appId, senderId)); return lazyIds.contains(buildSubscriptionUniqueId(appId, senderId));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment