Remove proximity sensor code from TeleService app.

This code is being moved to InCallUI in CL:
I5c2ea6daa9443e7ad77c67f272bc0bafdb060e5e

bug: 10366512
Change-Id: I77e0d15ad1a8f5a090c1368db98edaa246dbcd72
diff --git a/src/com/android/phone/CallController.java b/src/com/android/phone/CallController.java
index 11340aa..7b889de 100644
--- a/src/com/android/phone/CallController.java
+++ b/src/com/android/phone/CallController.java
@@ -271,9 +271,6 @@
                     inCallUiState.clearPendingCallStatusCode();
                 }
 
-                // Notify the phone app that a call is beginning so it can
-                // enable the proximity sensor
-                mApp.setBeginningCall(true);
                 break;
 
             default:
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index 6900183..42c73ae 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -97,7 +97,7 @@
 
     private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0;
 
-    private static final int USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR = 15000; // millis
+    // private static final int USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR = 15000; // millis
 
     EditText mDigits;
     private View mDialButton;
@@ -164,10 +164,11 @@
         // Allow this activity to be displayed in front of the keyguard / lockscreen.
         WindowManager.LayoutParams lp = getWindow().getAttributes();
         lp.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
-        if (!mApp.proximitySensorModeEnabled()) {
-            // When no proximity sensor is available, use a shorter timeout.
-            lp.userActivityTimeout = USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR;
-        }
+
+        // When no proximity sensor is available, use a shorter timeout.
+        // TODO(klp): Do we enable this for non proximity devices any more?
+        // lp.userActivityTimeout = USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR;
+
         getWindow().setAttributes(lp);
 
         setContentView(R.layout.emergency_dialer);
diff --git a/src/com/android/phone/InCallScreen.java b/src/com/android/phone/InCallScreen.java
index c672353..31f680b 100644
--- a/src/com/android/phone/InCallScreen.java
+++ b/src/com/android/phone/InCallScreen.java
@@ -235,7 +235,6 @@
     // current "activity lifecycle" state, we can remove these flags.
     private boolean mIsDestroyed = false;
     private boolean mIsForegroundActivity = false;
-    private boolean mIsForegroundActivityForProximity = false;
     private PowerManager mPowerManager;
 
     // For use with Pause/Wait dialogs
@@ -451,13 +450,6 @@
 
         WindowManager.LayoutParams lp = getWindow().getAttributes();
         lp.flags |= flags;
-        if (!mApp.proximitySensorModeEnabled()) {
-            // If we don't have a proximity sensor, then the in-call screen explicitly
-            // controls user activity.  This is to prevent spurious touches from waking
-            // the display.
-            lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
-        }
-        getWindow().setAttributes(lp);
 
         setPhone(mApp.phone);  // Sets mPhone
 
@@ -515,7 +507,6 @@
         super.onResume();
 
         mIsForegroundActivity = true;
-        mIsForegroundActivityForProximity = true;
 
         // The flag shouldn't be turned on when there are actual phone calls.
         if (mCM.hasActiveFgCall() || mCM.hasActiveBgCall() || mCM.hasActiveRingingCall()) {
@@ -738,11 +729,6 @@
         if (DBG) log("onPause()...");
         super.onPause();
 
-        if (mPowerManager.isScreenOn()) {
-            // Set to false when the screen went background *not* by screen turned off. Probably
-            // the user bailed out of the in-call screen (by pressing BACK, HOME, etc.)
-            mIsForegroundActivityForProximity = false;
-        }
         mIsForegroundActivity = false;
 
         // Force a clear of the provider info frame. Since the
@@ -754,10 +740,6 @@
         // We should never allow it to stay true after that.
         mApp.inCallUiState.showAlreadyDisconnectedState = false;
 
-        // A safety measure to disable proximity sensor in case call failed
-        // and the telephony state did not change.
-        mApp.setBeginningCall(false);
-
         // Make sure the "Manage conference" chronometer is stopped when
         // we move away from the foreground.
         mManageConferenceUtils.stopConferenceTime();
@@ -987,16 +969,6 @@
         return mIsForegroundActivity;
     }
 
