QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_android.h
blobc9db73f99f64dea48c52005c88122f13815a84c3
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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_
8 #include "base/android/jni_android.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/weak_ptr.h"
11 #include "device/bluetooth/bluetooth_adapter.h"
13 namespace base {
14 class SequencedTaskRunner;
15 } // namespace base
17 using base::android::ScopedJavaLocalRef;
19 namespace device {
21 // BluetoothAdapterAndroid, along with the Java class
22 // org.chromium.device.bluetooth.BluetoothAdapter, implement BluetoothAdapter.
24 // The GATT Profile over Low Energy is supported, but not Classic Bluetooth at
25 // this time. LE GATT support has been initially built out to support Web
26 // Bluetooth, which does not need other Bluetooth features. There is no
27 // technical reason they can not be supported should a need arrise.
29 // BluetoothAdapterAndroid is reference counted, and owns the lifetime of the
30 // Java class BluetoothAdapter via j_adapter_. The adapter also owns a tree of
31 // additional C++ objects (Devices, Services, Characteristics, Descriptors),
32 // with each C++ object owning its associated Java class.
33 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
34 : public BluetoothAdapter {
35 public:
36 // Create a BluetoothAdapterAndroid instance.
38 // |java_bluetooth_adapter_wrapper| is optional. If it is NULL the adapter
39 // will return false for |IsPresent()| and not be functional.
41 // The BluetoothAdapterAndroid instance will indirectly hold a Java reference
42 // to |bluetooth_adapter_wrapper|.
43 static base::WeakPtr<BluetoothAdapterAndroid> Create(
44 jobject bluetooth_adapter_wrapper); // Java Type: bluetoothAdapterWrapper
46 // Register C++ methods exposed to Java using JNI.
47 static bool RegisterJNI(JNIEnv* env);
49 // BluetoothAdapter:
50 std::string GetAddress() const override;
51 std::string GetName() const override;
52 void SetName(const std::string& name,
53 const base::Closure& callback,
54 const ErrorCallback& error_callback) override;
55 bool IsInitialized() const override;
56 bool IsPresent() const override;
57 bool IsPowered() const override;
58 void SetPowered(bool powered,
59 const base::Closure& callback,
60 const ErrorCallback& error_callback) override;
61 bool IsDiscoverable() const override;
62 void SetDiscoverable(bool discoverable,
63 const base::Closure& callback,
64 const ErrorCallback& error_callback) override;
65 bool IsDiscovering() const override;
66 void CreateRfcommService(
67 const BluetoothUUID& uuid,
68 const ServiceOptions& options,
69 const CreateServiceCallback& callback,
70 const CreateServiceErrorCallback& error_callback) override;
71 void CreateL2capService(
72 const BluetoothUUID& uuid,
73 const ServiceOptions& options,
74 const CreateServiceCallback& callback,
75 const CreateServiceErrorCallback& error_callback) override;
76 void RegisterAudioSink(
77 const BluetoothAudioSink::Options& options,
78 const AcquiredCallback& callback,
79 const BluetoothAudioSink::ErrorCallback& error_callback) override;
80 void RegisterAdvertisement(
81 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
82 const CreateAdvertisementCallback& callback,
83 const CreateAdvertisementErrorCallback& error_callback) override;
85 // Handles a scan error event by invalidating all discovery sessions.
86 void OnScanFailed(JNIEnv* env, jobject caller);
88 // Creates or updates device with advertised UUID information when a device is
89 // discovered during a scan.
90 void CreateOrUpdateDeviceOnScan(
91 JNIEnv* env,
92 jobject caller,
93 const jstring& address,
94 jobject bluetooth_device_wrapper, // Java Type: bluetoothDeviceWrapper
95 jobject advertised_uuids); // Java Type: List<ParcelUuid>
97 protected:
98 BluetoothAdapterAndroid();
99 ~BluetoothAdapterAndroid() override;
101 // BluetoothAdapter:
102 void AddDiscoverySession(
103 BluetoothDiscoveryFilter* discovery_filter,
104 const base::Closure& callback,
105 const DiscoverySessionErrorCallback& error_callback) override;
106 void RemoveDiscoverySession(
107 BluetoothDiscoveryFilter* discovery_filter,
108 const base::Closure& callback,
109 const DiscoverySessionErrorCallback& error_callback) override;
110 void SetDiscoveryFilter(
111 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
112 const base::Closure& callback,
113 const DiscoverySessionErrorCallback& error_callback) override;
114 void RemovePairingDelegateInternal(
115 BluetoothDevice::PairingDelegate* pairing_delegate) override;
117 // Java object org.chromium.device.bluetooth.ChromeBluetoothAdapter.
118 base::android::ScopedJavaGlobalRef<jobject> j_adapter_;
120 // Note: This should remain the last member so it'll be destroyed and
121 // invalidate its weak pointers before any other members are destroyed.
122 base::WeakPtrFactory<BluetoothAdapterAndroid> weak_ptr_factory_;
124 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterAndroid);
127 } // namespace device
129 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_