呼吸灯仅提示15分钟

来源:互联网 发布:redhat怎么安装mysql 编辑:程序博客网 时间:2024/04/28 13:05
呼吸灯仅提示15分钟
这里只是大致记录一下framework 层的大致修改方法.
每次NotificationManagerService 在处理通知的时候会判断该通知是否需要开启led灯,如果需要开启的话,首先判断设置里面关于这个功能的开关是否开启,如果是开启的话,如果这个通知和同一个通知不是同一个id,就设置一个15分钟的闹钟来在关闭这个led灯.
其中关闭是在闹钟时间到了之后,发出指定广播来处理的,所以我们在创建NotificationManagerService的时候需要注册一个广播监听器.


NotificationManagerService.java
  1. @Override
  2. public void onStart() {
  3. ...
  4. //zhangle add for notification light start 20150513
  5. /* Uri uri = android.provider.Settings.System.getUriFor(DISPLAY_LIGHT_TURN_QUARTER);
  6. getContext().getContentResolver().registerContentObserver(uri, false, myNotificationLightContentObserver);*/
  7. IntentFilter myFilter = new IntentFilter();
  8. myFilter.addAction(DOOV_LED_TURN_OFF_ACTION);
  9. getContext().registerReceiverAsUser(new MyBroadCastReceiver(),UserHandle.ALL, myFilter,null,
  10. null);
  11. Log.d(TAG,"register DOOV_LED_TURN_OFF_ACTION");
  12. //zhangle add for notification light end 20150513
  13. }
  14. // lock on mNotificationList
  15. void updateLightsLocked()
  16. {
  17. Log.d(TAG,"updateLightsLocked mLights size=" + mLights.size());
  18. // handle notification lights
  19. NotificationRecord ledNotification = null;
  20. while (ledNotification == null && !mLights.isEmpty()) {
  21. final String owner = mLights.get(mLights.size() - 1);
  22. Log.d(TAG,"updateLightsLocked owner=" + owner);
  23. ledNotification = mNotificationsByKey.get(owner);
  24. if (ledNotification == null) {
  25. Slog.wtfStack(TAG, "LED Notification does not exist: " + owner);
  26. mLights.remove(owner);
  27. }
  28. }
  29. //zhangle add for notification light start 20150513
  30. int value = Settings.System.getInt(getContext().getContentResolver(), DISPLAY_LIGHT_TURN_QUARTER, 0);
  31. Log.d(TAG,"updateLightsLocked value=" +value + " ledNotification=" + ledNotification+ " mNotificationPulseEnabled=" + mNotificationPulseEnabled);
  32. //zhangle add for notification light end 20150513
  33. // handle notification lights
  34. // Don't flash while we are in a call or screen is on
  35. //if (mLedNotification == null || mInCall || mScreenOn) {
  36. /// M: [ALPS01244800] Flash Notification LED regardless of screen state
  37. if (ledNotification == null || mInCall /*|| mScreenOn*/ || mDmLock || mPplLock) {
  38. mNotificationLight.turnOff();
  39. mStatusBar.notificationLightOff();
  40. } else {
  41. final Notification ledno = ledNotification.sbn.getNotification();
  42. int ledARGB = ledno.ledARGB;
  43. int ledOnMS = ledno.ledOnMS;
  44. int ledOffMS = ledno.ledOffMS;
  45. if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
  46. ledARGB = mDefaultNotificationColor;
  47. ledOnMS = mDefaultNotificationLedOn;
  48. ledOffMS = mDefaultNotificationLedOff;
  49. }
  50. if (mNotificationPulseEnabled) {
  51. // pulse repeatedly
  52. /// M: add log for lights debug @{
  53. if (DBG) {
  54. Log.d(TAG, "notification setFlashing ledOnMS = " + ledOnMS + " ledOffMS = " + ledOffMS);
  55. }
  56. /// M: add log for lights debug @{
  57. mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED,
  58. ledOnMS, ledOffMS);
  59. //zhangle add for notification light start 20150513
  60. StatusBarNotification sbn = ledNotification.getSbn();
  61. int notification_id = -1;
  62. if(null != sbn){
  63. notification_id = sbn.getId();
  64. Log.d(TAG, "notification notification_id =" + notification_id + " mNotification_id=" + mNotification_id);
  65. }
  66. if(value >0 && null != sbn && mNotification_id != sbn.getId() ){//测试时发现qq 会重复发同一个通知.
  67. turnOffLightLater();
  68. mNotification_id = notification_id;
  69. }
  70. //zhangle add for notification light end 20150513
  71. }
  72. // let SystemUI make an independent decision
  73. mStatusBar.notificationLightPulse(ledARGB, ledOnMS, ledOffMS);
  74. }
  75. }
  76. //zhangle add for notification light start 20150513
  77. private final int delaySeconds = 15*60;
  78. private final int delaySeconds_test = 20;
  79. private int mNotification_id = -1;
  80. private AlarmManager am = null;
  81. private final static String DOOV_LED_TURN_OFF_ACTION = "android.alarm.doov.led.action";
  82. public void turnOffLightLater(){
  83. Log.d(TAG,"turnOffLightLater " );
  84. setAlarm();
  85. }
  86. class MyBroadCastReceiver extends BroadcastReceiver {
  87. @Override
  88. public void onReceive(Context context, Intent intent) {
  89. int value = getValue();
  90. Log.d(TAG, "intent.action=" + intent.getAction() + " value=" + value);
  91. if(value >0){
  92. mNotificationLight.turnOff();
  93. mStatusBar.notificationLightOff();
  94. if(null != mLights){
  95. Log.d(TAG, "onReceive mLights=" + mLights.size());
  96. mLights.clear();
  97. }
  98. }
  99. }
  100. }
  101. public Calendar getTimeInSeconds(int amount){
  102. Calendar calendar = Calendar.getInstance();
  103. calendar.setTimeInMillis(System.currentTimeMillis());
  104. calendar.add(Calendar.SECOND, amount);
  105. Log.d(TAG,"getTimeInSeconds" +calendar.getTime());
  106. return calendar;
  107. }
  108. public void setAlarm() {
  109. if(am == null){
  110. am = (AlarmManager) this.getContext().getSystemService(Context.ALARM_SERVICE);
  111. }
  112. Intent i = new Intent(DOOV_LED_TURN_OFF_ACTION);
  113. PendingIntent sender = PendingIntent.getBroadcast(this.getContext(), 0, i,PendingIntent.FLAG_CANCEL_CURRENT);
  114. am.set(AlarmManager.RTC_WAKEUP, getTimeInSeconds(delaySeconds).getTimeInMillis(), sender);
  115. Log.d(TAG,"setAlarm");
  116. }
  117. public int getValue() {
  118. return android.provider.Settings.System.getInt(getContext().getContentResolver(), DISPLAY_LIGHT_TURN_QUARTER, 0);
  119. }
  120. //zhangle add for notification light end 20150513
0 0
原创粉丝点击