Android aidl在Framework的使用
生活随笔
收集整理的這篇文章主要介紹了
Android aidl在Framework的使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
為何要做這個(gè)
我要在framework的PhoneWindowManager.java里面調(diào)用LightService.java里面的函數(shù),用來做燈光的提示之類的,為何我要在PhoneWindowManager.java里面加這個(gè)呢,這里就不做討論了,但是直接調(diào)用哪些接口是不行的,所以就引進(jìn)了ipc通信,所以就有了我這篇博客,這其中有個(gè)安卓的大神朋友幫我解惑了很多問題
Aidl 和ipc通信之類的我就不講了,我永遠(yuǎn)都是實(shí)踐家,而且我的專長(zhǎng)是linux驅(qū)動(dòng),這個(gè)東西也是現(xiàn)在慢慢負(fù)責(zé)公司產(chǎn)品framework 需要做的才去學(xué)習(xí)的
要做的文件修改如下:
補(bǔ)丁鏈接 說明一下是Android 4.4的
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in working directory)modified: frameworks/base/Android.mkmodified: frameworks/base/core/java/android/app/ContextImpl.javamodified: frameworks/base/core/java/android/content/Context.javamodified: frameworks/base/core/java/android/content/ContextWrapper.javamodified: frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.javamodified: frameworks/base/services/java/com/android/server/SystemServer.javamodified: frameworks/base/test-runner/src/android/test/mock/MockContext.javamodified: frameworks/base/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.javamodified: kernel/mediatek/custom/outmodified: mediatek/misc/ota_scatter.txtUntracked files:(use "git add <file>..." to include in what will be committed)bootable/bootloader/lk/outframeworks/base/core/java/android/content/pm/ILightManager.aidlframeworks/base/core/java/android/content/pm/LightManager.javaframeworks/base/services/java/com/android/server/LightManagerService.java第一步:加入aidl文件
frameworks/base/core/java/android/content/pm/ILightManager.aidlframeworks/base/core/java/android/content/pm/LightManager.java //在app里面這個(gè)東西是自動(dòng)生成的,但是這個(gè)這個(gè)是手動(dòng)寫出來的第二步:加入service相關(guān)的文件還有
frameworks/base/services/java/com/android/server/LightManagerService.java第三步:加入注冊(cè)需要的一些代碼
modified: frameworks/base/Android.mkmodified: frameworks/base/core/java/android/app/ContextImpl.javamodified: frameworks/base/core/java/android/content/Context.javamodified: frameworks/base/core/java/android/content/ContextWrapper.javamodified: frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.javamodified: frameworks/base/services/java/com/android/server/SystemServer.javamodified: frameworks/base/test-runner/src/android/test/mock/MockContext.javamodified: frameworks/base/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java第四步:在PhoneWindowManager.java加入調(diào)用代碼
--- a/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -37,6 +37,7 @@ import android.content.IntentFilter;import android.content.ServiceConnection;import android.content.pm.ApplicationInfo;import android.content.pm.ActivityInfo; +import android.content.pm.LightManager;import android.content.pm.PackageManager;import android.content.pm.ResolveInfo;import android.content.res.CompatibilityInfo; @@ -252,6 +253,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {IWindowManager mWindowManager;WindowManagerFuncs mWindowManagerFuncs;PowerManager mPowerManager; + //AlarmManagerService mAlarmManagerService;//weiqifaIStatusBarService mStatusBarService;boolean mPreloadedRecentApps;final Object mServiceAquireLock = new Object(); @@ -1019,8 +1021,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);- -mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"PhoneWindowManager.mBroadcastWakeLock");mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); @@ -2256,41 +2256,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {}if(keyCode == KeyEvent.KEYCODE_HDYRODENT){ - if(down) - { + if(down){ + LightManager a = mContext.getLightManager(); + a.addStudent("12312345678"); + Log.d(TAG,"--------------------------->mLightManager is null ");Log.d(TAG,"key mode m is pressed!!!!");Intent intent = new Intent("com.key.android.KEY_M_ACTION_DOWM");mContext.sendBroadcast(intent); - } - else - { + }else{Log.d(TAG,"key mode m is released!!!!");Intent intent = new Intent("com.key.android.KEY_M_ACTION_UP");mContext.sendBroadcast(intent);}}第五步:查看日志
D/ADB_SERVICES( 222): read_data=8892 W/LightManagerService( 597): --------------->testLightManagerService<---------------12312345678 D/ADB_SERVICES( 222): max_read_time=0.000265 max_send_time=0.001093 W/LightManagerService( 597): <--------------->testLightManagerService<--------------->12312345678 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Android aidl在Framework的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 史上最详细的Hadoop环境搭建
- 下一篇: I2C和SPI注定要打一架