OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |