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

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

Issue 2105573002: Revert of 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: 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
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;
11 import android.net.ConnectivityManager; 12 import android.net.ConnectivityManager;
13 import android.os.Build;
12 import android.support.v4.content.PermissionChecker; 14 import android.support.v4.content.PermissionChecker;
13 15
14 16
15 /** 17 /**
16 * This class provides basic static utilities for the Physical Web. 18 * This class provides basic static utilities for the Physical Web.
17 */ 19 */
18 class Utils { 20 class Utils {
19 public static final int RESULT_FAILURE = 0; 21 public static final int RESULT_FAILURE = 0;
20 public static final int RESULT_SUCCESS = 1; 22 public static final int RESULT_SUCCESS = 1;
21 public static final int RESULT_INDETERMINATE = 2; 23 public static final int RESULT_INDETERMINATE = 2;
(...skipping 11 matching lines...) Expand all
33 } 35 }
34 36
35 public static int getBluetoothEnabledStatus(Context context) { 37 public static int getBluetoothEnabledStatus(Context context) {
36 int statusResult = RESULT_INDETERMINATE; 38 int statusResult = RESULT_INDETERMINATE;
37 if (isBluetoothPermissionGranted(context)) { 39 if (isBluetoothPermissionGranted(context)) {
38 BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); 40 BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
39 statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RES ULT_FAILURE; 41 statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RES ULT_FAILURE;
40 } 42 }
41 return statusResult; 43 return statusResult;
42 } 44 }
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
43 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698