third_party: Add OWNERS for re2 library.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_adapter_android.h
blobd458bb5659cc2a42c1de519da1bc02db69dc1531
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/memory/weak_ptr.h"
10 #include "device/bluetooth/bluetooth_adapter.h"
12 namespace base {
13 class SequencedTaskRunner;
14 } // namespace base
16 namespace device {
18 // The BluetoothAdapterAndroid class implements BluetoothAdapter for the
19 // Android platform.
20 class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
21 : public BluetoothAdapter {
22 public:
23 // Create a BluetoothAdapterAndroid instance.
24 static base::WeakPtr<BluetoothAdapterAndroid> CreateAdapter();
26 // Create a BluetoothAdapterAndroid instance without Bluetooth permission.
27 static base::WeakPtr<BluetoothAdapterAndroid>
28 CreateAdapterWithoutPermissionForTesting();
30 // Register C++ methods exposed to Java using JNI.
31 static bool RegisterJNI(JNIEnv* env);
33 // True if this app has android permissions necessary for Bluetooth.
34 bool HasBluetoothPermission() const;
36 // BluetoothAdapter:
37 std::string GetAddress() const override;
38 std::string GetName() const override;
39 void SetName(const std::string& name,
40 const base::Closure& callback,
41 const ErrorCallback& error_callback) override;
42 bool IsInitialized() const override;
43 bool IsPresent() const override;
44 bool IsPowered() const override;
45 void SetPowered(bool powered,
46 const base::Closure& callback,
47 const ErrorCallback& error_callback) override;
48 bool IsDiscoverable() const override;
49 void SetDiscoverable(bool discoverable,
50 const base::Closure& callback,
51 const ErrorCallback& error_callback) override;
52 bool IsDiscovering() const override;
53 void CreateRfcommService(
54 const BluetoothUUID& uuid,
55 const ServiceOptions& options,
56 const CreateServiceCallback& callback,
57 const CreateServiceErrorCallback& error_callback) override;
58 void CreateL2capService(
59 const BluetoothUUID& uuid,
60 const ServiceOptions& options,
61 const CreateServiceCallback& callback,
62 const CreateServiceErrorCallback& error_callback) override;
63 void RegisterAudioSink(
64 const BluetoothAudioSink::Options& options,
65 const AcquiredCallback& callback,
66 const BluetoothAudioSink::ErrorCallback& error_callback) override;
67 void RegisterAdvertisement(
68 scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
69 const CreateAdvertisementCallback& callback,
70 const CreateAdvertisementErrorCallback& error_callback) override;
72 protected:
73 BluetoothAdapterAndroid();
74 ~BluetoothAdapterAndroid() override;
76 // BluetoothAdapter:
77 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
78 const base::Closure& callback,
79 const ErrorCallback& error_callback) override;
80 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter,
81 const base::Closure& callback,
82 const ErrorCallback& error_callback) override;
83 void SetDiscoveryFilter(scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
84 const base::Closure& callback,
85 const ErrorCallback& error_callback) override;
86 void RemovePairingDelegateInternal(
87 BluetoothDevice::PairingDelegate* pairing_delegate) override;
89 // Java object org.chromium.device.bluetooth.BluetoothAdapter.
90 base::android::ScopedJavaGlobalRef<jobject> j_bluetooth_adapter_;
92 std::string address_;
93 std::string name_;
95 // Note: This should remain the last member so it'll be destroyed and
96 // invalidate its weak pointers before any other members are destroyed.
97 base::WeakPtrFactory<BluetoothAdapterAndroid> weak_ptr_factory_;
99 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterAndroid);
102 } // namespace device
104 #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_