and5.1powermanagerservice深入分析(二)powermanager中各函数.doc
文本预览下载声明
and5.1PowerManagerService深入分析(二)PowerManager中各函数
今天主要从PowerManager中的接口入手去分析PowerManagerService.
先分析PowerManager中的一个内部类WakeLock,可以使用这个类持睡眠锁。
下面是PowerManager中WakeLock内部类来里面的代码:
[java] view plain copy
public void acquire() {
synchronized (mToken) {
acquireLocked();
}
}
/**
* Acquires the wake lock with a timeout.
* p
* Ensures that the device is on at the level requested when
* the wake lock was created. The lock will be released after the given timeout
* expires.
* /p
*
* @param timeout The timeout after which to release the wake lock, in milliseconds.
*/
public void acquire(long timeout) {
synchronized (mToken) {
acquireLocked();
mHandler.postDelayed(mReleaser, timeout);//利用消息机制做一个timeout的持锁,mReleaser中是对该锁释放了
}
}
private void acquireLocked() {
if (!mRefCounted || mCount++ == 0) {
// Do this even if the wake lock is already thought to be held (mHeld == true)
// because non-reference counted wake locks are not always properly released.
// For example, the keyguards wake lock might be forcibly released by the
// power manager without the keyguard knowing. A subsequent call to acquire
// should immediately acquire the wake lock once again despite never having
// been explicitly released by the keyguard.
mHandler.removeCallbacks(mReleaser);
Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, mTraceName, 0);
try {
mService.acquireWakeLock(mToken, mFlags, mTag, mPackageName, mWorkSource,//调用PMS的acquireWakeLock
mHistoryTag);
} catch (RemoteException e) {
}
mHeld = true;
}
}
先看PMS里的acquireWakeLock函数,先做一些权限的检查,然后就调用acquireWakeLockInternal函数。
[java] view plain copy
@Override // Binder call
public void acquireWakeLock(IBinder lock, int flags, String tag, String packageName,
WorkS
显示全部