am 191f412e: am d1ee2e3a: Merge "Send telephony notifications to appropriate users." into lmp-dev

* commit '191f412ed2fb03c895e9af9385292efcb34db0f7':
  Send telephony notifications to appropriate users.
diff --git a/src/com/android/phone/INetworkQueryService.aidl b/src/com/android/phone/INetworkQueryService.aidl
index 749163c..0733d73 100644
--- a/src/com/android/phone/INetworkQueryService.aidl
+++ b/src/com/android/phone/INetworkQueryService.aidl
@@ -34,12 +34,21 @@
      * that will be sent upon query completion.
      */
     void startNetworkQuery(in INetworkQueryServiceCallback cb);
- 
+
     /**
      * Tells the service that the requested query is to be ignored.
-     * This may not do anything for the Query request in the 
+     * This may not do anything for the Query request in the
      * underlying RIL, but it ensures that the callback is removed
      * from the list of notifications.
      */
     void stopNetworkQuery(in INetworkQueryServiceCallback cb);
+
+    /**
+     * Tells the service to unregister the network query callback.
+     * Will not attempt to stop an ongoing network query.
+     * Functionally may be the same as stopNetworkQuery since that
+     * function also does not stop a query request in the underlying
+     * RIL.
+     */
+    void unregisterCallback(in INetworkQueryServiceCallback cb);
 }
diff --git a/src/com/android/phone/NetworkQueryService.java b/src/com/android/phone/NetworkQueryService.java
index be8c78e..77f3720 100644
--- a/src/com/android/phone/NetworkQueryService.java
+++ b/src/com/android/phone/NetworkQueryService.java
@@ -34,20 +34,20 @@
 
 /**
  * Service code used to assist in querying the network for service
- * availability.   
+ * availability.
  */
 public class NetworkQueryService extends Service {
     // debug data
     private static final String LOG_TAG = "NetworkQuery";
-    private static final boolean DBG = false;
+    private static final boolean DBG = true;
 
     // static events
-    private static final int EVENT_NETWORK_SCAN_COMPLETED = 100; 
-    
-    // static states indicating the query status of the service 
+    private static final int EVENT_NETWORK_SCAN_COMPLETED = 100;
+
+    // static states indicating the query status of the service
     private static final int QUERY_READY = -1;
     private static final int QUERY_IS_RUNNING = -2;
-    
+
     // error statuses that will be retured in the callback.
     public static final int QUERY_OK = 0;
     public static final int QUERY_EXCEPTION = 1;
@@ -142,24 +142,31 @@
             // currently we just unregister the callback, since there is 
             // no way to tell the RIL to terminate the query request.  
             // This means that the RIL may still be busy after the stop 
-            // request was made, but the state tracking logic ensures 
-            // that the delay will only last for 1 request even with 
-            // repeated button presses in the NetworkSetting activity. 
+            // request was made, but the state tracking logic ensures
+            // that the delay will only last for 1 request even with
+            // repeated button presses in the NetworkSetting activity.
+            unregisterCallback(cb);
+        }
+
+        /**
+         * Unregisters the callback without impacting an underlying query.
+         */
+        public void unregisterCallback(INetworkQueryServiceCallback cb) {
             if (cb != null) {
                 synchronized (mCallbacks) {
                     if (DBG) log("unregistering callback " + cb.getClass().toString());
                     mCallbacks.unregister(cb);
                 }
-            }            
+            }
         }
     };
-    
+
     @Override
     public void onCreate() {
         mState = QUERY_READY;
         mPhone = PhoneFactory.getDefaultPhone();
     }
-    
+
     /**
      * Required for service implementation.
      */
