1 /*
2 * Copyright 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "wifi"
18
19 #include <hardware_legacy/wifi_hal.h>
20 #include <nativehelper/ScopedUtfChars.h>
21 #include <nativehelper/jni.h>
22 #include <utils/Log.h>
23 #include <utils/String16.h>
24 #include <utils/misc.h>
25
26 #include "jni_helper.h"
27
28 namespace android {
29
30 /* JNI Helpers for wifi_hal implementation */
31
JNIHelper(JavaVM * vm)32 JNIHelper::JNIHelper(JavaVM *vm)
33 {
34 vm->AttachCurrentThread(&mEnv, NULL);
35 mVM = vm;
36 }
37
JNIHelper(JNIEnv * env)38 JNIHelper::JNIHelper(JNIEnv *env)
39 {
40 mVM = NULL;
41 mEnv = env;
42 }
43
~JNIHelper()44 JNIHelper::~JNIHelper()
45 {
46 if (mVM != NULL) {
47 // mVM->DetachCurrentThread(); /* 'attempting to detach while still running code' */
48 mVM = NULL; /* not really required; but may help debugging */
49 mEnv = NULL; /* not really required; but may help debugging */
50 }
51 }
52
newLocalRef(jobject obj)53 jobject JNIHelper::newLocalRef(jobject obj) {
54 return mEnv->NewLocalRef(obj);
55 }
56
deleteLocalRef(jobject obj)57 void JNIHelper::deleteLocalRef(jobject obj) {
58 mEnv->DeleteLocalRef(obj);
59 }
60
newByteArray(int num)61 JNIObject<jbyteArray> JNIHelper::newByteArray(int num) {
62 return JNIObject<jbyteArray>(*this, mEnv->NewByteArray(num));
63 }
64
setByteArrayRegion(jbyteArray array,int from,int to,const jbyte * bytes)65 void JNIHelper::setByteArrayRegion(jbyteArray array, int from, int to, const jbyte *bytes) {
66 mEnv->SetByteArrayRegion(array, from, to, bytes);
67 }
68 }; // namespace android
69