| Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/Utils.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/Utils.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/Utils.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..638f66fb49504cd091e6c7b192e91acd88c2300a
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/Utils.java
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.physicalweb;
|
| +
|
| +import android.Manifest;
|
| +import android.bluetooth.BluetoothAdapter;
|
| +import android.content.Context;
|
| +import android.content.pm.PackageManager;
|
| +import android.location.LocationManager;
|
| +import android.net.ConnectivityManager;
|
| +import android.os.Build;
|
| +import android.support.v4.content.PermissionChecker;
|
| +
|
| +
|
| +/**
|
| + * This class provides basic static utilities for the Physical Web.
|
| + */
|
| +class Utils {
|
| + public static final int RESULT_FAILURE = 0;
|
| + public static final int RESULT_SUCCESS = 1;
|
| + public static final int RESULT_INDETERMINATE = 2;
|
| +
|
| + public static boolean isDataConnectionActive(Context context) {
|
| + ConnectivityManager cm =
|
| + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
| + return (cm.getActiveNetworkInfo() != null
|
| + && cm.getActiveNetworkInfo().isConnectedOrConnecting());
|
| + }
|
| +
|
| + public static boolean isBluetoothPermissionGranted(Context context) {
|
| + return PermissionChecker.checkSelfPermission(context, Manifest.permission.BLUETOOTH)
|
| + == PackageManager.PERMISSION_GRANTED;
|
| + }
|
| +
|
| + public static int getBluetoothEnabledStatus(Context context) {
|
| + int statusResult = RESULT_INDETERMINATE;
|
| + if (isBluetoothPermissionGranted(context)) {
|
| + BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
| + statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RESULT_FAILURE;
|
| + }
|
| + return statusResult;
|
| + }
|
| +
|
| + public static boolean isLocationServicesEnabled(Context context) {
|
| + LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
| + boolean isGpsProviderEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
| + boolean isNetworkProviderEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
| + return isGpsProviderEnabled || isNetworkProviderEnabled;
|
| + }
|
| +
|
| + public static boolean isLocationPermissionGranted(Context context) {
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
| + return true;
|
| + }
|
| + return PermissionChecker.checkSelfPermission(context,
|
| + Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
| + }
|
| +
|
| +}
|
|
|