xref: /aosp_15_r20/external/cronet/base/test/android/java_handler_thread_helpers.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/test/android/java_handler_thread_helpers.h"
6 
7 #include "base/android/java_handler_thread.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "base/task/current_thread.h"
10 #include "base/test/base_unittests_jni_headers/JavaHandlerThreadHelpers_jni.h"
11 
12 namespace base {
13 namespace android {
14 
15 // static
CreateJavaFirst()16 std::unique_ptr<JavaHandlerThread> JavaHandlerThreadHelpers::CreateJavaFirst() {
17   return std::make_unique<JavaHandlerThread>(
18       nullptr, Java_JavaHandlerThreadHelpers_testAndGetJavaHandlerThread(
19                    jni_zero::AttachCurrentThread()));
20 }
21 
22 // static
ThrowExceptionAndAbort(WaitableEvent * event)23 void JavaHandlerThreadHelpers::ThrowExceptionAndAbort(WaitableEvent* event) {
24   JNIEnv* env = jni_zero::AttachCurrentThread();
25   Java_JavaHandlerThreadHelpers_throwException(env);
26   DCHECK(jni_zero::HasException(env));
27   base::CurrentUIThread::Get()->Abort();
28   event->Signal();
29 }
30 
31 // static
IsExceptionTestException(ScopedJavaLocalRef<jthrowable> exception)32 bool JavaHandlerThreadHelpers::IsExceptionTestException(
33     ScopedJavaLocalRef<jthrowable> exception) {
34   JNIEnv* env = jni_zero::AttachCurrentThread();
35   return Java_JavaHandlerThreadHelpers_isExceptionTestException(env, exception);
36 }
37 
38 }  // namespace android
39 }  // namespace base
40