-    /**
-     * Returns true when the Activity is in foreground (between onResume() and onPause()),
-     * or, is in background due to user's bailing out of the screen, not by screen turning off.
-     *
-     * @see #isForegroundActivity()
-     */
-    /* package */ boolean isForegroundActivityForProximity() {
-        return mIsForegroundActivityForProximity;
-    }
-
     /* package */ void updateKeyguardPolicy(boolean dismissKeyguard) {
         if (dismissKeyguard) {
             getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
@@ -1881,13 +1853,12 @@
             // show "DISCONNECTED" state once, with appropriate elapsed time. After showing that
             // we *must* bail out of the screen again, showing screen lock if needed.
             //
-            // See also comments for isForegroundActivityForProximity()
             //
             // TODO: Consider moving this to CallNotifier. This code assumes the InCallScreen
             // never gets destroyed. For this exact case, it works (since InCallScreen won't be
             // destroyed), while technically this isn't right; Activity may be destroyed when
             // in background.
-            if (currentlyIdle && !isForegroundActivity() && isForegroundActivityForProximity()) {
+            if (currentlyIdle && !isForegroundActivity()) {
                 log("Force waking up the screen to let users see \"disconnected\" state");
                 if (call != null) {
                     mCallCard.updateElapsedTimeWidget(call);
@@ -2789,7 +2760,6 @@
         } else {
             openDialpadInternal(true);  // do the "opening" animation
         }
-        mApp.updateProximitySensorMode(mCM.getState());
     }
 
     /** Internal wrapper around {@link DTMFTwelveKeyDialer#openDialer(boolean)} */
@@ -4235,15 +4205,9 @@
      */
     private void updateExpandedViewState() {
         if (mIsForegroundActivity) {
-            if (mApp.proximitySensorModeEnabled()) {
-                // We should not enable notification's expanded view on RINGING state.
-                mApp.notificationMgr.statusBarHelper.enableExpandedView(
-                        mCM.getState() != PhoneConstants.State.RINGING);
-            } else {
-                // If proximity sensor is unavailable on the device, disable it to avoid false
-                // touches toward notifications.
-                mApp.notificationMgr.statusBarHelper.enableExpandedView(false);
-            }
+            // We should not enable notification's expanded view on RINGING state.
+            mApp.notificationMgr.statusBarHelper.enableExpandedView(
+                    mCM.getState() != PhoneConstants.State.RINGING);
         } else {
             mApp.notificationMgr.statusBarHelper.enableExpandedView(true);
         }
diff --git a/src/com/android/phone/PhoneApp.java b/src/com/android/phone/PhoneApp.java
index e3d3fa9..6b5aa11 100644
--- a/src/com/android/phone/PhoneApp.java
+++ b/src/com/android/phone/PhoneApp.java
@@ -38,12 +38,4 @@
             mPhoneGlobals.onCreate();
         }
     }
-
-    @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-        if (mPhoneGlobals != null) {
-            mPhoneGlobals.onConfigurationChanged(newConfig);
-        }
-        super.onConfigurationChanged(newConfig);
-    }
 }
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index b9cd6c3..9ed0470 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -67,7 +67,6 @@
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.telephony.cdma.TtyIntent;
 import com.android.phone.common.CallLogAsync;
-import com.android.phone.BluetoothManager.BluetoothIndicatorListener;
 import com.android.phone.OtaUtils.CdmaOtaScreenState;
 import com.android.phone.WiredHeadsetManager.WiredHeadsetListener;
 import com.android.server.sip.SipService;
@@ -77,10 +76,7 @@
  * Global state for the telephony subsystem when running in the primary
  * phone process.
  */
