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

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

Issue 2038753004: Add a LocationUtils class to give all Chromium Android code access to location helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Adjust DEPS. Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.Manifest; 7 import android.Manifest;
8 import android.bluetooth.BluetoothAdapter; 8 import android.bluetooth.BluetoothAdapter;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.pm.PackageManager; 10 import android.content.pm.PackageManager;
11 import android.location.LocationManager;
12 import android.net.ConnectivityManager; 11 import android.net.ConnectivityManager;
13 import android.os.Build;
14 import android.support.v4.content.PermissionChecker; 12 import android.support.v4.content.PermissionChecker;
15 13
16 14
17 /** 15 /**
18 * This class provides basic static utilities for the Physical Web. 16 * This class provides basic static utilities for the Physical Web.
19 */ 17 */
20 class Utils { 18 class Utils {
21 public static final int RESULT_FAILURE = 0; 19 public static final int RESULT_FAILURE = 0;
22 public static final int RESULT_SUCCESS = 1; 20 public static final int RESULT_SUCCESS = 1;
23 public static final int RESULT_INDETERMINATE = 2; 21 public static final int RESULT_INDETERMINATE = 2;
(...skipping 11 matching lines...) Expand all
35 } 33 }
36 34
37 public static int getBluetoothEnabledStatus(Context context) { 35 public static int getBluetoothEnabledStatus(Context context) {
38 int statusResult = RESULT_INDETERMINATE; 36 int statusResult = RESULT_INDETERMINATE;
39 if (isBluetoothPermissionGranted(context)) { 37 if (isBluetoothPermissionGranted(context)) {
40 BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); 38 BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
41 statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RES ULT_FAILURE; 39 statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RES ULT_FAILURE;
42 } 40 }
43 return statusResult; 41 return statusResult;
44 } 42 }
45
46 public static boolean isLocationServicesEnabled(Context context) {
47 LocationManager lm = (LocationManager) context.getSystemService(Context. LOCATION_SERVICE);
48 boolean isGpsProviderEnabled = lm.isProviderEnabled(LocationManager.GPS_ PROVIDER);
49 boolean isNetworkProviderEnabled = lm.isProviderEnabled(LocationManager. NETWORK_PROVIDER);
50 return isGpsProviderEnabled || isNetworkProviderEnabled;
51 }
52
53 public static boolean isLocationPermissionGranted(Context context) {
54 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
55 return true;
56 }
57 return PermissionChecker.checkSelfPermission(context,
58 Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERM ISSION_GRANTED;
59 }
60
61 } 43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698