diff --git a/src/com/android/phone/NetworkSetting.java b/src/com/android/phone/NetworkSetting.java
index 4bd02cf..5925b0f 100644
--- a/src/com/android/phone/NetworkSetting.java
+++ b/src/com/android/phone/NetworkSetting.java
@@ -51,7 +51,7 @@
         implements DialogInterface.OnCancelListener {
 
     private static final String LOG_TAG = "phone";
-    private static final boolean DBG = false;
+    private static final boolean DBG = true;
 
     private static final int EVENT_NETWORK_SCAN_COMPLETED = 100;
     private static final int EVENT_NETWORK_SELECTION_DONE = 200;
@@ -106,6 +106,10 @@
                         if (DBG) log("manual network selection: succeeded!");
                         displayNetworkSelectionSucceeded();
                     }
+
+                    // update the phone in case replaced as part of selection
+                    mPhone = PhoneGlobals.getPhone();
+
                     break;
                 case EVENT_AUTO_SELECT_DONE:
                     if (DBG) log("hideProgressPanel");
@@ -118,7 +122,7 @@
                         // "auto select" is always trigged in foreground, so "auto select" dialog
                         //  should be shown when "auto select" is trigged. Should NOT get
                         // this exception, and Log it.
-                        Log.w(LOG_TAG, "[NetworksList] Fail to dismiss auto select dialog", e);
+                        Log.w(LOG_TAG, "[NetworksList] Fail to dismiss auto select dialog ", e);
                     }
                     getPreferenceScreen().setEnabled(true);
 
@@ -130,6 +134,10 @@
                         if (DBG) log("automatic network selection: succeeded!");
                         displayNetworkSelectionSucceeded();
                     }
+
+                    // update the phone in case replaced as part of selection
+                    mPhone = PhoneGlobals.getPhone();
+
                     break;
             }
 
@@ -212,7 +220,7 @@
         try {
             mNetworkQueryService.stopNetworkQuery(mCallback);
         } catch (RemoteException e) {
-            throw new RuntimeException(e);
+            log("onCancel: exception from stopNetworkQuery " + e);
         }
         finish();
     }
