灭屏状态下,接收新信息,屏幕会半亮显示通知流程

1,应用构造notification后,传给NotificationManager,而后进入NotificationManagerService处理。

NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

nm.notify(NOTIFICATION_ID, notification)

frameworks\base\core\java\android\app\NotificationManager.java

public void notify(int id, Notification notification)
{
notify(null, id, notification);
}
public void notify(String tag, int id, Notification notification)
{
……      Notification stripped = notification.clone();
Builder.stripForDelivery(stripped);
try {
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
stripped, idOut, UserHandle.myUserId());
if (id != idOut[0]) {
Log.w(TAG, "notify: id corrupted: sent " + id + ", got back " + idOut[0]);
}
} catch (RemoteException e) {
}
}

frameworks\base\services\core\java\com\android\server\notification\NotificationManagerService.java

public void enqueueNotificationWithTag(String pkg, String opPkg, String tag, int id,
Notification notification, int[] idOut, int userId) throws RemoteException {
enqueueNotificationInternal(pkg, opPkg, Binder.getCallingUid(),
Binder.getCallingPid(), tag, id, notification, idOut, userId);
}

同一个包名的通知超过50条不会继续处理。


if (count >= MAX_PACKAGE_NOTIFICATIONS) {
Slog.e(TAG, "Package has already posted " + count
+ " notifications. Not showing more. package=" + pkg);
return;
}

private void buzzBeepBlinkLocked(NotificationRecord record) {
……
……
// light
// release the light
boolean wasShowLights = mLights.remove(record.getKey());
if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && aboveThreshold) {
mLights.add(record.getKey());
updateLightsLocked();
if (mUseAttentionLight) {
mAttentionLight.pulse();
}
blink = true;
} else if (wasShowLights) {
updateLightsLocked();
}
if (buzz || beep || blink) {
EventLogTags.writeNotificationAlert(record.getKey(),
buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0);
mHandler.post(mBuzzBeepBlinked);
} }

屏幕半亮闪烁需要判断 (notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0

所以在应用构建notification时可以通过给flag赋值来控制是否要屏幕半亮闪烁。

先读取设置数据库中的NOTIFICATION_LIGHT_PULSE来判断是否闪烁,如果mNotificationPulseEnabled为true,则先闪烁一次(Light.LIGHT_FLASH_TIMED =1)。

Settings.System.getInt(resolver, Settings.System.NOTIFICATION_LIGHT_PULSE, 0)
if (mNotificationPulseEnabled) {
// pulse repeatedly
mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED,  //Light.LIGHT_FLASH_TIMED =1
ledOnMS, ledOffMS);
}
// let SystemUI make an independent decision //进入SystemUI处理
mStatusBar.notificationLightPulse(ledARGB, ledOnMS, ledOffMS);

2,然后进入SystemUi继续处理。
SystemUI中最终处理在DozeService中,也有一个开关判断,是否要闪烁。
if (!mDozeParameters.getPulseOnNotifications()) return;//getPulseOnNotifications默认为true

DozeService.java中调用private void requestPulse(final int reason)执行点亮屏幕。

private void requestPulse(final int reason, boolean performedProxCheck) {
if (mHost != null && mDreaming && !mPulsing) {
// Let the host know we want to pulse. Wait for it to be ready, then
// turn the screen on. When finished, turn the screen off again.
// Here we need a wakelock to stay awake until the pulse is finished.
mWakeLock.acquire();
mPulsing = true;
if (!mDozeParameters.getProxCheckBeforePulse()) {//这里先判断是否要先执行ProxCheck, proxCheck会检查手机sensor是否正常,如果不正常就退出,不执行点亮屏幕
// skip proximity check
continuePulsing(reason);
return;
}
final long start = SystemClock.uptimeMillis();
if (performedProxCheck) {
// the caller already performed a successful proximity check; we'll only do one to
// capture statistics, continue pulsing immediately.
continuePulsing(reason);
}
// perform a proximity check
new ProximityCheck() {
@Override
public void onProximityResult(int result) {
……
……
}
}.check();
}
} private abstract class ProximityCheck implements SensorEventListener, Runnable {
……
……
public void check() {
if (mFinished || mRegistered) return;
final Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
if (sensor == null) {//手机sensor无效,直接退出程序。
if (DEBUG) Log.d(mTag, "No sensor found");
finishWithResult(RESULT_UNKNOWN);
return;
}
// the pickup sensor interferes with the prox event, disable it until we have a result
mPickupSensor.setDisabled(true); mMaxRange = sensor.getMaximumRange();
mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL, 0,
mHandler);
mHandler.postDelayed(this, TIMEOUT_DELAY_MS);
mRegistered = true;
} ……
……
}

