在Ubuntu为Android硬件抽象层(HAL…
来源:互联网 发布:cad看图软件 for mac 编辑:程序博客网 时间:2024/06/02 01:33
在上两篇文章中,我们介绍了如何为Android系统的硬件编写驱动程序,包括如何在Linux内核空间实现内核驱动程序和在用户空间实现硬件抽象层接口。实现这两者的目的是为了向更上一层提供硬件访问接口,即为Android的ApplicationFrameworks层提供硬件服务。我们知道,Android系统的应用程序是用Java语言编写的,而硬件驱动程序是用C语言来实现的,那么,Java接口如何去访问C接口呢?众所周知,Java提供了JNI方法调用,同样,在Android系统中,Java应用程序通过JNI来调用硬件抽象层接口。在这一篇文章中,我们将介绍如何为Android硬件抽象层接口编写JNI方法,以便使得上层的Java应用程序能够使用下层提供的硬件服务。
- #define
LOG_TAG "HelloService" - #include
"jni.h" - #include
"JNIHelp.h" - #include
"android_runtime/AndroidRuntime.h" - #include
- #include
- #include
- #include
- #include
- namespace
android - {
-
-
struct hello_device_t* hello_device = NULL; -
-
static void hello_setVal(JNIEnv* env, jobject clazz, jint value) { -
int val = value; -
LOGI("Hello JNI: ,set value %d to device." val); -
if(!hello_device) { -
LOGI("Hello JNI: );device is not open." -
return; -
} -
-
hello_device->set_val(hello_device, val); -
} -
-
static jint hello_getVal(JNIEnv* env, jobject clazz) { -
int val = 0; -
if(!hello_device) { -
LOGI("Hello JNI: );device is not open." -
return val; -
} -
hello_device->get_val(hello_device, &val); -
-
LOGI("Hello JNI: ,get value %d from device." val); -
-
return val; -
} -
-
static inline int hello_device_open( consthw_module_t* structmodule, hello_device_t** device) { -
return module->methods->open(module, structHELLO_HARDWARE_MODULE_ID, ( hw_device_t**)device); -
} -
-
static jboolean hello_init(JNIEnv* env, jclass clazz) { -
hello_module_t* module; -
-
LOGI("Hello JNI: );initializing......" -
if(hw_get_module(HELLO_HARDWARE_MODULE_ID, ( conststruct hw_module_t**)&module) == 0) { -
LOGI("Hello JNI: );hello Stub found." -
if(hello_device_open(&(module->common), &hello_device) == 0) { -
LOGI("Hello JNI: );hello device is open." -
return 0; -
} -
LOGE("Hello JNI: );failed to open hello device." -
return -1; -
} -
LOGE("Hello JNI: );failed to get hello stub module." -
return -1; -
} -
-
static const JNINativeMethod method_table[] = { -
{"init_native", "()Z", ( void*)hello_init}, -
{"setVal_native", "(I)V", ( void*)hello_setVal}, -
{"getVal_native", "()I", ( void*)hello_getVal}, -
}; -
-
int register_android_server_HelloService(JNIEnv *env) { -
return jniRegisterNativeMethods "com/android/server/HelloService",(env, method_table, NELEM(method_table)); -
} - };
- 在Ubuntu为Android硬件抽象层(HAL…
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序 .
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- 在Ubuntu上为Android增加硬件抽象层(HAL)模块访问Linux内核驱动程序
- skyeye安装
- 静态类static class(转载)
- 将博客搬至CSDN
- 认识理解Java中native方法(转载)
- JNi调用过程(转载)
- 在Ubuntu为Android硬件抽象层(HAL…
- Android高手进阶教程(二十五)之---…
- Android硬件抽象层(HAL)概要介绍…
- listcontrol控件不显示列名
- C. Inna and Huge Candy Matrix(cf)
- onkeyup同时执行两个方法怎么写
- (libgdx小结)常见UI的使用
- 齐次坐标的理解
- CentOS 6.5 配置VPN教程