| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/test/bluetooth_test_android.h" | 5 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 EXPECT_EQ(0, gatt_open_connections_); | 49 EXPECT_EQ(0, gatt_open_connections_); |
| 50 BluetoothTestBase::TearDown(); | 50 BluetoothTestBase::TearDown(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() { | 53 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() { |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void BluetoothTestAndroid::InitWithDefaultAdapter() { | 57 void BluetoothTestAndroid::InitWithDefaultAdapter() { |
| 58 adapter_ = BluetoothAdapterAndroid::Create( | 58 adapter_ = BluetoothAdapterAndroid::Create( |
| 59 BluetoothAdapterWrapper_CreateWithDefaultAdapter()) | 59 BluetoothAdapterWrapper_CreateWithDefaultAdapter(), |
| 60 BluetoothManagerWrapper_CreateWithDefaultManager()) |
| 60 .get(); | 61 .get(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void BluetoothTestAndroid::InitWithoutDefaultAdapter() { | 64 void BluetoothTestAndroid::InitWithoutDefaultAdapter() { |
| 64 adapter_ = BluetoothAdapterAndroid::Create(NULL).get(); | 65 adapter_ = BluetoothAdapterAndroid::Create(NULL, NULL).get(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void BluetoothTestAndroid::InitWithFakeAdapter() { | 68 void BluetoothTestAndroid::InitWithFakeAdapter() { |
| 68 j_fake_bluetooth_adapter_.Reset(Java_FakeBluetoothAdapter_create( | 69 JNIEnv* env = AttachCurrentThread(); |
| 69 AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); | 70 j_fake_bluetooth_adapter_.Reset( |
| 71 Java_FakeBluetoothAdapter_create(env, reinterpret_cast<intptr_t>(this))); |
| 72 j_fake_bluetooth_manager_.Reset( |
| 73 Java_FakeBluetoothManager_create(env, reinterpret_cast<intptr_t>(this))); |
| 70 | 74 |
| 71 adapter_ = BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_).get(); | 75 adapter_ = BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_, |
| 76 j_fake_bluetooth_manager_) |
| 77 .get(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 bool BluetoothTestAndroid::DenyPermission() { | 80 bool BluetoothTestAndroid::DenyPermission() { |
| 75 Java_Fakes_setLocationServicesState( | 81 Java_Fakes_setLocationServicesState( |
| 76 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); | 82 AttachCurrentThread(), false /* hasPermission */, true /* isEnabled */); |
| 77 return true; | 83 return true; |
| 78 } | 84 } |
| 79 | 85 |
| 80 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( | 86 BluetoothDevice* BluetoothTestAndroid::SimulateLowEnergyDevice( |
| 81 int device_ordinal) { | 87 int device_ordinal) { |
| 82 TestBluetoothAdapterObserver observer(adapter_); | 88 TestBluetoothAdapterObserver observer(adapter_); |
| 83 Java_FakeBluetoothAdapter_simulateLowEnergyDevice( | 89 Java_FakeBluetoothAdapter_simulateLowEnergyDevice( |
| 84 AttachCurrentThread(), j_fake_bluetooth_adapter_, device_ordinal); | 90 AttachCurrentThread(), j_fake_bluetooth_adapter_, device_ordinal); |
| 85 return observer.last_device(); | 91 return observer.last_device(); |
| 86 } | 92 } |
| 87 | 93 |
| 94 void BluetoothTestAndroid::SimulateConnectedLowEnergyDevice( |
| 95 ConnectedDeviceType device_type) { |
| 96 Java_FakeBluetoothManager_simulateConnectedLowEnergyDevice( |
| 97 AttachCurrentThread(), j_fake_bluetooth_manager_, |
| 98 static_cast<int32_t>(device_type)); |
| 99 } |
| 100 |
| 88 void BluetoothTestAndroid::RememberDeviceForSubsequentAction( | 101 void BluetoothTestAndroid::RememberDeviceForSubsequentAction( |
| 89 BluetoothDevice* device) { | 102 BluetoothDevice* device) { |
| 90 BluetoothDeviceAndroid* device_android = | 103 BluetoothDeviceAndroid* device_android = |
| 91 static_cast<BluetoothDeviceAndroid*>(device); | 104 static_cast<BluetoothDeviceAndroid*>(device); |
| 92 | 105 |
| 93 Java_FakeBluetoothDevice_rememberDeviceForSubsequentAction( | 106 Java_FakeBluetoothDevice_rememberDeviceForSubsequentAction( |
| 94 base::android::AttachCurrentThread(), device_android->GetJavaObject()); | 107 base::android::AttachCurrentThread(), device_android->GetJavaObject()); |
| 95 } | 108 } |
| 96 | 109 |
| 97 void BluetoothTestAndroid::SimulateLocationServicesOff() { | 110 void BluetoothTestAndroid::SimulateLocationServicesOff() { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 524 } |
| 512 | 525 |
| 513 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( | 526 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( |
| 514 JNIEnv* env, | 527 JNIEnv* env, |
| 515 const JavaParamRef<jobject>& caller, | 528 const JavaParamRef<jobject>& caller, |
| 516 const JavaParamRef<jbyteArray>& value) { | 529 const JavaParamRef<jbyteArray>& value) { |
| 517 gatt_write_descriptor_attempts_++; | 530 gatt_write_descriptor_attempts_++; |
| 518 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); | 531 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); |
| 519 } | 532 } |
| 520 | 533 |
| 534 void BluetoothTestAndroid::OnFakeManagerGetConnectedDevices( |
| 535 JNIEnv* env, |
| 536 const JavaParamRef<jobject>& caller) { |
| 537 manager_get_connected_devices_attempts_++; |
| 538 } |
| 539 |
| 521 void BluetoothTestAndroid::OnFakeAdapterStateChanged( | 540 void BluetoothTestAndroid::OnFakeAdapterStateChanged( |
| 522 JNIEnv* env, | 541 JNIEnv* env, |
| 523 const JavaParamRef<jobject>& caller, | 542 const JavaParamRef<jobject>& caller, |
| 524 const bool powered) { | 543 const bool powered) { |
| 525 adapter_->NotifyAdapterPoweredChanged(powered); | 544 adapter_->NotifyAdapterPoweredChanged(powered); |
| 526 } | 545 } |
| 527 | 546 |
| 528 } // namespace device | 547 } // namespace device |
| OLD | NEW |