android6.0 powermanagerservice notifier分析

上传人:第*** 文档编号:31311101 上传时间:2018-02-06 格式:DOC 页数:9 大小:71KB
返回 下载 相关 举报
android6.0 powermanagerservice notifier分析_第1页
第1页 / 共9页
android6.0 powermanagerservice notifier分析_第2页
第2页 / 共9页
android6.0 powermanagerservice notifier分析_第3页
第3页 / 共9页
android6.0 powermanagerservice notifier分析_第4页
第4页 / 共9页
android6.0 powermanagerservice notifier分析_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《android6.0 powermanagerservice notifier分析》由会员分享,可在线阅读,更多相关《android6.0 powermanagerservice notifier分析(9页珍藏版)》请在金锄头文库上搜索。

1、android6.0 PowerManagerService Notifier 分析这个类在 PowerManagerService 中是非常重要的,当 PowerManagerService 的状态改变时,都是靠这个类通知。比如常用的灭屏和亮屏广播,也是在这个类中发送的。一、Notifier 初始化首先我们来看它在 PowerManagerService 构造函数中的初始化:cpp view plain copy 在 CODE 上查看代码片派生到我的代码片mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatterySt

2、ats, mAppOps, createSuspendBlockerLocked(PowerManagerService.Broadcasts), mPolicy); PowerManagerService 把自己的 main looper 传进去了,说明在 Notifier 的消息处理是在PowerManagerService 的主线程中,还有一点和之前的 WakeLocks,和 Display 锁一样,这里也为 Notifier 创建了一个 Broadcasts 锁。二、 持锁我们现在开始看各 PowerManagerService 个状态是如何在 Notifier 里处理的。先来看 ac

3、quireWakeLockInternal 函数cpp view plain copy 在 CODE 上查看代码片派生到我的代码片private void acquireWakeLockInternal(IBinder lock, int flags, String tag, String packageName, WorkSource ws, String historyTag, int uid, int pid) synchronized (mLock) WakeLock wakeLock; int index = findWakeLockIndexLocked(lock); boolea

4、n notifyAcquire; if (index = 0) wakeLock = mWakeLocks.get(index); if (!wakeLock.hasSameProperties(flags, tag, ws, uid, pid) / Update existing wake lock. This shouldnt happen but is harmless. notifyWakeLockChangingLocked(wakeLock, flags, tag, packageName, uid, pid, ws, historyTag); wakeLock.updatePro

5、perties(flags, tag, packageName, ws, historyTag, uid, pid); notifyAcquire = false; else wakeLock = new WakeLock(lock, flags, tag, packageName, ws, historyTag, uid, pid); try lock.linkToDeath(wakeLock, 0); catch (RemoteException ex) throw new IllegalArgumentException(Wake lock is already dead.); mWak

6、eLocks.add(wakeLock); setWakeLockDisabledStateLocked(wakeLock); notifyAcquire = true;/只有在新建的时候通知 Notifier applyWakeLockFlagsOnAcquireLocked(wakeLock, uid); mDirty |= DIRTY_WAKE_LOCKS; updatePowerStateLocked(); if (notifyAcquire) / This needs to be done last so we are sure we have acquired the / kern

7、el wake lock. Otherwise we have a race where the system may / go to sleep between the time we start the accounting in battery / stats and when we actually get around to telling the kernel to / stay awake. notifyWakeLockAcquiredLocked(wakeLock); 我们看上面函数只有在 WakeLock 是新建的时候才会调用 notifyWakeLockAcquiredLo

8、cked函数:cpp view plain copy 在 CODE 上查看代码片派生到我的代码片private void notifyWakeLockAcquiredLocked(WakeLock wakeLock) if (mSystemReady & !wakeLock.mDisabled) wakeLock.mNotifiedAcquired = true; mNotifier.onWakeLockAcquired(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName, wakeLock.mOwnerUid, wakeLock.mOw

9、nerPid, wakeLock.mWorkSource, wakeLock.mHistoryTag); Notifier 也是统计电量和 appops 处理下。cpp view plain copy 在 CODE 上查看代码片派生到我的代码片public void onWakeLockAcquired(int flags, String tag, String packageName, int ownerUid, int ownerPid, WorkSource workSource, String historyTag) final int monitorType = getBattery

10、StatsWakeLockMonitorType(flags); if (monitorType = 0) try final boolean unimportantForLogging = ownerUid = Process.SYSTEM_UID if (workSource != null) mBatteryStats.noteStartWakelockFromSource(workSource, ownerPid, tag, historyTag, monitorType, unimportantForLogging); else mBatteryStats.noteStartWake

11、lock(ownerUid, ownerPid, tag, historyTag, monitorType, unimportantForLogging); / XXX need to deal with disabled operations. mAppOps.startOperation(AppOpsManager.getToken(mAppOps), AppOpsManager.OP_WAKE_LOCK, ownerUid, packageName); catch (RemoteException ex) / Ignore PowerManagerService 在删除锁的时候会调用 m

12、Notifier.onWakeLockReleased 函数,更新锁的时候最后会调用 mNotifier.onWakeLockChanging 函数。这里面都是通知电池以及 appops相关。三、唤醒在 PowerManagerService 的 wakeUpNoUpdateLocked 函数会调用如下函数:cpp view plain copy 在 CODE 上查看代码片派生到我的代码片mNotifier.onWakeUp(reason, reasonUid, opPackageName, opUid); 再看下 Notifier 处理:cpp view plain copy 在 CODE

13、上查看代码片派生到我的代码片public void onWakeUp(String reason, int reasonUid, String opPackageName, int opUid) try mBatteryStats.noteWakeUp(reason, reasonUid); if (opPackageName != null) mAppOps.noteOperation(AppOpsManager.OP_TURN_SCREEN_ON, opUid, opPackageName); catch (RemoteException ex) / Ignore 四、userActivi

14、ty在 userActivityNoUpdateLocked 函数中也会调用如下函数cpp view plain copy 在 CODE 上查看代码片派生到我的代码片mNotifier.onUserActivity(event, uid); 我们看下 Notifier 的处理cpp view plain copy 在 CODE 上查看代码片派生到我的代码片public void onUserActivity(int event, int uid) try mBatteryStats.noteUserActivity(uid, event); catch (RemoteException ex)

15、 / Ignore synchronized (mLock) if (!mUserActivityPending) mUserActivityPending = true; Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY); msg.setAsynchronous(true); mHandler.sendMessage(msg); 消息处理函数为:sendUserActivitycpp view plain copy 在 CODE 上查看代码片派生到我的代码片private void sendUserActivity() synchronized (mLock) if (!mUserActivityPending) return; mUserActivityPending = false; mPolicy.userActivity(); 最后是在 PhoneWindowManager 中处理好像是在 keyguard 中处理。五、更新屏幕最亮化我们再来看 updateScreenBrightnessBoostL

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号