----------------------------------------------------------------------------------------------------

3,SystemUI下拉展开布局中显示通知处理流程:

BaseStatusBar中通过mNotificationListener监听通知更新,获取通知

 private final NotificationListenerService mNotificationListener =
new NotificationListenerService() { public void onListenerConnected() {
if (DEBUG) Log.d(TAG, "onListenerConnected");
final StatusBarNotification[] notifications = getActiveNotifications();//获取当前所有通知集合
final RankingMap currentRanking = getCurrentRanking();
mHandler.post(new Runnable() {
@Override
public void run() {
for (StatusBarNotification sbn : notifications) {
addNotification(sbn, currentRanking, null /* oldEntry */);
}
}
});
}
……
} NotificationListenerService获取通知
   public StatusBarNotification[] getActiveNotifications() {
return getActiveNotifications(null, TRIM_FULL);
} public StatusBarNotification[] getActiveNotifications(String[] keys, int trim) {
if (!isBound())
return null;
try {
//这里通过Binder调用NotificationManagerService调用getActiveNotificationsFromListener获取通知
ParceledListSlice<StatusBarNotification> parceledList = getNotificationInterface().getActiveNotificationsFromListener(mWrapper, keys, trim);
List<StatusBarNotification> list = parceledList.getList();
…………
return list.toArray(new StatusBarNotification[list.size()]);
} catch (android.os.RemoteException ex) {
Log.v(TAG, "Unable to contact notification manager", ex);
}
return null;
} //获取INotificationManager的实例,也就是NotificationManagerService中的mService
private final INotificationManager getNotificationInterface() {
if (mNoMan == null) {
mNoMan = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
}
return mNoMan;
}
NotificationManagerService中对Context.NOTIFICATION_SERVICE的映射
public class NotificationManagerService extends SystemService
public void onStart() {
……
publishBinderService(Context.NOTIFICATION_SERVICE, mService);//SystemService中定义的方法 publishBinderService(..)
……
}

通过上述流程已经获取通知数据,将数据显示在SystemUI中在PhoneStatusBar中处理

  //重载父类BaseStatusBar中的方法,mNotificationListener中会直接调用这里添加通知
public void addNotification(StatusBarNotification notification, RankingMap ranking, Entry oldEntry) {
if (DEBUG) Log.d(TAG, "addNotification key=" + notification.getKey()); Entry shadeEntry = createNotificationViews(notification);
if (shadeEntry == null) {
return;
}
……
addNotificationViews(shadeEntry, ranking);//
// Recalculate the position of the sliding windows and the titles.
setAreThereNotifications();
}
  protected void addNotificationViews(Entry entry, RankingMap ranking) {
if (entry == null) {
return;
}
// Add the expanded view and icon.
mNotificationData.add(entry, ranking);//
updateNotifications(); //此方法会将新通知添加到SystemUI布局中显示
}

