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 <utils/Log.h>
22 #include <utils/String16.h>
23 #include <utils/misc.h>
24
25 #include "jni_helper.h"
26
27 namespace android {
28
29 /* JNI Helpers for wifi_hal implementation */
30
JNIHelper(JavaVM * vm)31 JNIHelper::JNIHelper(JavaVM *vm)
32 {
33 vm->AttachCurrentThread(&mEnv, NULL);
34 mVM = vm;
35 }
36
JNIHelper(JNIEnv * env)37 JNIHelper::JNIHelper(JNIEnv *env)
38 {
39 mVM = NULL;
40 mEnv = env;
41 }
42
~JNIHelper()43 JNIHelper::~JNIHelper()
44 {
45 if (mVM != NULL) {
46 // mVM->DetachCurrentThread(); /* 'attempting to detach while still running code' */
47 mVM = NULL; /* not really required; but may help debugging */
48 mEnv = NULL; /* not really required; but may help debugging */
49 }
50 }
51
newLocalRef(jobject obj)52 jobject JNIHelper::newLocalRef(jobject obj) {
53 return mEnv->NewLocalRef(obj);
54 }
55
deleteLocalRef(jobject obj)56 void JNIHelper::deleteLocalRef(jobject obj) {
57 mEnv->DeleteLocalRef(obj);
58 }
59
newByteArray(int num)60 JNIObject<jbyteArray> JNIHelper::newByteArray(int num) {
61 return JNIObject<jbyteArray>(*this, mEnv->NewByteArray(num));
62 }
63
setByteArrayRegion(jbyteArray array,int from,int to,const jbyte * bytes)64 void JNIHelper::setByteArrayRegion(jbyteArray array, int from, int to, const jbyte *bytes) {
65 mEnv->SetByteArrayRegion(array, from, to, bytes);
66 }
67 }; // namespace android
68