Fix issue: 2413494: Add TTY support.

This is a new implementation of TTY support.
Previous implementation in commit aead64def1fe58c95c086a0ca00cf0b13fa32ef1 is reverted.
The new method does not rely any more on the kernel headset driver to send a UEvent containing
current TTY mode.
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 6cd6ff9..0b6f97e 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -218,8 +218,4 @@
     <!-- Component name of the default wallpaper. This will be ImageWallpaper if not 
          specified -->
     <string name="default_wallpaper_component">@null</string>
-
-    <!-- Flag indicating whether headset events are used by kernel to indicate
-    TTY mode changes. -->
-    <bool name="tty_mode_uses_headset_events">false</bool>
 </resources>
diff --git a/services/java/com/android/server/HeadsetObserver.java b/services/java/com/android/server/HeadsetObserver.java
index c94450b..9d69564 100644
--- a/services/java/com/android/server/HeadsetObserver.java
+++ b/services/java/com/android/server/HeadsetObserver.java
@@ -53,19 +53,6 @@
     private final Context mContext;
     private final WakeLock mWakeLock;  // held while there is a pending route change
 
-    private boolean mHandleTTY;
-    private int mTTYState;
-    private AudioManager mAudioManager = null;
-
-    // special use of bits in headset state received from kernel made by some
-    // platforms to indicate changes in TTY mode.
-    private static final int BIT_TTY_OFF = 0;
-    private static final int BIT_TTY_FULL = (1 << 2);
-    private static final int BIT_TTY_VCO = (1 << 5);
-    private static final int BIT_TTY_HCO = (1 << 6);
-    private static final int TTY_BITS_MASK = (BIT_TTY_FULL | BIT_TTY_VCO | BIT_TTY_HCO);
-
-
     public HeadsetObserver(Context context) {
         mContext = context;
         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
@@ -74,11 +61,6 @@
 
         startObserving(HEADSET_UEVENT_MATCH);
 
-        // read settings for TTY mode indication method
-        mHandleTTY = context.getResources().getBoolean(
-                com.android.internal.R.bool.tty_mode_uses_headset_events);
-        mTTYState = BIT_TTY_OFF;
-
         init();  // set initial status
     }
 
@@ -118,39 +100,6 @@
     }
 
     private synchronized final void update(String newName, int newState) {
-        // handle TTY state change first
-        if (mHandleTTY) {
-            int ttyState = newState  & TTY_BITS_MASK;
-            if (ttyState != mTTYState) {
-                String ttyMode;
-
-                switch (ttyState) {
-                case BIT_TTY_FULL:
-                    ttyMode = "tty_full";
-                    break;
-                case BIT_TTY_VCO:
-                    ttyMode = "tty_vco";
-                    break;
-                case BIT_TTY_HCO:
-                    ttyMode = "tty_hco";
-                    break;
-                case BIT_TTY_OFF:
-                    ttyMode = "tty_off";
-                    break;
-                default:
-                    ttyMode = "tty_invalid";
-                    break;
-
-                }
-                if (ttyMode != "tty_invalid") {
-                    mTTYState = ttyState;
-                    if (mAudioManager == null) {
-                        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
-                    }
-                    mAudioManager.setParameters("tty_mode="+ttyMode);
-                }
-            }
-        }
         // Retain only relevant bits
         int headsetState = newState & SUPPORTED_HEADSETS;
         int newOrOld = headsetState | mHeadsetState;
diff --git a/telephony/java/com/android/internal/telephony/cdma/TtyIntent.java b/telephony/java/com/android/internal/telephony/cdma/TtyIntent.java
index f27f79c..3813b1d 100644
--- a/telephony/java/com/android/internal/telephony/cdma/TtyIntent.java
+++ b/telephony/java/com/android/internal/telephony/cdma/TtyIntent.java
@@ -43,4 +43,25 @@
      */
     public static final String TTY_ENABLED = "ttyEnabled";
 
+    /**
+     * Broadcast intent action indicating that the TTY preferred operating mode
+     * has changed. An intent extra provides the new mode as an int.
+     * @see #TTY_PREFFERED_MODE
+     *
+     * {@hide}
+     */
+    public static final String TTY_PREFERRED_MODE_CHANGE_ACTION =
+        "com.android.internal.telephony.cdma.intent.action.TTY_PREFERRED_MODE_CHANGE";
+
+    /**
+     * The lookup key for an int that indicates preferred TTY mode.
+     * Valid modes are:
+     * - {@link Phone.TTY_MODE_OFF}
+     * - {@link Phone.TTY_MODE_FULL}
+     * - {@link Phone.TTY_MODE_HCO}
+     * - {@link Phone.TTY_MODE_VCO}
+     *
+     * {@hide}
+     */
+    public static final String TTY_PREFFERED_MODE = "ttyPreferredMode";
 }