为何要做这个
我要在framework的PhoneWindowManager.java里面调用LightService.java里面的函数,用来做灯光的提示之类的,为何我要在PhoneWindowManager.java里面加这个呢,这里就不做讨论了,但是直接调用哪些接口是不行的,所以就引进了ipc通信,所以就有了我这篇博客,这其中有个安卓的大神朋友帮我解惑了很多问题
Aidl 和ipc通信之类的我就不讲了,我永远都是实践家,而且我的专长是linux驱动,这个东西也是现在慢慢负责公司产品framework 需要做的才去学习的
要做的文件修改如下:
补丁链接 说明一下是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里面这个东西是自动生成的,但是这个这个是手动写出来的
第二步:加入service相关的文件还有
frameworks/base/services/java/com/android/server/LightManagerService.java
第三步:加入注册需要的一些代码
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加入调用代码
--- 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