#ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_ANDROID_H_
#define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_ANDROID_H_
#include <stdint.h>
#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/test/task_environment.h"
#include "device/bluetooth/bluetooth_common.h"
#include "device/bluetooth/bluetooth_socket.h"
#include "device/bluetooth/test/bluetooth_test.h"
namespace device {
class BluetoothTestAndroid : public BluetoothTestBase {
public:
BluetoothTestAndroid();
explicit BluetoothTestAndroid(
base::test::TaskEnvironment::TimeSource time_source);
~BluetoothTestAndroid() override;
void SetUp() override;
void TearDown() override;
bool PlatformSupportsLowEnergy() override;
void InitWithDefaultAdapter() override;
void InitWithoutDefaultAdapter() override;
void InitWithFakeAdapter() override;
bool DenyPermission() override;
BluetoothDevice* SimulateLowEnergyDevice(int device_ordinal) override;
BluetoothDevice* SimulateClassicDevice() override;
void RememberDeviceForSubsequentAction(BluetoothDevice* device) override;
void SimulateGattConnection(BluetoothDevice* device) override;
void SimulateGattConnectionError(BluetoothDevice* device,
BluetoothDevice::ConnectErrorCode) override;
void SimulateGattDisconnection(BluetoothDevice* device) override;
void SimulateGattServicesDiscovered(
BluetoothDevice* device,
const std::vector<std::string>& uuids,
const std::vector<std::string>& blocked_uuids = {}) override;
void SimulateGattServicesDiscoveryError(BluetoothDevice* device) override;
void SimulateGattCharacteristic(BluetoothRemoteGattService* service,
const std::string& uuid,
int properties) override;
void RememberCharacteristicForSubsequentAction(
BluetoothRemoteGattCharacteristic* characteristic) override;
void RememberCCCDescriptorForSubsequentAction(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattNotifySessionStarted(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattNotifySessionStartError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattNotifySessionStopped(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattNotifySessionStopError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode error_code) override;
void SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattCharacteristicChanged(
BluetoothRemoteGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
void SimulateGattCharacteristicRead(
BluetoothRemoteGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
void SimulateGattCharacteristicReadError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode) override;
void SimulateGattCharacteristicReadWillFailSynchronouslyOnce(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattCharacteristicWrite(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattCharacteristicWriteError(
BluetoothRemoteGattCharacteristic* characteristic,
BluetoothGattService::GattErrorCode) override;
void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(
BluetoothRemoteGattCharacteristic* characteristic) override;
void SimulateGattDescriptor(BluetoothRemoteGattCharacteristic* characteristic,
const std::string& uuid) override;
void RememberDescriptorForSubsequentAction(
BluetoothRemoteGattDescriptor* descriptor) override;
void SimulateGattDescriptorRead(BluetoothRemoteGattDescriptor* descriptor,
const std::vector<uint8_t>& value) override;
void SimulateGattDescriptorReadError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothGattService::GattErrorCode) override;
void SimulateGattDescriptorReadWillFailSynchronouslyOnce(
BluetoothRemoteGattDescriptor* descriptor) override;
void SimulateGattDescriptorWrite(
BluetoothRemoteGattDescriptor* descriptor) override;
void SimulateGattDescriptorWriteError(
BluetoothRemoteGattDescriptor* descriptor,
BluetoothGattService::GattErrorCode) override;
void SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
BluetoothRemoteGattDescriptor* descriptor) override;
void SetEnabledDeviceTransport(BluetoothTransport transport);
std::string SimulatePairedClassicDevice(int device_ordinal,
bool notify_callback = false);
void UnpairDevice(std::string address);
void SimulateAclConnectStateChange(BluetoothDevice* device,
uint8_t transport,
bool connected);
void SimulateLocationServicesOff();
void ForceIllegalStateException();
void FailCurrentLeScan(int error_code);
void FailNextServiceConnection(BluetoothDevice* device,
const std::string& error_message);
std::vector<uint8_t> GetSentBytes(BluetoothSocket* socket);
void SetReceivedBytes(BluetoothSocket* socket,
const std::vector<uint8_t>& bytes);
void FailNextOperation(BluetoothSocket* socket,
const std::string& error_message);
void OnFakeBluetoothDeviceConnectGattCalled(JNIEnv* env);
void OnFakeBluetoothGattDisconnect(JNIEnv* env);
void OnFakeBluetoothGattClose(JNIEnv* env);
void OnFakeBluetoothGattDiscoverServices(JNIEnv* env);
void OnFakeBluetoothGattSetCharacteristicNotification(JNIEnv* env);
void OnFakeBluetoothGattReadCharacteristic(JNIEnv* env);
void OnFakeBluetoothGattWriteCharacteristic(
JNIEnv* env,
const base::android::JavaParamRef<jbyteArray>& value);
void OnFakeBluetoothGattReadDescriptor(JNIEnv* env);
void OnFakeBluetoothGattWriteDescriptor(
JNIEnv* env,
const base::android::JavaParamRef<jbyteArray>& value);
void OnFakeAdapterStateChanged(JNIEnv* env, const bool powered);
void PostTaskFromJava(JNIEnv* env,
const base::android::JavaParamRef<jobject>& runnable);
void PostDelayedTaskFromJava(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& runnable,
jlong delayMillis);
base::android::ScopedJavaGlobalRef<jobject> j_default_bluetooth_adapter_;
base::android::ScopedJavaGlobalRef<jobject> j_fake_bluetooth_adapter_;
int gatt_open_connections_ = 0;
raw_ptr<BluetoothRemoteGattDescriptor> remembered_ccc_descriptor_ = nullptr;
};
typedef BluetoothTestAndroid BluetoothTest;
}
#endif