OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.device.bluetooth; | |
6 | |
7 import android.annotation.TargetApi; | |
8 import android.bluetooth.BluetoothDevice; | |
9 import android.os.Build; | |
10 import android.os.ParcelUuid; | |
11 | |
12 import org.chromium.base.CalledByNative; | |
13 import org.chromium.base.JNINamespace; | |
14 import org.chromium.base.Log; | |
15 | |
16 import java.util.List; | |
17 | |
18 /** | |
19 * Exposes android.bluetooth.BluetoothDevice as necessary for C++ | |
20 * device::BluetoothDeviceAndroid. | |
21 * | |
22 * Lifetime is controlled by device::BluetoothDeviceAndroid. | |
23 */ | |
24 @JNINamespace("device") | |
25 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
26 final class ChromeBluetoothDevice { | |
27 private static final String TAG = "cr.Bluetooth"; | |
28 | |
29 private final Wrappers.BluetoothDeviceWrapper mDevice; | |
30 private List<ParcelUuid> mUuidsFromScan; | |
31 | |
32 private ChromeBluetoothDevice(Wrappers.BluetoothDeviceWrapper deviceWrapper) { | |
33 mDevice = deviceWrapper; | |
34 Log.v(TAG, "ChromeBluetoothDevice created."); | |
35 } | |
36 | |
37 // ------------------------------------------------------------------------- -------------------- | |
38 // BluetoothDeviceAndroid methods implemented in java: | |
39 | |
40 // Implements BluetoothDeviceAndroid::Create. | |
41 // 'Object' type must be used because inner class Wrappers.BluetoothDeviceWr apper reference is | |
42 // not handled by jni_generator.py JavaToJni. http://crbug.com/505554 | |
43 @CalledByNative | |
44 private static ChromeBluetoothDevice create(Object deviceWrapper) { | |
45 return new ChromeBluetoothDevice((Wrappers.BluetoothDeviceWrapper) devic eWrapper); | |
46 } | |
47 | |
48 // Implements BluetoothDeviceAndroid::UpdateAdvertisedUUIDs. | |
49 @CalledByNative | |
50 private boolean updateAdvertisedUUIDs(List<ParcelUuid> uuidsFromScan) { | |
51 if ((mUuidsFromScan == null && uuidsFromScan == null) | |
52 || (mUuidsFromScan != null && mUuidsFromScan.equals(uuidsFromSca n))) { | |
53 return false; | |
54 } | |
55 mUuidsFromScan = uuidsFromScan; | |
56 return true; | |
57 } | |
58 | |
59 // Implements BluetoothDeviceAndroid::GetBluetoothClass. | |
60 @CalledByNative | |
61 private int getBluetoothClass() { | |
62 return mDevice.getBluetoothClass_getDeviceClass(); | |
63 } | |
64 | |
65 // Implements BluetoothDeviceAndroid::GetAddress. | |
66 @CalledByNative | |
67 private String getAddress() { | |
68 return mDevice.getAddress(); | |
69 } | |
70 | |
71 // Implements BluetoothDeviceAndroid::IsPaired. | |
72 @CalledByNative | |
73 private boolean isPaired() { | |
74 return mDevice.getBondState() == BluetoothDevice.BOND_BONDED; | |
75 } | |
76 | |
77 // Implements BluetoothDeviceAndroid::GetUUIDs. | |
78 @CalledByNative | |
79 private String[] getUuids() { | |
armansito
2015/07/09 18:54:22
Right, my previous comment was basically that GetU
scheib
2015/07/09 20:31:04
Done.
| |
80 int uuidCount = (mUuidsFromScan != null) ? mUuidsFromScan.size() : 0; | |
81 String[] string_array = new String[uuidCount]; | |
82 for (int i = 0; i < uuidCount; i++) { | |
83 string_array[i] = mUuidsFromScan.get(i).toString(); | |
84 } | |
85 return string_array; | |
86 } | |
87 | |
88 // Implements BluetoothDeviceAndroid::GetDeviceName. | |
89 @CalledByNative | |
90 private String getDeviceName() { | |
91 return mDevice.getName(); | |
92 } | |
93 } | |
OLD | NEW |