-public class PhoneGlobals extends ContextWrapper
-        implements AccelerometerListener.OrientationListener,
-                   BluetoothIndicatorListener,
-                   WiredHeadsetListener {
+public class PhoneGlobals extends ContextWrapper implements WiredHeadsetListener {
     /* package */ static final String LOG_TAG = "PhoneApp";
 
     /**
@@ -204,10 +200,6 @@
     private boolean mIsSimPinEnabled;
     private String mCachedSimPin;
 
-    // True if the keyboard is currently *not* hidden
-    // Gets updated whenever there is a Configuration change
-    private boolean mIsHardKeyboardOpen;
-
     // True if we are beginning a call, but the phone state has not changed yet
     private boolean mBeginningCall;
 
@@ -220,10 +212,7 @@
     private IPowerManager mPowerManagerService;
     private PowerManager.WakeLock mWakeLock;
     private PowerManager.WakeLock mPartialWakeLock;
-    private PowerManager.WakeLock mProximityWakeLock;
     private KeyguardManager mKeyguardManager;
-    private AccelerometerListener mAccelerometerListener;
-    private int mOrientation = AccelerometerListener.ORIENTATION_UNKNOWN;
 
     private UpdateLock mUpdateLock;
 
@@ -469,18 +458,6 @@
             // lock used to keep the processor awake, when we don't care for the display.
             mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
                     | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
-            // Wake lock used to control proximity sensor behavior.
-            if (mPowerManager.isWakeLockLevelSupported(
-                    PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
-                mProximityWakeLock = mPowerManager.newWakeLock(
-                        PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, LOG_TAG);
-            }
-            if (DBG) Log.d(LOG_TAG, "onCreate: mProximityWakeLock: " + mProximityWakeLock);
-
-            // create mAccelerometerListener only if we are using the proximity sensor
-            if (proximitySensorModeEnabled()) {
-                mAccelerometerListener = new AccelerometerListener(this, this);
-            }
 
             mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
 
@@ -529,7 +506,6 @@
 
             // Bluetooth manager
             bluetoothManager = new BluetoothManager(this, mCM, callModeler);
-            bluetoothManager.addBluetoothIndicatorListener(this);
 
             ringer = Ringer.init(this, bluetoothManager);
 
@@ -650,17 +626,6 @@
         }
    }
 
-    public void onConfigurationChanged(Configuration newConfig) {
-        if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
-            mIsHardKeyboardOpen = true;
-        } else {
-            mIsHardKeyboardOpen = false;
-        }
-
-        // Update the Proximity sensor based on keyboard state
-        updateProximitySensorMode(mCM.getState());
-    }
-
     /**
      * Returns the singleton instance of the PhoneApp.
      */
@@ -835,35 +800,6 @@
     }
 
     /**
-     * @return true if the in-call UI is running as the foreground activity, or,
-     * it went to background due to screen being turned off. This might be useful
-     * to determine if the in-call screen went to background because of other
-     * activities, or its proximity sensor state or manual power-button press.
-     *
-     * Here are some examples.
-     *
-     * - If you want to know if the activity is in foreground or screen is turned off
-     *   from the in-call UI (i.e. though it is not "foreground" anymore it will become
-     *   so after screen being turned on), check
-     *   {@link #isShowingCallScreenForProximity()} is true or not.
-     *   {@link #updateProximitySensorMode(com.android.internal.telephony.PhoneConstants.State)} is
-     *   doing this.
-     *
-     * - If you want to know if the activity is not in foreground just because screen
-     *   is turned off (not due to other activity's interference), check
-     *   {@link #isShowingCallScreen()} is false *and* {@link #isShowingCallScreenForProximity()}
-     *   is true. InCallScreen#onDisconnect() is doing this check.
-     *
-     * @see #isShowingCallScreen()
-     *
-     * TODO: come up with better naming..
-     */
-    boolean isShowingCallScreenForProximity() {
-        if (mInCallScreen == null) return false;
-        return mInCallScreen.isForegroundActivityForProximity();
-    }
-
-    /**
      * Dismisses the in-call UI.
      *
      * This also ensures that you won't be able to get back to the in-call
@@ -1113,125 +1049,13 @@
     }
 
     /**
-     * Set when a new outgoing call is beginning, so we can update
-     * the proximity sensor state.
-     * Cleared when the InCallScreen is no longer in the foreground,
-     * in case the call fails without changing the telephony state.
-     */
-    /* package */ void setBeginningCall(boolean beginning) {
-        // Note that we are beginning a new call, for proximity sensor support
-        mBeginningCall = beginning;
-        // Update the Proximity sensor based on mBeginningCall state
-        updateProximitySensorMode(mCM.getState());
-    }
-
-    /**
-     * Updates the wake lock used to control proximity sensor behavior,
-     * based on the current state of the phone.  This method is called
-     * from the CallNotifier on any phone state change.
-     *
-     * 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.
-     *
-     * Note this method doesn't care if the InCallScreen is the foreground
-     * activity or not.  That's because we want the proximity sensor to be
-     * enabled any time the phone is in use, to avoid false cheek events
-     * for whatever app you happen to be running.
-     *
-     * Proximity wake lock will *not* be held if any one of the
-     * conditions is true while on a call:
-     * 1) If the audio is routed via Bluetooth
-     * 2) If a wired headset is connected
-     * 3) if the speaker is ON
-     * 4) If the slider is open(i.e. the hardkeyboard is *not* hidden)
-     *
-     * @param state current state of the phone (see {@link Phone#State})
-     */
-    /* package */ void updateProximitySensorMode(PhoneConstants.State state) {
-        if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: state = " + state);
-
-        if (proximitySensorModeEnabled()) {
-            synchronized (mProximityWakeLock) {
-                // turn proximity sensor off and turn screen on immediately if
-                // we are using a headset, the keyboard is open, or the device
-                // is being held in a horizontal position.
-                boolean screenOnImmediately = (wiredHeadsetManager.isHeadsetPlugged()
-                                               || PhoneUtils.isSpeakerOn(this)
-                                               || bluetoothManager.isBluetoothHeadsetAudioOn()
-                                               || mIsHardKeyboardOpen);
-
-                // 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.
-                boolean horizontal =
-                        (mOrientation == AccelerometerListener.ORIENTATION_HORIZONTAL);
-                screenOnImmediately |= !isShowingCallScreenForProximity() && horizontal;
-
-                // 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.
-                boolean dialpadVisible = false;
-                if (mInCallScreen != null) {
-                    dialpadVisible =
-                            mInCallScreen.getUpdatedInCallControlState().dialpadEnabled
-                            && mInCallScreen.getUpdatedInCallControlState().dialpadVisible
-                            && isShowingCallScreen();
-                }
-                screenOnImmediately |= dialpadVisible && horizontal;
-
-                if (((state == PhoneConstants.State.OFFHOOK) || mBeginningCall) && !screenOnImmediately) {
-                    // Phone is in use!  Arrange for the screen to turn off
-                    // automatically when the sensor detects a close object.
-                    if (!mProximityWakeLock.isHeld()) {
-                        if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: acquiring...");
-                        mProximityWakeLock.acquire();
-                    } else {
-                        if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already held.");
-                    }
-                } else {
-                    // Phone is either idle, or ringing.  We don't want any
-                    // special proximity sensor behavior in either case.
-                    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 =
-                            (screenOnImmediately ? 0 : PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
-                        mProximityWakeLock.release(flags);
-                    } else {
-                        if (VDBG) {
-                            Log.d(LOG_TAG, "updateProximitySensorMode: lock already released.");
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void orientationChanged(int orientation) {
-        mOrientation = orientation;
-        updateProximitySensorMode(mCM.getState());
-    }
-
-    /**
      * Notifies the phone app when the phone state changes.
      *
-     * This method will updates various states inside Phone app (e.g. proximity sensor mode,
-     * accelerometer listener state, update-lock state, etc.)
+     * This method will updates various states inside Phone app (e.g. update-lock state, etc.)
      */
     /* package */ void updatePhoneState(PhoneConstants.State state) {
         if (state != mLastPhoneState) {
             mLastPhoneState = state;
-            updateProximitySensorMode(state);
 
             // Try to acquire or release UpdateLock.
             //
@@ -1255,13 +1079,6 @@
                 }
             }
 
-            if (mAccelerometerListener != null) {
-                // use accelerometer to augment proximity sensor when in call
-                mOrientation = AccelerometerListener.ORIENTATION_UNKNOWN;
-                mAccelerometerListener.enable(state == PhoneConstants.State.OFFHOOK);
-            }
-            // clear our beginning call flag
-            mBeginningCall = false;
             // While we are in call, the in-call screen should dismiss the keyguard.
             // This allows the user to press Home to go directly home without going through
             // an insecure lock screen.
@@ -1284,14 +1101,6 @@
         return mUpdateLock;
     }
 
-    /**
-     * @return true if this device supports the "proximity sensor
-     * auto-lock" feature while in-call (see updateProximitySensorMode()).
-     */
-    /* package */ boolean proximitySensorModeEnabled() {
-        return (mProximityWakeLock != null);
-    }
-
     KeyguardManager getKeyguardManager() {
         return mKeyguardManager;
     }
@@ -1356,28 +1165,12 @@
 
 
     /**
-     * This needs to be called any time the bluetooth headset state or the
-     * telephony state changes.
-     * TODO(klp): See about a ProximityManager-type class listening to bluetooth
-     * state changes instead of having this global method
-     */
-
-    @Override
-    public void onBluetoothIndicationChange(boolean showAsConnected, BluetoothManager manager) {
-        // Update the Proximity sensor based on Bluetooth audio state
-        updateProximitySensorMode(mCM.getState());
-    }
-
-    /**
      * This is called when the wired headset state changes.
      */
     @Override
     public void onWiredHeadsetConnection(boolean pluggedIn) {
         PhoneConstants.State phoneState = mCM.getState();
 
-        // Update the Proximity sensor based on headset state
-        updateProximitySensorMode(phoneState);
-
         // Force TTY state update according to new headset state
         if (mTtyEnabled) {
             mHandler.sendMessage(mHandler.obtainMessage(EVENT_TTY_PREFERRED_MODE_CHANGED, 0));
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index 93f3002..9671c17 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -1835,9 +1835,6 @@
         // in use.
         app.updateWakeState();
 
-        // Update the Proximity sensor based on speaker state
-        app.updateProximitySensorMode(app.mCM.getState());
-
         app.mCM.setEchoSuppressionEnabled(flag);
     }