From a076a71d5d85a66af05899d051430bdb1f16d0e8 Mon Sep 17 00:00:00 2001 From: Jan Altensen Date: Sun, 10 May 2020 15:35:37 +0200 Subject: [PATCH] fm: add empty libfm_jni boilerplate Change-Id: I14a0349b69819c23d82ab4495e5b7b178d936513 --- Android.mk | 35 +++++++++ libfm_jni.cpp | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 Android.mk create mode 100644 libfm_jni.cpp diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..bee193f --- /dev/null +++ b/Android.mk @@ -0,0 +1,35 @@ +# +# Copyright (C) 2020 The LineageOS Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ifeq ($(BOARD_HAVE_SLSI_FM), true) + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + libfm_jni.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + liblog + +LOCAL_MODULE := libfmjni +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + +endif # BOARD_HAVE_SLSI_FM diff --git a/libfm_jni.cpp b/libfm_jni.cpp new file mode 100644 index 0000000..0c4e4eb --- /dev/null +++ b/libfm_jni.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "FMLIB_JNI" + +jboolean openDev(JNIEnv *env, jobject thiz) +{ +} + +jboolean closeDev(JNIEnv *env, jobject thiz) +{ +} + +jboolean powerUp(JNIEnv *env, jobject thiz, jfloat freq) +{ +} + +jboolean powerDown(JNIEnv *env, jobject thiz, jint type) +{ +} + +jboolean tune(JNIEnv *env, jobject thiz, jfloat freq) +{ +} + +jfloat seek(JNIEnv *env, jobject thiz, jfloat freq, jboolean isUp) //jboolean isUp; +{ +} + +jshortArray autoScan(JNIEnv *env, jobject thiz) +{ +} + +jshort readRds(JNIEnv *env, jobject thiz) +{ +} + +jbyteArray getPs(JNIEnv *env, jobject thiz) +{ +} + +jbyteArray getLrText(JNIEnv *env, jobject thiz) +{ +} + +jshort activeAf(JNIEnv *env, jobject thiz) +{ +} + +jshortArray getAFList(JNIEnv *env, jobject thiz) +{ +} + +jint setRds(JNIEnv *env, jobject thiz, jboolean rdson) +{ +} + +jboolean stopScan(JNIEnv *env, jobject thiz) +{ +} + +jint setMute(JNIEnv *env, jobject thiz, jboolean mute) +{ +} + +jint isRdsSupport(JNIEnv *env, jobject thiz) +{ +} + +jint switchAntenna(JNIEnv *env, jobject thiz, jint antenna) +{ +} + +static const char *classPathNameRx = "com/android/fmradio/FmNative"; + +static JNINativeMethod methodsRx[] = { + { "openDev", "()Z", (void*)openDev }, + { "closeDev", "()Z", (void*)closeDev }, + { "powerUp", "(F)Z", (void*)powerUp }, + { "powerDown", "(I)Z", (void*)powerDown }, + { "tune", "(F)Z", (void*)tune }, + { "seek", "(FZ)F", (void*)seek }, + { "autoScan", "()[S", (void*)autoScan }, + { "stopScan", "()Z", (void*)stopScan }, + { "setRds", "(Z)I", (void*)setRds }, + { "readRds", "()S", (void*)readRds }, + { "getPs", "()[B", (void*)getPs }, + { "getLrText", "()[B", (void*)getLrText }, + { "activeAf", "()S", (void*)activeAf }, + { "setMute", "(Z)I", (void*)setMute }, + { "isRdsSupport", "()I", (void*)isRdsSupport }, + { "switchAntenna", "(I)I", (void*)switchAntenna }, +}; + +/* + * Register several native methods for one class. + */ +static jint registerNativeMethods(JNIEnv* env, const char* className, + JNINativeMethod* gMethods, int numMethods) +{ + jclass clazz; + + clazz = env->FindClass(className); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); + } + if (clazz == NULL) { + ALOGE("Native registration unable to find class '%s'", className); + return JNI_FALSE; + } + if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) { + ALOGE("RegisterNatives failed for '%s'", className); + return JNI_FALSE; + } + + ALOGD("%s, success\n", __func__); + return JNI_TRUE; +} + +/* + * Register native methods for all classes we know about. + * + * returns JNI_TRUE on success. + */ +static jint registerNatives(JNIEnv* env) +{ + jint ret = JNI_FALSE; + + if (registerNativeMethods(env, classPathNameRx,methodsRx, + sizeof(methodsRx) / sizeof(methodsRx[0]))) { + ret = JNI_TRUE; + } + + ALOGD("%s, done\n", __func__); + return ret; +} + +// ---------------------------------------------------------------------------- + +/* + * This is called by the VM when the shared library is first loaded. + */ + +typedef union { + JNIEnv* env; + void* venv; +} UnionJNIEnvToVoid; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + jint result = -1; + JNIEnv* env = NULL; + + ALOGI("JNI_OnLoad"); + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + ALOGE("ERROR: GetEnv failed"); + goto fail; + } + env = uenv.env; + + if (registerNatives(env) != JNI_TRUE) { + ALOGE("ERROR: registerNatives failed"); + goto fail; + } + + result = JNI_VERSION_1_4; + +fail: + return result; +} -- 2.20.1