最近我的HTC Desire S 掛斷電話有時屏幕無法喚醒。查了一下是proximity sensor的問題。當遠離sensor是沒有中斷,就是隻有near的中斷,沒有far的中斷。
這個是硬件問題,我又不想換sensor,所以就查了一下代碼。
見下面這段,註釋寫的很明白,會等到用戶把手機從頭部拿開後才release wakelock。但sensor並不會發出far 的中斷,所以會一直等下去,屏就不亮了。
改也很簡單,直接改爲0。
但這種改法需要有源碼,好在CM的ROM也不錯,就先用着了。 以後或許可以嘗試下反編譯或者用反射看看行不行。
PhoneApp
updateProximitySensorMode
if (mProximityWakeLock.isHeld()) {
if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: releasing...");
// Wait until user has moved the phone away from his head if we are
// releasing due to the phone call ending.
// Qtherwise, turn screen on immediately
int flags = 0;//hnmsky
//(screenOnImmediately ? 0 : PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
mProximityWakeLock.release(flags);
後面這些是調用流程,做個備份。
PowerManagerSevice
releaseWakeLockLocked
if (isScreenLock(wl.flags)) {
if ((wl.flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
mProximityWakeLockCount--;
if (mProximityWakeLockCount == 0) {
if (mProximitySensorActive &&
((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0)) {
// wait for proximity sensor to go negative before disabling sensor
if (mDebugProximitySensor) {
Slog.d(TAG, "waiting for proximity sensor to go negative");
}
} else {
disableProximityLockLocked();
}
}
}
SensorManager
unregisterListener
sensors_enable_sensor
android_hardware_SensorManager.cpp
sensors_enable_sensor
SensorDevice
activate