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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWeb.java

Issue 2071713002: Add a PhysicalWebIgnoreOtherClients feature (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Store setting in onChromeStart Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.physicalweb; 5 package org.chromium.chrome.browser.physicalweb;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
9 import android.os.AsyncTask; 9 import android.os.AsyncTask;
10 import android.os.Build; 10 import android.os.Build;
11 11
12 import org.chromium.base.ContextUtils; 12 import org.chromium.base.ContextUtils;
13 import org.chromium.chrome.browser.ChromeApplication; 13 import org.chromium.chrome.browser.ChromeApplication;
14 import org.chromium.chrome.browser.ChromeFeatureList; 14 import org.chromium.chrome.browser.ChromeFeatureList;
15 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ; 15 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ;
16 16
17 /** 17 /**
18 * This class provides the basic interface to the Physical Web feature. 18 * This class provides the basic interface to the Physical Web feature.
19 */ 19 */
20 public class PhysicalWeb { 20 public class PhysicalWeb {
21 public static final int OPTIN_NOTIFY_MAX_TRIES = 1; 21 public static final int OPTIN_NOTIFY_MAX_TRIES = 1;
22 private static final String PREF_PHYSICAL_WEB_NOTIFY_COUNT = "physical_web_n otify_count"; 22 private static final String PREF_PHYSICAL_WEB_NOTIFY_COUNT = "physical_web_n otify_count";
23 private static final String PREF_IGNORE_OTHER_CLIENTS = "physical_web_ignore _other_clients";
23 private static final String FEATURE_NAME = "PhysicalWeb"; 24 private static final String FEATURE_NAME = "PhysicalWeb";
25 private static final String IGNORE_OTHER_CLIENTS_FEATURE_NAME = "PhysicalWeb IgnoreOtherClients";
24 private static final int MIN_ANDROID_VERSION = 18; 26 private static final int MIN_ANDROID_VERSION = 18;
25 27
26 /** 28 /**
27 * Evaluate whether the environment is one in which the Physical Web should 29 * Evaluate whether the environment is one in which the Physical Web should
28 * be enabled. 30 * be enabled.
29 * @return true if the PhysicalWeb should be enabled 31 * @return true if the PhysicalWeb should be enabled
30 */ 32 */
31 public static boolean featureIsEnabled() { 33 public static boolean featureIsEnabled() {
32 return ChromeFeatureList.isEnabled(FEATURE_NAME) 34 return ChromeFeatureList.isEnabled(FEATURE_NAME)
33 && Build.VERSION.SDK_INT >= MIN_ANDROID_VERSION; 35 && Build.VERSION.SDK_INT >= MIN_ANDROID_VERSION;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 * @param application An instance of {@link ChromeApplication}, used to get the 73 * @param application An instance of {@link ChromeApplication}, used to get the
72 * appropriate PhysicalWebBleClient implementation. 74 * appropriate PhysicalWebBleClient implementation.
73 */ 75 */
74 public static void stopPhysicalWeb(ChromeApplication application) { 76 public static void stopPhysicalWeb(ChromeApplication application) {
75 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application); 77 PhysicalWebBleClient physicalWebBleClient = PhysicalWebBleClient.getInst ance(application);
76 physicalWebBleClient.backgroundUnsubscribe(); 78 physicalWebBleClient.backgroundUnsubscribe();
77 clearUrlsAsync(application); 79 clearUrlsAsync(application);
78 } 80 }
79 81
80 /** 82 /**
83 * Returns true if we should fire notifications regardless of the existence of other Physical
84 * Web clients.
85 * This method is for use when the native library is not available.
86 */
87 public static boolean shouldIgnoreOtherClients() {
88 return ContextUtils.getAppSharedPreferences().getBoolean(PREF_IGNORE_OTH ER_CLIENTS, false);
89 }
90
91 /**
81 * Increments a value tracking how many times we've shown the Physical Web 92 * Increments a value tracking how many times we've shown the Physical Web
82 * opt-in notification. 93 * opt-in notification.
83 * 94 *
84 * @param context An instance of android.content.Context 95 * @param context An instance of android.content.Context
85 */ 96 */
86 public static void recordOptInNotification(Context context) { 97 public static void recordOptInNotification(Context context) {
87 SharedPreferences sharedPreferences = 98 SharedPreferences sharedPreferences =
88 ContextUtils.getAppSharedPreferences(); 99 ContextUtils.getAppSharedPreferences();
89 int value = sharedPreferences.getInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, 0); 100 int value = sharedPreferences.getInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, 0);
90 sharedPreferences.edit().putInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, value + 1).apply(); 101 sharedPreferences.edit().putInt(PREF_PHYSICAL_WEB_NOTIFY_COUNT, value + 1).apply();
(...skipping 14 matching lines...) Expand all
105 116
106 /** 117 /**
107 * Perform various Physical Web operations that should happen on startup. 118 * Perform various Physical Web operations that should happen on startup.
108 * @param application An instance of {@link ChromeApplication}. 119 * @param application An instance of {@link ChromeApplication}.
109 */ 120 */
110 public static void onChromeStart(ChromeApplication application) { 121 public static void onChromeStart(ChromeApplication application) {
111 // The PhysicalWebUma calls in this method should be called only when th e native library is 122 // The PhysicalWebUma calls in this method should be called only when th e native library is
112 // loaded. This is always the case on chrome startup. 123 // loaded. This is always the case on chrome startup.
113 if (featureIsEnabled() 124 if (featureIsEnabled()
114 && (isPhysicalWebPreferenceEnabled(application) || isOnboarding( application))) { 125 && (isPhysicalWebPreferenceEnabled(application) || isOnboarding( application))) {
126 boolean ignoreOtherClients =
127 ChromeFeatureList.isEnabled(IGNORE_OTHER_CLIENTS_FEATURE_NAM E);
128 ContextUtils.getAppSharedPreferences().edit()
129 .putBoolean(PREF_IGNORE_OTHER_CLIENTS, ignoreOtherClients)
130 .apply();
115 startPhysicalWeb(application); 131 startPhysicalWeb(application);
116 PhysicalWebUma.uploadDeferredMetrics(application); 132 PhysicalWebUma.uploadDeferredMetrics(application);
117 } else { 133 } else {
118 stopPhysicalWeb(application); 134 stopPhysicalWeb(application);
119 } 135 }
120 } 136 }
121 137
122 private static void clearUrlsAsync(final Context context) { 138 private static void clearUrlsAsync(final Context context) {
123 Runnable task = new Runnable() { 139 Runnable task = new Runnable() {
124 @Override 140 @Override
125 public void run() { 141 public void run() {
126 UrlManager.getInstance(context).clearUrls(); 142 UrlManager.getInstance(context).clearUrls();
127 } 143 }
128 }; 144 };
129 AsyncTask.THREAD_POOL_EXECUTOR.execute(task); 145 AsyncTask.THREAD_POOL_EXECUTOR.execute(task);
130 } 146 }
131 } 147 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698