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

Unified Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java

Issue 1215303006: bluetooth: android: Initial BluetoothDeviceAndroid implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-discovery-
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
new file mode 100644
index 0000000000000000000000000000000000000000..cbe6919761c5b7997d6e741460f44ddee911b1bb
--- /dev/null
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java
@@ -0,0 +1,98 @@
+// Copyright 2015 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.device.bluetooth;
+
+import android.annotation.TargetApi;
+import android.bluetooth.BluetoothDevice;
+import android.os.Build;
+import android.os.ParcelUuid;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.base.Log;
+
+import java.util.List;
+
+/**
+ * Exposes android.bluetooth.BluetoothDevice as necessary for C++
+ * device::BluetoothDeviceAndroid.
+ *
+ * Lifetime is controlled by device::BluetoothDeviceAndroid.
+ */
+@JNINamespace("device")
+@TargetApi(Build.VERSION_CODES.LOLLIPOP)
+final class ChromeBluetoothDevice {
+ private static final String TAG = "cr.Bluetooth";
+
+ private final Wrappers.BluetoothDeviceWrapper mDevice;
+ private List<ParcelUuid> mUuidsFromScan;
+
+ private ChromeBluetoothDevice(Wrappers.BluetoothDeviceWrapper deviceWrapper) {
+ mDevice = deviceWrapper;
+ Log.v(TAG, "ChromeBluetoothDevice created.");
+ }
+
+ // ---------------------------------------------------------------------------------------------
+ // BluetoothDeviceAndroid methods implemented in java:
+
+ // Implements BluetoothDeviceAndroid::Create.
+ // 'Object' type must be used because inner class Wrappers.BluetoothDeviceWrapper reference is
+ // not handled by jni_generator.py JavaToJni. http://crbug.com/505554
+ @CalledByNative
+ private static ChromeBluetoothDevice create(Object deviceWrapper) {
+ return new ChromeBluetoothDevice((Wrappers.BluetoothDeviceWrapper) deviceWrapper);
+ }
+
+ // Implements BluetoothDeviceAndroid::UpdateAdvertisedUUIDs.
+ @CalledByNative
+ private boolean updateAdvertisedUUIDs(List<ParcelUuid> uuidsFromScan) {
+ if (uuidsFromScan.equals(mUuidsFromScan)) {
+ return false;
+ }
+ mUuidsFromScan = uuidsFromScan;
+ return true;
+ }
+
+ // Implements BluetoothDeviceAndroid::GetBluetoothClass.
+ @CalledByNative
+ private int getBluetoothClass() {
+ return mDevice.getBluetoothClass_getDeviceClass();
+ }
+
+ // Implements BluetoothDeviceAndroid::GetAddress.
+ @CalledByNative
+ private String getAddress() {
+ return mDevice.getAddress();
+ }
+
+ // Implements BluetoothDeviceAndroid::IsPaired.
+ @CalledByNative
+ private boolean isPaired() {
+ return mDevice.getBondState() == BluetoothDevice.BOND_BONDED;
+ }
+
+ // Implements BluetoothDeviceAndroid::GetUUIDs.
Jeffrey Yasskin 2015/07/07 00:11:13 More "Used in implementation of GetUUIDs", but I g
scheib 2015/07/08 00:49:10 True, yes.
+ // Returns number of UUIDs found when scanning.
+ @CalledByNative
+ private int getUuidsCount() {
+ if (mUuidsFromScan == null) {
+ return 0;
+ }
+ return mUuidsFromScan.size();
+ }
+
+ // Implements BluetoothDeviceAndroid::GetUUIDs.
+ // Returns one UUID String from the array of UUIDs.
+ @CalledByNative
+ private String getUuid(int i) {
+ return mUuidsFromScan.get(i).toString();
+ }
+
+ // Implements BluetoothDeviceAndroid::GetDeviceName.
+ @CalledByNative
+ private String getDeviceName() {
+ return mDevice.getName();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698