java/com/android/incallui/ProximitySensor.java
/**
   * Updates the wake lock used to control proximity sensor behavior, based on the current state of
   * the phone.
   *
   * <p>On devices that have a proximity sensor, to avoid false touches during a call, we hold a
   * PROXIMITY_SCREEN_OFF_WAKE_LOCK wake lock whenever the phone is off hook. (When held, that wake
   * lock causes the screen to turn off automatically when the sensor detects an object close to the
   * screen.)
   *
   * <p>This method is a no-op for devices that don't have a proximity sensor.
   *
   * <p>Proximity wake lock will be released if any of the following conditions are true: the audio
   * is routed through bluetooth, a wired headset, or the speaker; the user requested, received a
   * request for, or is in a video call; or the phone is horizontal while in a call.
   */
Updates the wake lock used to control proximity sensor behavior, based on the current state of
the phone.

On devices that have a proximity sensor, to avoid false touches during a call, we hold a
PROXIMITY_SCREEN_OFF_WAKE_LOCK wake lock whenever the phone is off hook. (When held, that wake
lock causes the screen to turn off automatically when the sensor detects an object close to the
screen.)

This method is a no-op for devices that don't have a proximity sensor.

Proximity wake lock will be released if any of the following conditions are true: the audio
is routed through bluetooth, a wired headset, or the speaker; the user requested, received a
request for, or is in a video call; or the phone is horizontal while in a call.
Updates the wake lock used to control proximity sensor behavior based on the current state of the phone . On devices that have a proximity sensor to avoid false touches during a call we hold a PROXIMITY_SCREEN_OFF_WAKE_LOCK wake lock whenever the phone is off hook . ( When held that wake lock causes the screen to turn off automatically when the sensor detects an object close to the screen . ) This method is a no - op for devices that don ' t have a proximity sensor . Proximity wake lock will be released if any of the following conditions are true : the audio is routed through bluetooth a wired headset or the speaker ; the user requested received a request for or is in a video call ; or the phone is horizontal while in a call .
private synchronized void updateProximitySensorMode() {
    final int audioRoute = mAudioModeProvider.getAudioState().getRoute();
    boolean screenOnImmediately =
        (CallAudioState.ROUTE_WIRED_HEADSET == audioRoute
            || CallAudioState.ROUTE_SPEAKER == audioRoute
            || CallAudioState.ROUTE_BLUETOOTH == audioRoute
            || mIsAttemptingVideoCall
            || mIsVideoCall);
    final boolean horizontal = (mOrientation == AccelerometerListener.ORIENTATION_HORIZONTAL);
    screenOnImmediately |= !mUiShowing && horizontal;
    screenOnImmediately |= mDialpadVisible && horizontal;
    LogUtil.i(
        "ProximitySensor.updateProximitySensorMode",
        "screenOnImmediately: %b, dialPadVisible: %b, "
            + "offHook: %b, horizontal: %b, uiShowing: %b, audioRoute: %s",
        screenOnImmediately,
        mDialpadVisible,
        mIsPhoneOffhook,
        mOrientation == AccelerometerListener.ORIENTATION_HORIZONTAL,
        mUiShowing,
        CallAudioState.audioRouteToString(audioRoute));
    if ((mIsPhoneOffhook || mHasIncomingCall) && !screenOnImmediately) {
      LogUtil.v("ProximitySensor.updateProximitySensorMode", "turning on proximity sensor");
      turnOnProximitySensor();
    } else {
      LogUtil.v("ProximitySensor.updateProximitySensorMode", "turning off proximity sensor");
      turnOffProximitySensor(screenOnImmediately);
    }
  }
private synchronized void updateProximitySensorMode ( ) { final int audioRoute = mAudioModeProvider . getAudioState ( ) . getRoute ( ) ; boolean screenOnImmediately = ( CallAudioState . ROUTE_WIRED_HEADSET == audioRoute || CallAudioState . ROUTE_SPEAKER == audioRoute || CallAudioState . ROUTE_BLUETOOTH == audioRoute || mIsAttemptingVideoCall || mIsVideoCall ) ; final boolean horizontal = ( mOrientation == AccelerometerListener . ORIENTATION_HORIZONTAL ) ; screenOnImmediately |= ! mUiShowing && horizontal ; screenOnImmediately |= mDialpadVisible && horizontal ; LogUtil . i ( "ProximitySensor.updateProximitySensorMode" , "screenOnImmediately: %b, dialPadVisible: %b, " + "offHook: %b, horizontal: %b, uiShowing: %b, audioRoute: %s" , screenOnImmediately , mDialpadVisible , mIsPhoneOffhook , mOrientation == AccelerometerListener . ORIENTATION_HORIZONTAL , mUiShowing , CallAudioState . audioRouteToString ( audioRoute ) ) ; if ( ( mIsPhoneOffhook || mHasIncomingCall ) && ! screenOnImmediately ) { LogUtil . v ( "ProximitySensor.updateProximitySensorMode" , "turning on proximity sensor" ) ; turnOnProximitySensor ( ) ; } else { LogUtil . v ( "ProximitySensor.updateProximitySensorMode" , "turning off proximity sensor" ) ; turnOffProximitySensor ( screenOnImmediately ) ; } }
Updates the wake lock used to control proximity sensor behavior, based on the current state of
 the phone.
Updates the wake lock used to control proximity sensor behavior based on the current state of the phone .
// We do not keep the screen off when the user is outside in-call screen and we are // horizontal, but we do not force it on when we become horizontal until the // proximity sensor goes negative. // We do not keep the screen off when dialpad is visible, we are horizontal, and // the in-call screen is being shown. // At that moment we're pretty sure users want to use it, instead of letting the // proximity sensor turn off the screen by their hands. // Phone is in use!  Arrange for the screen to turn off // automatically when the sensor detects a close object. // Phone is either idle, or ringing.  We don't want any special proximity sensor // behavior in either case.