android6.0锁屏界面接收新通知处理流程的更多相关文章

  1. 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义重复

    从图片中我们可以看到,这里在语义上有一定的重复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,不过由于Android4.3在锁屏功能上比起老版本做了很大的改动,而 ...

  2. android------锁屏(手机启动出现锁屏界面)

    以前用过一个红包锁屏的软件,第一次打开手机出现锁屏,滑动领取收益,当时觉得这功能不错,就查阅资料,写了一个案例, apk运行流程: 进入软件--->启动服务--->关闭手机(可先退出应用) ...

  3. Android 7.1.1 锁屏界面启动流程

    前几天遇到一个低概率复现锁屏界面不显示,仅仅显示状态栏的问题,跟了下锁屏界面启动显示的流程,在这分享下,也方便以后自己查看.前面简介了下Zygote启动流程, Zygote进程启动后会首先创建一个Sy ...

  4. Android4.0+锁屏程序开发——设置锁屏页面篇

    [如何开发一个锁屏应用] 想要开发一个锁屏应用,似乎很难,其实并没有想象中那么难. 从本质上来说,锁屏界面也只是一个Activity而已,只是这个界面比较特殊,在我们点亮屏幕的时候,这个界面就会出现. ...

  5. Android4.0+锁屏程序开发——按键屏蔽篇

    开发锁屏程序的时候我们要面临的重要问题无疑是如何屏蔽三个按键,Back,Home,Menu  看似简单的功能,实现起来却并不是那么容易. [屏蔽Back按键] 相对来说,屏蔽Back键是比较简单的,只 ...

  6. 解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义反复

    从图片中我们能够看到,这里在语义上有一定的反复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,只是因为Android4.3在锁屏功能上比起老版本号做了非常大的修改 ...

  7. Qt - 锁屏界面加虚拟小键盘

    一.实现效果 鼠标点击"密码输入栏",弹出虚拟键盘,输入锁屏密码后,点击虚拟键盘外部区域,则会隐藏虚拟键盘,再点击登录,成功进入主界面. 二.虚拟键盘-程序设计 2.1 frmNu ...

  8. iOS开发--QQ音乐练习,后台播放和锁屏界面

    一.设置后台播放 首先允许程序后台播放 代码实现 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOpti ...

  9. win10锁屏界面无法更新

    win10的锁屏界面都是巨硬公司推送过来的,质量还不错,最近锁屏界面无法更新,解决方案如下: 以管理员身份运行cmd,分别运行如下两个命令 del /f /s /q /a "%userpro ...

随机推荐

  1. Matlab melband的计算

    %% mel bankmelnum = 24;low = 0;high = 0.5;melbank=melbankm(melnum,fftsize,Fs,low,high,'m');%归一化mel滤波 ...

  2. MySQL for Visual Studio Version

    MySQL for Visual Studio Version Connector/Net Version Supported Visual Studio Version Supported MySQ ...

  3. tomcat开机启动

    最近老板租了个阿里云的服务器,动不动就自动重启,搞得我还得有事没事盯着服务器,谁知道它什么时候会重启啊,为了让自己不要那么累,也为了不要造成不必要的麻烦,还是把tomcat改成开机启动的程序吧. 网上 ...

  4. Netty

    首先值得注意的是netty的jar包版本问题,版本不同,运用的方式也不同.我这里用4.0版本. 对于小白来说,netty到底是什么,我就没必要在这里阐明了,因为百度上比我描述的更全面. 这里就直接开门 ...

  5. redis 扩展 安装 和 memcached 安装

    在Windows下为PHP5.6安装redis扩展和memcached扩展   一.php安装redis扩展   1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本       ...

  6. android_demo之自动生成动态表格

    今天我们学习了如何更好的利用Android 的 layout 布局. 接下来是个简单的栗子去了解这个自动生成的动态的控件(自动生成表格) 这是我们的layout 页面 <?xml version ...

  7. Java和.NET使用DES对称加密的区别

    Java和.NET的系统类库里都有封装DES对称加密的实现方式,但是对外暴露的接口却各不相同,甚至有时会让自己难以解决其中的问题,比如Java加密后的结果在.NET中解密不出来等,由于最近项目有跨Ja ...

  8. java基础快捷键(1)

    1)  输出快捷键:System.out.println():在键盘上输入  Syso  然后按  Alt + ?:就出来了:System.out.println(); 2)主方法:(main): 快 ...

  9. ORACLE FAQ

    Q:sqlplus连接时报:ORA-12560: TNS:protocol adapter error A:1:cmd命令行上: C:\> set ORACLE_SID=orcl orcl是设置 ...

  10. spark job, stage ,task介绍。

    1. spark 如何执行程序? 首先看下spark 的部署图: 节点类型有: 1. master 节点: 常驻master进程,负责管理全部worker节点. 2. worker 节点: 常驻wor ...