Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: device/bluetooth/test/bluetooth_test_android.cc

Issue 2708513002: bluetooth: Post a task when sending GATT events to simulate another thread. (Closed)
Patch Set: Remove unnecessary if statement Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/bind.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "device/bluetooth/android/wrappers.h" 15 #include "device/bluetooth/android/wrappers.h"
15 #include "device/bluetooth/bluetooth_adapter_android.h" 16 #include "device/bluetooth/bluetooth_adapter_android.h"
16 #include "device/bluetooth/bluetooth_device_android.h" 17 #include "device/bluetooth/bluetooth_device_android.h"
17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" 18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h"
18 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" 19 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h"
19 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" 20 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h"
20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 21 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
21 #include "jni/Fakes_jni.h" 22 #include "jni/Fakes_jni.h"
(...skipping 10 matching lines...) Expand all
32 BluetoothTestAndroid::~BluetoothTestAndroid() { 33 BluetoothTestAndroid::~BluetoothTestAndroid() {
33 } 34 }
34 35
35 void BluetoothTestAndroid::SetUp() { 36 void BluetoothTestAndroid::SetUp() {
36 // Register in SetUp so that ASSERT can be used. 37 // Register in SetUp so that ASSERT can be used.
37 ASSERT_TRUE(RegisterNativesImpl(AttachCurrentThread())); 38 ASSERT_TRUE(RegisterNativesImpl(AttachCurrentThread()));
38 39
39 // Set the permission to true so that we can use the API. 40 // Set the permission to true so that we can use the API.
40 Java_Fakes_setLocationServicesState( 41 Java_Fakes_setLocationServicesState(
41 AttachCurrentThread(), true /* hasPermission */, true /* isEnabled */); 42 AttachCurrentThread(), true /* hasPermission */, true /* isEnabled */);
43 Java_Fakes_initFakeThreadUtilsWrapper(AttachCurrentThread(),
44 reinterpret_cast<intptr_t>(this));
42 } 45 }
43 46
44 void BluetoothTestAndroid::TearDown() { 47 void BluetoothTestAndroid::TearDown() {
45 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 48 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
46 for (auto* device : devices) { 49 for (auto* device : devices) {
47 DeleteDevice(device); 50 DeleteDevice(device);
48 } 51 }
49 EXPECT_EQ(0, gatt_open_connections_); 52 EXPECT_EQ(0, gatt_open_connections_);
53
50 BluetoothTestBase::TearDown(); 54 BluetoothTestBase::TearDown();
51 } 55 }
52 56
57 static void RunJavaRunnable(
58 const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
59 Java_Fakes_runRunnable(AttachCurrentThread(), runnable_ref);
60 }
61
62 void BluetoothTestAndroid::PostTaskFromJava(
63 JNIEnv* env,
64 const JavaParamRef<jobject>& caller,
65 const JavaParamRef<jobject>& runnable) {
66 base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
67 // ScopedJavaGlobalRef does not hold onto the env reference, so it is safe to
68 // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
69 // running the Runnable.
70 runnable_ref.Reset(env, runnable);
71 message_loop_.task_runner()->PostTask(
72 FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref));
73 }
74
53 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() { 75 bool BluetoothTestAndroid::PlatformSupportsLowEnergy() {
54 return true; 76 return true;
55 } 77 }
56 78
57 void BluetoothTestAndroid::InitWithDefaultAdapter() { 79 void BluetoothTestAndroid::InitWithDefaultAdapter() {
58 adapter_ = BluetoothAdapterAndroid::Create( 80 adapter_ = BluetoothAdapterAndroid::Create(
59 BluetoothAdapterWrapper_CreateWithDefaultAdapter()) 81 BluetoothAdapterWrapper_CreateWithDefaultAdapter())
60 .get(); 82 .get();
61 } 83 }
62 84
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 541 }
520 542
521 void BluetoothTestAndroid::OnFakeAdapterStateChanged( 543 void BluetoothTestAndroid::OnFakeAdapterStateChanged(
522 JNIEnv* env, 544 JNIEnv* env,
523 const JavaParamRef<jobject>& caller, 545 const JavaParamRef<jobject>& caller,
524 const bool powered) { 546 const bool powered) {
525 adapter_->NotifyAdapterPoweredChanged(powered); 547 adapter_->NotifyAdapterPoweredChanged(powered);
526 } 548 }
527 549
528 } // namespace device 550 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698