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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/test/bluetooth_test_android.cc
diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc
index 4b55498dda947984fbe682123bfdb9aba781d373..b718cf44049fbad83026e65299b9092e52816ec9 100644
--- a/device/bluetooth/test/bluetooth_test_android.cc
+++ b/device/bluetooth/test/bluetooth_test_android.cc
@@ -9,6 +9,7 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "device/bluetooth/android/wrappers.h"
@@ -39,6 +40,8 @@ void BluetoothTestAndroid::SetUp() {
// Set the permission to true so that we can use the API.
Java_Fakes_setLocationServicesState(
AttachCurrentThread(), true /* hasPermission */, true /* isEnabled */);
+ Java_Fakes_initFakeThreadUtilsWrapper(AttachCurrentThread(),
+ reinterpret_cast<intptr_t>(this));
}
void BluetoothTestAndroid::TearDown() {
@@ -47,9 +50,28 @@ void BluetoothTestAndroid::TearDown() {
DeleteDevice(device);
}
EXPECT_EQ(0, gatt_open_connections_);
+
BluetoothTestBase::TearDown();
}
+static void RunJavaRunnable(
+ const base::android::ScopedJavaGlobalRef<jobject>& runnable_ref) {
+ Java_Fakes_runRunnable(AttachCurrentThread(), runnable_ref);
+}
+
+void BluetoothTestAndroid::PostTaskFromJava(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& caller,
+ const JavaParamRef<jobject>& runnable) {
+ base::android::ScopedJavaGlobalRef<jobject> runnable_ref;
+ // ScopedJavaGlobalRef does not hold onto the env reference, so it is safe to
+ // use it across threads. |RunJavaRunnable| will acquire a new JNIEnv before
+ // running the Runnable.
+ runnable_ref.Reset(env, runnable);
+ message_loop_.task_runner()->PostTask(
+ FROM_HERE, base::Bind(&RunJavaRunnable, runnable_ref));
+}
+
bool BluetoothTestAndroid::PlatformSupportsLowEnergy() {
return true;
}
« 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