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
27namespace android {
28
29/* JNI Helpers for wifi_hal implementation */
30
31JNIHelper::JNIHelper(JavaVM *vm)
32{
33    vm->AttachCurrentThread(&mEnv, NULL);
34    mVM = vm;
35}
36
37JNIHelper::JNIHelper(JNIEnv *env)
38{
39    mVM  = NULL;
40    mEnv = env;
41}
42
43JNIHelper::~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
52jobject JNIHelper::newLocalRef(jobject obj) {
53      return mEnv->NewLocalRef(obj);
54}
55
56void JNIHelper::deleteLocalRef(jobject obj) {
57      mEnv->DeleteLocalRef(obj);
58}
59
60JNIObject<jbyteArray> JNIHelper::newByteArray(int num) {
61    return JNIObject<jbyteArray>(*this, mEnv->NewByteArray(num));
62}
63
64void JNIHelper::setByteArrayRegion(jbyteArray array, int from, int to, const jbyte *bytes) {
65    mEnv->SetByteArrayRegion(array, from, to, bytes);
66}
67}; // namespace android
68