AndroidM及以上,接听电话之后5S 灭屏

时间:2021-10-31 18:51:35

  笔记:好久没有更新博客了.期间换了份新的工作,多了一些烦心的事情,后续博客会坚持更新.....

  AndroidM及以上,接听电话之后5S 灭屏处理:
  涉及到两个文件:packages/services/Telephony  路径中的PhoneGlobals.java  和 CallNotifier.java

  1:PhoneGlobals.java 中添加两个方法

 

void setScreenTimeout(long time) {
mHandler.removeCallbacks(timeOutTask);
mHandler.postDelayed(timeOutTask, time);
}
Runnable timeOutTask = new Runnable(){
public void run(){
try{
mPowerManagerService.goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_PROXIMITY,0);
} catch(RemoteException e){

}
}
};

   2:CallNotifier.java中

  先添加如下方法

private Call.State mLastCallState = Call.State.IDLE;
private void setScreenTimeOut(){
Call.State ringCallState = mCM.getFirstActiveRingingCall().getState();
Call.State fgCallState = mCM.getActiveFgCallState();
if((ringCallState == Call.State.IDLE && mLastCallState.isRinging())||
(fgCallState == Call.State.ACTIVE && mLastCallState.isDialing())){
PhoneGlobals.getInstance().setScreenTimeout(5000);
}
mLastCallState = ringCallState.isRinging()?ringCallState:fgCallState;
}
然后在这个方法中直接调用即可.
private void onPhoneStateChanged(AsyncResult r) {     ....     setScreenTimeOut();    ...}