上一章介绍了直接调用Service来操作硬件的方法,如果我们再优化一下结构,通过一个Manager来调用这个Service的方法,可能会更好。这样Service就可以跑在后台,由于这时候service和manager是两个进程,所以只能通过IPC来进行通信。我们在上一篇看到
public final class LedService extends ILedService.Stub { }, ILedService.Stub就是
ILedService.aidl由aidl工具自动生成的类。
我们现在看看manager是如何实现的:
frameworks/base/core/java/mokoid/hardware/ILedService.aidl
package mokoid.hardware;
interface ILedService {
boolean setOn(int led);
boolean setOff(int led);
}
该aidl文件最后能被aidl工具自动生成ILedService.java文件,提供了remotable的LedService可用的接口setOn和setOff.
frameworks/base/core/java/mokoid/hardware/LedManager.java
public class LedManager {
private static final String TAG = "LedManager";
private ILedService mLedService;
public LedManager() {
mLedService = ILedService.Stub.asInterface(
ServiceManager.getService("led"));
if (mLedService != null) {
Log.i(TAG, "The LedManager object is ready.");
}
}
public boolean LedOn(int n) {
boolean result = false;
try {
result = mLedService.setOn(n);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in LedManager.LedOn:", e);
}
return result;
}
public boolean LedOff(int n) {
boolean result = false;
try {
result = mLedService.setOff(n);
} catch (RemoteException e) {
添加新评论4 条评论
2013-08-30 14:56
http://www.hzlitai.com.cn/product/accessories/product/Tablet-CZ/1859.html
2013-05-08 15:11
http://www.hzlitai.com.cn/news/1855.html
2013-03-29 11:35
立宇泰推出的车载一代(型号)、车载二代(型号)目前已经大批量使用在各大城市的驾培终端升级中,在实际使用场合考验下,工作稳定、可靠,受到用户的好评。
车载一代:ARM9处理器+WINCE5.0操作系统,480x272像素4.3寸液晶屏,电阻式触摸屏,支持GPS定位,2G/3G拨号,RFID(TypeA/B)卡的读写,指纹采集(上层实现算法),支持1路串口摄像头,内置2~4GTF存储卡,支持音频播放。
车载二代:ARM Cotex-A8处理器+Android2.3操作系统,800x480像素7寸液晶屏,电容式触摸屏,支持GPS定位,2G/3G拨号,RFID(TypeA/B)卡读写,接触式IC卡读写,指纹采集模块(已经实现算法),支持2路模拟摄像头(支持拍照、录像),内置8GTF存储卡,提供外置TF卡接口(最大),支持录音、放音,具备陀螺仪和加速度传感器。
通过与软件方案商、集成商的合作,实现了全新的驾培管理软、硬件体系,促进各大城市的驾培管理变得更加成熟、规范、公平、公正。
http://www.hzlitai.com.cn/product/Tablet-PC/1840.html
2012-11-12 10:04