In frameworks/base/services/JNI
Add:
Com_android_server_helloservice.cpp
The content is as follows:
/*
* Copyright (c) 2009 the android open source project
*
* Licensed under the Apache license, version 2.0 (the "License ");
* You may not use this file before t in compliance with the license.
* You may obtain a copy of the license
*
* 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.
*/
# Define log_tag "helloservice"
# Include "JNI. H"
# Include "jnihelp. H"
# Include "android_runtime/androidruntime. H"
# Include <utils/Misc. h>
# Include <utils/log. h>
# Include <Hardware/hardware. h>
# Include <Hardware/Hello. h>
# Include <stdio. h>
Namespace android
{
Struct hello_device_t * hello_device = NULL;
Static void hello_setval (jnienv * EVN, jobject clazz, jint value)
{
Int val = value;
Alogi ("Hello JNI: Set Value % d to device.", Val );
If (! Hello_device ){
Alogi ("Hello JNI: device is not open .");
Return;
}
Hello_device-> set_val (hello_device, Val );
}
Static jint hello_getval (jnienv * EVN, jobject clazz)
{
Int val = 0;
If (! Hello_device ){
Alogi ("Hello JNI: device is not open .");
Return val;
}
Hello_device-> get_val (hello_device, & Val );
Alogi ("Hello JNI: Get value % d to device.", Val );
Return val;
}
/* Open the interface of the hardware module defined in the hardware abstraction layer to open the hardware device */
Static inline int hello_device_open (const hw_module_t * module, struct hello_device_t ** device ){
Return Module-> methods-> open (module, hello_hardware_module_id, (struct hw_device_t **) device );
}
/* Use the hardware module ID to load the specified Hardware Abstraction Layer module and open the hardware */
Static jboolean hello_init (jnienv * ENV, jclass clazz ){
Hello_module_t * module;
Alogi ("Hello JNI: initializing ......");
If (hw_get_module (hello_hardware_module_id, (const struct hw_module_t **) & module) = 0 ){
Alogi ("Hello JNI: Hello stub found .");
If (hello_device_open (& (module-> common), & hello_device) = 0 ){
Alogi ("Hello JNI: Hello device is open .");
Return 0;
}
Aloge ("Hello JNI: failed to open Hello device .");
Return-1;
}
Aloge ("Hello JNI: failed to get Hello stub module .");
Return-1;
}
Static 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 (ENV, "com/Android/Server/helloservice ",
Method_table, nelem (method_table ));
}
};
Then in Android. mk:
Diff -- git a/services/JNI/Android. mk B/services/JNI/Android. mk
Index 2c72f32 .. 3c61a33 100755
--- A/services/JNI/Android. mk
++ B/services/JNI/Android. mk
@-18,6 + 18,7 @ local_src_files: = \
Com_android_server_connectivity_vpn.cpp \
Com_android_server_displaymanagerserviceaw.cpp \
Com_android_server_bid.cpp \
+ Com_android_server_helloservice.cpp \
Onload. cpp
Local_c_includes + = \
Then onload. cpp:
Index a4f99ca .. 53e0de6 100755
--- A/services/JNI/onload. cpp
++ B/services/JNI/onload. cpp
@-36,6 + 36,7 @ int register_android_server_location_gpslocationprovider (jnienv * env );
Int register_android_server_connectivity_vpn (jnienv * env );
Int register_android_server_displaymanagerserviceaw (jnienv * env );
Int register_android_server_bid (jnienv * env );
+ Int register_android_server_helloservice (jnienv * env );
};
Using namespace android;
@-67,6 + 68,7 @ extern "C" jint jni_onload (JavaVM * Vm, void * Reserved)
Register_android_server_connectivity_vpn (ENV );
Register_android_server_displaymanagerserviceaw (ENV );
Register_android_server_bid (ENV );
+ Register_android_server_helloservice (ENV );
Return jni_version_1_4;
}
Then:
Add helloservice. Java to frameworks/base/services/Java/COM/Android/Server:
Package com. Android. server;
Import Android. content. context;
Import Android. OS. ihelloservice;
Import Android. util. slog;
Public class helloservice extends ihelloservice. Stub {
Private Static final string tag = "helloservice ";
Helloservice (){
Init_native ();
}
Public void setval (INT Val ){
Setval_native (VAL );
}
Public int getval (){
Return getval_native ();
}
Private Static native Boolean init_native ();
Private Static native void setval_native (INT Val );
Private Static native int getval_native ();
};
Then modify systemserver. Java:
Index a743c44 .. 1dded42 100755
--- A/services/Java/COM/Android/Server/systemserver. Java
++ B/services/Java/COM/Android/Server/systemserver. Java
@-734,6 + 734,14 @ Class serverthread extends thread {
} Catch (throwable e ){
Reportwtf ("Starting diskstats service", e );
}
+
+ Try {
+ Slog. I (TAG, "helloservice ");
+ Servicemanager. addservice ("hello", new helloservice ());
+} Catch (throwable e ){
+ Slog. E (TAG, "Failure starting Hello service", e );
+}
+
Try {
// Need to add this service even if samplingprofilerintegration. isenabled ()
Then, add ihelloservice in frameworks/base/CORE/Java/Android/OS:
Package Android. OS;
Interface ihelloservice {
Void setval (INT Val );
Int getval ();
}
Then, modify Android. mk in frameworks/base:
Diff -- git a/Android. mk B/Android. mk
Index bef18d1 .. cad9ad5 100755
--- A/Android. mk
++ B/Android. mk
@-145, 6 + 145, 7 @ local_src_files + = \
Core/Java/Android/OS/iupdatelock. aidl \
Core/Java/Android/OS/iusermanager. aidl \
Core/Java/Android/OS/ivibratorservice. aidl \
+ Core/Java/Android/OS/ihelloservice. aidl \
Core/Java/Android/service/dreams/idreammanager. aidl \
Core/Java/Android/service/dreams/idreamservice. aidl \
Core/Java/Android/service/wallpaper/iwallpaperconnection. aidl \
In fact, Lao Luo must modify API/current.txt after adding a class. Of course, you can also update it. People who have worked on frameworks usually manually Add the following items:
Diff -- git a/API/current.txt B/API/current.txt
Index 7e99a58.. 9c820ae 100755
--- A/API/current.txt
++ B/API/current.txt
@-16372,6 + 16372,18 @ package Android. OS {
Method public abstract void binderdied ();
}
+ Public abstract interface ihelloservice implements Android. OS. iinterface {
+ Method public abstract int getval () throws Android. OS. RemoteException;
+ Method public abstract void setval (INT) throws Android. OS. RemoteException;
+}
+
+ Public static abstract class ihelloservice. Stub extends Android. OS. Binder implements Android. OS. ihelloservice {
+ Ctor public ihelloservice. Stub ();
+ Method public Android. OS. ibinder asbinder ();
+ Method public static Android. OS. ihelloservice asinterface (Android. OS. ibinder );
+ Method public Boolean ontransact (INT, Android. OS. parcel, Android. OS. parcel, INT) throws Android. OS. RemoteException;
+}
+
Public abstract interface iinterface {
Method public abstract Android. OS. ibinder asbinder ();
}
In the end, please copy "Hello. H" in "/device/softwinner/common/hardware/Hello" to "/hardware/libhardware/include/hardware.