正文

Android HAL 开发 (5)2012-09-17 11:53:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/liyutai/53802.html

分享到:

上一章介绍了直接调用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) {

             Log.e(TAG, "RemoteException in LedManager.LedOff:", e);
         }
         return result;
     }
 }
阅读更多下文请点击:http://www.hzlitai.com.cn/article/ARM11/SYSTEM/Android_HAL_kaifa5.html

阅读(1987) | 评论(4)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

评论人: 发布时间: 2013-06-14 11:02:00
学习!
评论人: 发布时间: 2013-05-15 11:50:00
祝贺立宇泰视频指纹车载驾培终端产品,一次性通过“国家电子计算机外部设备质量监督检验中心”权威部门的检测,测试项目包括:性能检验、环境适应性检验、可靠性检验、电磁兼容性检验、安全检验。
http://www.hzlitai.com.cn/news/1855.html
评论人: 发布时间: 2013-02-28 16:59:00
学习了
评论人: 发布时间: 2012-12-04 11:16:00
一起分享
您需要登录后才能评论,请 登录 或者 注册