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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java

Issue 1535883002: Request location perm. on enabling Physical Web (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't request permission if already granted Created 5 years 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/preferences/privacy/PhysicalWebPreferenceFragment.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java
index 5a802b5b48b7a7ac859a153962e0e3c94a999b06..5eedd4d682ef9a668d316feccc3fd951f03dd290 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PhysicalWebPreferenceFragment.java
@@ -4,11 +4,15 @@
package org.chromium.chrome.browser.preferences.privacy;
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
+import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
@@ -16,8 +20,9 @@ import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
* Fragment to manage the Physical Web preference and to explain to the user what it does.
*/
public class PhysicalWebPreferenceFragment extends PreferenceFragment {
-
+ private static final String TAG = "PhysicalWeb";
private static final String PREF_PHYSICAL_WEB_SWITCH = "physical_web_switch";
+ private static final int REQUEST_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -27,6 +32,46 @@ public class PhysicalWebPreferenceFragment extends PreferenceFragment {
initPhysicalWebSwitch();
}
+ private void ensureLocationPermission() {
gone 2015/12/28 23:35:56 nit: you can avoid the extra indentation if you fl
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (getActivity().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
+ == PackageManager.PERMISSION_GRANTED) {
+ Log.d(TAG, "Location permission already granted");
+ setPhysicalWebEnabled(true);
+ return;
+ }
+
+ Log.d(TAG, "Requesting location permission");
+ requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_ID);
+ return;
+ }
+
+ setPhysicalWebEnabled(true);
+ }
+
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[],
+ int[] grantResults) {
+ // TODO(cco3): Add UMA here.
+ switch (requestCode) {
+ case REQUEST_ID:
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ Log.d(TAG, "Location permission granted");
+ } else {
+ Log.d(TAG, "Location permission rejected");
+ }
+ break;
+ default:
+ }
+
+ // It doesn't matter whether we were given the location permission or not. We will flip
+ // the setting to true and let the PreferenceManager figure out what to do with the
+ // location permission or lack thereof.
+ setPhysicalWebEnabled(true);
+ }
+
private void initPhysicalWebSwitch() {
ChromeSwitchPreference physicalWebSwitch =
(ChromeSwitchPreference) findPreference(PREF_PHYSICAL_WEB_SWITCH);
@@ -38,11 +83,17 @@ public class PhysicalWebPreferenceFragment extends PreferenceFragment {
physicalWebSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- PrivacyPreferencesManager.getInstance(getActivity()).setPhysicalWebEnabled(
- (boolean) newValue);
+ if ((boolean) newValue) {
+ ensureLocationPermission();
+ } else {
+ setPhysicalWebEnabled(false);
+ }
return true;
}
});
}
-}
+ private void setPhysicalWebEnabled(boolean value) {
+ PrivacyPreferencesManager.getInstance(getActivity()).setPhysicalWebEnabled(value);
+ }
+}
« 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