Android 从硬件到应用程序:一步一步爬上去 5 -- 在Frameworks蒂姆层硬件服务
Android Frameworks层提供硬件服务,Android系统APP能够调用这些硬件服务,而硬件则完全控制。实现应有的功能。上一页下一页。为了这一个frameworks高层的应用java接口硬件服务。cd至frameworks/base/core/java/android/os文件夹,加入 IGpioService.aidl:
package android.os; interface IGpioService { void setVal(int val); int getVal(); }我们通过setVal去设置LED的亮灭。getVal一直是省略的
打开frameworks/base下的Android.mk,改动LOCAL_SRC_FILES,添加:
core/java/android/os/IGpioService.aidl \编译IGpioService.aidl接口:
make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x
生成:
Install: out/target/product/am335xevm_sk/system/framework/framework.jar
成功后cd到frameworks/base/services/java/com/android/server文件夹,加入GpioService.java文件:package com.android.server; import android.content.Context; import android.os.IGpioService; import android.util.Slog; public class GpioService extends IGpioService.Stub { private static final String TAG = "GpioService"; GpioService() { 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(); };改动当前文件夹下的SystemServer.java文件,在ServerThread::run中添加GpioService:
try { Slog.i(TAG, "Recognition Service"); recognition = new RecognitionManagerService(context); } catch (Throwable e) { reportWtf("starting Recognition Service", e); } try { Slog.i(TAG, "DiskStats Service"); ServiceManager.addService("diskstats", new DiskStatsService(context)); } catch (Throwable e) { reportWtf("starting DiskStats Service", e); } try { Slog.i(TAG, "Gpio Service"); ServiceManager.addService("gpio", new GpioService()); } catch (Throwable e) { Slog.e(TAG, "Failure starting Gpio Service", e); }
编译GpioService:
make TARGET_PRODUCT=am335xevm_sk -j8 OMAPES=4.x
生成:
Install: out/target/product/am335xevm_sk/system/framework/services.jarFrameworks层已经包括我们写的硬件服务,这些都可以应用java接口访问硬件和服务。