@@ -274,6 +282,13 @@
      */
     @Override
     protected void onDestroy() {
+        try {
+            // used to un-register callback
+            mNetworkQueryService.unregisterCallback(mCallback);
+        } catch (RemoteException e) {
+            log("onDestroy: exception from unregisterCallback " + e);
+        }
+
         if (!mUnavailable) {
             // unbind the service.
             unbindService(mNetworkQueryServiceConnection);
@@ -389,6 +404,14 @@
         try {
             mNetworkQueryService.startNetworkQuery(mCallback);
         } catch (RemoteException e) {
+            log("loadNetworksList: exception from startNetworkQuery " + e);
+            if (mIsForeground) {
+                try {
+                    dismissDialog(DIALOG_NETWORK_LIST_LOAD);
+                } catch (IllegalArgumentException e1) {
+                    // do nothing
+                }
+            }
         }
 
         displayEmptyNetworkList(false);
@@ -404,10 +427,16 @@
     private void networksListLoaded(List<OperatorInfo> result, int status) {
         if (DBG) log("networks list loaded");
 
+        // used to un-register callback
+        try {
+            mNetworkQueryService.unregisterCallback(mCallback);
+        } catch (RemoteException e) {
+            log("networksListLoaded: exception from unregisterCallback " + e);
+        }
+
         // update the state of the preferences.
         if (DBG) log("hideProgressPanel");
 
-
         // Always try to dismiss the dialog because activity may
         // be moved to background after dialog is shown.
         try {
@@ -416,7 +445,7 @@
             // It's not a error in following scenario, we just ignore it.
             // "Load list" dialog will not show, if NetworkQueryService is
             // connected after this activity is moved to background.
-            if (DBG) log("Fail to dismiss network load list dialog");
+            if (DBG) log("Fail to dismiss network load list dialog " + e);
         }
 
         getPreferenceScreen().setEnabled(true);
diff --git a/src/com/android/phone/TimeConsumingPreferenceActivity.java b/src/com/android/phone/TimeConsumingPreferenceActivity.java
index 19c4dda..bab9469 100644
--- a/src/com/android/phone/TimeConsumingPreferenceActivity.java
+++ b/src/com/android/phone/TimeConsumingPreferenceActivity.java
@@ -101,7 +101,7 @@
                 default:
                     msgId = R.string.exception_error;
                     // The error is not recoverable on dialog exit.
-                    builder.setPositiveButton(R.string.close_dialog, mDismissAndFinish);
+                    builder.setPositiveButton(R.string.close_dialog, mDismiss);
                     break;
             }
 
diff --git a/src/com/android/services/telephony/CdmaConnection.java b/src/com/android/services/telephony/CdmaConnection.java
index 1915fe0..ddd732b 100644
--- a/src/com/android/services/telephony/CdmaConnection.java
+++ b/src/com/android/services/telephony/CdmaConnection.java
@@ -27,6 +27,7 @@
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.Connection;
+import com.android.internal.telephony.imsphone.ImsPhoneConnection;
 import com.android.internal.telephony.Phone;
 import com.android.phone.Constants;
 
@@ -205,6 +206,11 @@
      * Read the settings to determine which type of DTMF method this CDMA phone calls.
      */
     private boolean useBurstDtmf() {
+        boolean isImsCall = getOriginalConnection() instanceof ImsPhoneConnection;
+        if (isImsCall) {
+            Log.d(this,"in ims call, return false");
+            return false;
+        }
         int dtmfTypeSetting = Settings.System.getInt(
                 getPhone().getContext().getContentResolver(),
                 Settings.System.DTMF_TONE_TYPE_WHEN_DIALING,
diff --git a/src/com/android/services/telephony/TtyManager.java b/src/com/android/services/telephony/TtyManager.java
index f3f11f4..6c8a495 100644
--- a/src/com/android/services/telephony/TtyManager.java
+++ b/src/com/android/services/telephony/TtyManager.java
@@ -34,6 +34,7 @@
     private final TtyBroadcastReceiver mReceiver = new TtyBroadcastReceiver();
     private final Phone mPhone;
     private int mTtyMode;
+    private int mUiTtyMode = -1;
 
     private final Handler mHandler = new Handler() {
         @Override
@@ -73,6 +74,7 @@
 
         IntentFilter intentFilter = new IntentFilter(
                 TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
+        intentFilter.addAction(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
         context.registerReceiver(mReceiver, intentFilter);
 
         int ttyMode = TelecomManager.TTY_MODE_OFF;
@@ -81,6 +83,7 @@
             ttyMode = telecomManager.getCurrentTtyMode();
         }
         updateTtyMode(ttyMode);
+        updateUiTtyMode(ttyMode);
     }
 
     private void updateTtyMode(int ttyMode) {
@@ -90,6 +93,16 @@
                 mHandler.obtainMessage(MSG_SET_TTY_MODE_RESPONSE));
     }
 
+    private void updateUiTtyMode(int ttyMode) {
+        Log.i(this, "updateUiTtyMode %d -> %d", mUiTtyMode, ttyMode);
+        if(mUiTtyMode != ttyMode) {
+            mUiTtyMode = ttyMode;
+            mPhone.setUiTTYMode(telecomModeToPhoneMode(ttyMode), null);
+        } else {
+           Log.i(this, "ui tty mode didnt change");
+        }
+    }
+
     private final class TtyBroadcastReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -99,6 +112,10 @@
                 int ttyMode = intent.getIntExtra(
                         TelecomManager.EXTRA_CURRENT_TTY_MODE, TelecomManager.TTY_MODE_OFF);
                 updateTtyMode(ttyMode);
+            } else if (action.equals(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED)) {
+                int newPreferredTtyMode = intent.getIntExtra(
+                        TelecomManager.EXTRA_TTY_PREFERRED_MODE, TelecomManager.TTY_MODE_OFF);
+                updateUiTtyMode(newPreferredTtyMode);
             }
         }
     }