Commit f0cc0ad3 authored by iankc's avatar iankc Committed by Commit bot

Add Bluetooth Checks to Service

This change adds two bluetooth checks. 1 is to determine if the hardware has bluetooth capabilities. 2 is to determine if bluetooth is on for the device. Both conditions must be met for the PhysicalWebSharing feature to be enabled.

BUG=685856

Review-Url: https://codereview.chromium.org/2737393003
Cr-Commit-Position: refs/heads/master@{#456216}
parent e4437fe7
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
package org.chromium.chrome.browser.physicalweb; package org.chromium.chrome.browser.physicalweb;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
...@@ -153,4 +157,28 @@ public class PhysicalWeb { ...@@ -153,4 +157,28 @@ public class PhysicalWeb {
new Intent(Intent.ACTION_VIEW, Uri.parse(UrlConstants.PHYSICAL_WEB_URL)) new Intent(Intent.ACTION_VIEW, Uri.parse(UrlConstants.PHYSICAL_WEB_URL))
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} }
/**
* Check if bluetooth is on and enabled.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean bluetoothIsEnabled() {
Context context = ContextUtils.getApplicationContext();
BluetoothManager bluetoothManager =
(BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
return bluetoothAdapter != null && bluetoothAdapter.isEnabled();
}
/**
* Check if the device bluetooth hardware supports BLE advertisements.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean hasBleAdvertiseCapability() {
Context context = ContextUtils.getApplicationContext();
BluetoothManager bluetoothManager =
(BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
return bluetoothAdapter != null && bluetoothAdapter.getBluetoothLeAdvertiser() != null;
}
} }
...@@ -26,11 +26,15 @@ public class PhysicalWebShareActivity extends ShareActivity { ...@@ -26,11 +26,15 @@ public class PhysicalWebShareActivity extends ShareActivity {
/** /**
* Returns whether we should show this sharing option in the share sheet. * Returns whether we should show this sharing option in the share sheet.
* Pre-conditions for Physical Web Sharing to be enabled: * Pre-conditions for Physical Web Sharing to be enabled:
* Device has hardware BLE advertising capabilities.
* Device had Bluetooth on.
* Device is Marshmallow or above. * Device is Marshmallow or above.
* Device has sharing feature enabled. * Device has sharing feature enabled.
* @return {@code true} if the feature should be enabled. * @return {@code true} if the feature should be enabled.
*/ */
public static boolean featureIsAvailable() { public static boolean featureIsAvailable() {
return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
return PhysicalWeb.hasBleAdvertiseCapability() && PhysicalWeb.bluetoothIsEnabled()
&& PhysicalWeb.sharingIsEnabled();
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment