有谁研究过电源管理PowerManagerService里面的源代码的。。。

wenzheng38 2011-09-04 05:21:58
里面定义了个数组:private final int[] mBroadcastQueue = new int[] { -1, -1, -1 }; 为什么只是3维?
private void sendNotificationLocked(boolean on, int why)
{
if (!on) {
mStillNeedSleepNotification = false;
}

// Add to the queue.
int index = 0;
while (mBroadcastQueue[index] != -1) {
index++;
}
mBroadcastQueue[index] = on ? 1 : 0;
mBroadcastWhy[index] = why;

// If we added it position 2, then there is a pair that can be stripped.
// If we added it position 1 and we're turning the screen off, we can strip
// the pair and do nothing, because the screen is already off, and therefore
// keyguard has already been enabled.
// However, if we added it at position 1 and we're turning it on, then position
// 0 was to turn it off, and we can't strip that, because keyguard needs to come
// on, so have to run the queue then.
if (index == 2) {
// While we're collapsing them, if it's going off, and the new reason
// is more significant than the first, then use the new one.
if (!on && mBroadcastWhy[0] > why) {
mBroadcastWhy[0] = why;
}
mBroadcastQueue[0] = on ? 1 : 0;
mBroadcastQueue[1] = -1;
mBroadcastQueue[2] = -1;
mBroadcastWakeLock.release();
mBroadcastWakeLock.release();
index = 0;
}
if (index == 1 && !on) {
mBroadcastQueue[0] = -1;
mBroadcastQueue[1] = -1;
index = -1;
// The wake lock was being held, but we're not actually going to do any
// broadcasts, so release the wake lock.
EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 1, mBroadcastWakeLock.mCount);
mBroadcastWakeLock.release();
}

// Now send the message.
if (index >= 0) {
// Acquire the broadcast wake lock before changing the power
// state. It will be release after the broadcast is sent.
// We always increment the ref count for each notification in the queue
// and always decrement when that notification is handled.
mBroadcastWakeLock.acquire();
EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_SEND, mBroadcastWakeLock.mCount);
mHandler.post(mNotificationTask);
}
}
能帮忙解释下吗,在这个函数里,尤其分别在三个if条件里,对mBroadcastQueue数组进行了重新赋值,为什么要这样操作,理论是什么,根据。。。?
...全文
470 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
csuhanyong 2011-12-24
  • 打赏
  • 举报
回复
还有dim
wenzheng38 2011-09-25
  • 打赏
  • 举报
回复
没人懂吗。。。?三个是否对应三个状态?
那个三个个,除了on、off,还要第三个是啥呀
lyzzzwx 2011-09-05
  • 打赏
  • 举报
回复
学习中

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