Android硬件訪問服務框架初探

 new SystemServer().run();
 
  System.loadLibrary("android_servers");
  
OnLoad.cpp
報警的:
 register_android_server_AlarmManagerService(env);
 
 return jniRegisterNativeMethods(env, "com/android/server/VibratorService",
            method_table, NELEM(method_table))
            
            public class VibratorService extends IVibratorService.Stub
            
            電源:
               register_android_server_PowerManagerService(env);
               
               int register_android_server_PowerManagerService(JNIEnv* env) {
               
               public final class PowerManagerService extends SystemService
               
               
               private void startOtherServices()

 

./work/android-5.0.2/frameworks/base/core/java/android/os/IVibratorService.aidl


./core/tests/overlaytests/OverlayAppSecond/Android.mk
./core/tests/overlaytests/Android.mk
./core/tests/systemproperties/Android.mk
./core/tests/ConnectivityManagerTest/Android.mk
./Android.mk
./sax/tests/saxtests/Android.mk
root@android-virtual-machine:/work/android-5.0.2/frameworks/base# vi Android.mk


mmm: command not found
root@android-virtual-machine:/work/android-5.0.2# . build/envsetup.sh


make: *** No rule to make target `out/target/common/obj/APPS/framework-res_intermediates/src/R.stamp', needed by `out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar'.  Stop.
make: Leaving directory `/work/android-5.0.2'


out/target/common/obj/JAVA_LIBRARIES/framework_intermediates


mmm <android source code path>/frameworks/base/core/res


Install: out/target/product/generic/system/framework/framework-res.apk
make: Leaving directory `/work/android-5.0.2'


root@android-virtual-machine:/work/android-5.0.2/frameworks/base# vi Android.mk
root@android-virtual-machine:/work/android-5.0.2/frameworks/base# mmm .

make: *** No rule to make target `out/host/linux-x86/bin/dex2oatd', needed by `out/target/product/generic/dex_bootjars/system/framework/arm/boot.art'.  Stop.
make: Leaving directory `/work/android-5.0.2'
 

frameworks/base/services/core/java/com/android/server/LedService.java:6: error: class, interface, or enum expected
public LedService extends ILedService.Stub {
       ^
frameworks/base/services/core/java/com/android/server/LedService.java:7: error: class, interface, or enum expected
     private static final String TAG = "LedService";
                          ^
frameworks/base/services/core/java/com/android/server/LedService.java:10: error: class, interface, or enum expected
     public int ledCtrl(int which, int status) throws android.os.RemoteException
            ^
frameworks/base/services/core/java/com/android/server/LedService.java:13: error: class, interface, or enum expected
    }
    ^
frameworks/base/services/core/java/com/android/server/LedService.java:16: error: class, interface, or enum expected
     public LedService() {
            ^
frameworks/base/services/core/java/com/android/server/LedService.java:18: error: class, interface, or enum expected
         }
         ^
frameworks/base/services/core/java/com/android/server/LedService.java:20: error: class, interface, or enum expected
    public static native int native_ledOpen();
                         ^
frameworks/base/services/core/java/com/android/server/LedService.java:21: error: class, interface, or enum expected
    public static native void native_ledClose();
                         ^
frameworks/base/services/core/java/com/android/server/LedService.java:23: error: class, interface, or enum expected
    public static native int native_ledCtrl(int which,int status);
                         ^
frameworks/base/services/core/java/com/android/server/LedService.java:24: error: class, interface, or enum expected
}


./work/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/ILedService.java
./work/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/ILedService.P
./work/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService.class
./work/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService$Stub$Proxy.class
./work/android-5.0.2/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService$Stub.class
./work/android-5.0.2/frameworks/base/core/java/android/os/ILedService.aidl
root@android-virtual-machine:/# 
root@android-virtual-machine:/# 
root@android-virtual-machine:/# 
root@android-virtual-machine:/# find ./ -name 'LedService*'
./work/android-5.0.2/frameworks/base/services/core/java/com/android/server/LedService.java

frameworks/base/services/core/java/com/android/server/LedService.java:4: error: package ILedService does not exist
public class LedService extends ILedService.Stub {
                                           ^


./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/ILedService.java
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/ILedService.P
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService.class
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService$Stub$Proxy.class
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/ILedService$Stub.class
./frameworks/base/core/java/android/os/ILedService.aidl
root@android-virtual-machine:/work/android-5.0.2# find ./ -name 'IVibratorService*'
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/IVibratorService.java
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/IVibratorService.P
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/android/os/IVibratorService$Stub.class
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/android/os/IVibratorService$Stub$Proxy.class
./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes/android/os/IVibratorService.class
./frameworks/base/core/java/android/os/IVibratorService.aidl
root@android-virtual-machine:/work/android-5.0.2# 


frameworks/base/services/core/jni/com_android_server_LedService.cpp:18:30: fatal error: hardware/led_hal.h: No such file or directory
 #include <hardware/led_hal.h>
                              ^
調試到如下圖:

 

 

(1) AIDL
1. 把 ILedService.aidl 放入 frameworks/base/core/java/android/os
2. 修改 frameworks/base/Android.mk  添加一行
         core/java/android/os/IVibratorService.aidl \
+        core/java/android/os/ILedService.aidl \

3. mmm frameworks/base

4. 它會生成: ./out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/ILedService.java

(2) Server : LedService.java 
             SystemServer.java

把新文件上傳到服務器, 所在目錄:
frameworks/base/services/java/com/android/server/SystemServer.java
frameworks/base/services/core/java/com/android/server/LedService.java

不需要修改 frameworks/base/services/core/Android.mk
它的內容裏已經把該目錄下所有JAVA文件自動包含進去了:
LOCAL_SRC_FILES += \
    $(call all-java-files-under,java)



(3) JNI : com_android_server_LedService.cpp
          onload.cpp

把新文件上傳到服務器, 所在目錄:
frameworks/base/services/core/jni/onload.cpp
frameworks/base/services/core/jni/com_android_server_LedService.cpp

修改 frameworks/base/services/core/jni/Android.mk :
  $(LOCAL_REL_DIR)/com_android_server_VibratorService.cpp \
+ $(LOCAL_REL_DIR)/com_android_server_LedService.cpp \


編譯:
$ mmm frameworks/base/services
$ make snod
$ ./gen-img.sh



frameworks/base/services/core/jni/com_android_server_LedService.cpp: In function 'int android::register_android_server_LedService(JNIEnv*)':
frameworks/base/services/core/jni/com_android_server_LedService.cpp:77:13: error: 'methods' was not declared in this scope
             methods, NELEM(methods));
             ^
frameworks/base/services/core/jni/com_android_server_LedService.cpp:79:3: error: control reaches end of non-void function [-Werror=return-type]
   }


make snod: ignoring dependencies
Target system fs image: out/target/product/tiny4412/system.img
Running:  mkuserimg.sh -s out/target/product/tiny4412/system out/target/product/tiny4412/system.img ext4 system 629145600 out/target/product/tiny4412/root/file_contexts
make_ext4fs -s -T -1 -S out/target/product/tiny4412/root/file_contexts -l 629145600 -a system out/target/product/tiny4412/system.img out/target/product/tiny4412/system
Creating filesystem with parameters:
    Size: 629145600
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7680
    Inode size: 256
    Journal blocks: 2400
    Label: 
    Blocks: 153600
    Block groups: 5
    Reserved block group size: 39
Created filesystem with 1901/38400 inodes and 136868/153600 blocks
out/target/product/tiny4412/system.img maxsize=642318336 blocksize=4224 total=552445236 reserve=6488064

#### make completed successfully (12 seconds) ####

root@android-virtual-machine:/work/android-5.0.2# ./gen-img.sh
Creating filesystem with parameters:
    Size: 629145600
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7680
    Inode size: 256
    Journal blocks: 2400
    Label: 
    Blocks: 153600
    Block groups: 5
    Reserved block group size: 39
Created filesystem with 1931/38400 inodes and 136979/153600 blocks
Creating filesystem with parameters:
    Size: 2149580800
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7728
    Inode size: 256
    Journal blocks: 8200
    Label: 
    Blocks: 524800
    Block groups: 17
    Reserved block group size: 135
Created filesystem with 18/131376 inodes and 17347/524800 blocks
Creating filesystem with parameters:
    Size: 4299161600
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7952
    Inode size: 256
    Journal blocks: 16400
    Label: 
    Blocks: 1049600
    Block groups: 33
    Reserved block group size: 263
Created filesystem with 18/262416 inodes and 35067/1049600 blocks
Creating filesystem with parameters:
    Size: 10485760000
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8112
    Inode size: 256
    Journal blocks: 32768
    Label: 
    Blocks: 2560000
    Block groups: 79
    Reserved block group size: 631
Created filesystem with 18/640848 inodes and 78756/2560000 blocks
Image Name:   ramdisk
Created:      Sun Jun 21 22:25:06 2020
Image Type:   ARM Linux RAMDisk Image (uncompressed)
Data Size:    720594 Bytes = 703.71 kB = 0.69 MB
Load Address: 40800000
Entry Point:  40800000
root@android-virtual-machine:/work/android-5.0.2# 
燒寫zImage如下圖:

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章