Automated import from //branches/cupcake/...@142924,142924
John Wang [Thu, 26 Mar 2009 16:27:16 +0000 (09:27 -0700)]
src/com/android/phone/CallFeaturesSetting.java
src/com/android/phone/PhoneUtils.java

index a342f11..bcc89a4 100644 (file)
@@ -740,6 +740,11 @@ public class CallFeaturesSetting extends PreferenceActivity
      * Helper function to set both the value and the summary of the CLIR preference.
      */
     private void setButtonCLIRValue (int value) {
+        
+        if (mButtonCLIR == null) {
+            return;
+        }
+        
         // first, set the value.
         mButtonCLIR.setValueIndex(value);
 
@@ -762,6 +767,11 @@ public class CallFeaturesSetting extends PreferenceActivity
     // called by syncCFUIState to do repetitive changes to UI button state.
     private void adjustCFbuttonState(EditPhoneNumberPreference epn,
             boolean isActive, int template, String number) {
+        
+        if (epn == null) {
+            return;
+        }
+        
         CharSequence summaryOn = "";
 
         if (isActive) {
@@ -805,6 +815,10 @@ public class CallFeaturesSetting extends PreferenceActivity
 
     // update the voicemail number from what we've recorded on the sim.
     private void updateVoiceNumberField() {
+        if (mSubMenuVoicemailSettings == null) {
+            return;
+        }
+        
         mOldVmNumber = mPhone.getVoiceMailNumber();
         if (mOldVmNumber == null) {
             mOldVmNumber = "";
@@ -1277,35 +1291,47 @@ public class CallFeaturesSetting extends PreferenceActivity
         // effect the dialog for each preference.  Also set the
         // dependencies between the child (CFB, CFNRy, CFNRc)
         // preferences and the CFU preference.
-        mButtonCFU.setParentActivity(this, CommandsInterface.CF_REASON_UNCONDITIONAL, this);
-        mButtonCFU.setDialogOnClosedListener(this);
-        mButtonCFU.setDialogTitle(R.string.labelCF);
-        mButtonCFU.setDialogMessage(R.string.messageCFU);
-
-        mButtonCFB.setParentActivity(this, CommandsInterface.CF_REASON_BUSY, this);
-        mButtonCFB.setDialogOnClosedListener(this);
-        mButtonCFB.setDependency(BUTTON_CFU_KEY);
-        mButtonCFB.setDialogTitle(R.string.labelCF);
-        mButtonCFB.setDialogMessage(R.string.messageCFB);
-
-        mButtonCFNRy.setParentActivity(this, CommandsInterface.CF_REASON_NO_REPLY, this);
-        mButtonCFNRy.setDialogOnClosedListener(this);
-        mButtonCFNRy.setDependency(BUTTON_CFU_KEY);
-        mButtonCFNRy.setDialogTitle(R.string.labelCF);
-        mButtonCFNRy.setDialogMessage(R.string.messageCFNRy);
-
-        mButtonCFNRc.setParentActivity(this, CommandsInterface.CF_REASON_NOT_REACHABLE, this);
-        mButtonCFNRc.setDialogOnClosedListener(this);
-        mButtonCFNRc.setDependency(BUTTON_CFU_KEY);
-        mButtonCFNRc.setDialogTitle(R.string.labelCF);
-        mButtonCFNRc.setDialogMessage(R.string.messageCFNRc);
-
-        mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
-        mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
-        mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
-
+        if (mButtonCFU != null){
+            mButtonCFU.setParentActivity(this, CommandsInterface.CF_REASON_UNCONDITIONAL, this);
+            mButtonCFU.setDialogOnClosedListener(this);
+            mButtonCFU.setDialogTitle(R.string.labelCF);
+            mButtonCFU.setDialogMessage(R.string.messageCFU);
+        }
+        
+        if (mButtonCFB != null) {
+            mButtonCFB.setParentActivity(this, CommandsInterface.CF_REASON_BUSY, this);
+            mButtonCFB.setDialogOnClosedListener(this);
+            mButtonCFB.setDependency(BUTTON_CFU_KEY);
+            mButtonCFB.setDialogTitle(R.string.labelCF);
+            mButtonCFB.setDialogMessage(R.string.messageCFB);
+        }
+        
+        if (mButtonCFNRy != null) {
+            mButtonCFNRy.setParentActivity(this, CommandsInterface.CF_REASON_NO_REPLY, this);
+            mButtonCFNRy.setDialogOnClosedListener(this);
+            mButtonCFNRy.setDependency(BUTTON_CFU_KEY);
+            mButtonCFNRy.setDialogTitle(R.string.labelCF);
+            mButtonCFNRy.setDialogMessage(R.string.messageCFNRy);
+        }
+        
+        if (mButtonCFNRc != null) {
+            mButtonCFNRc.setParentActivity(this, CommandsInterface.CF_REASON_NOT_REACHABLE, this);
+            mButtonCFNRc.setDialogOnClosedListener(this);
+            mButtonCFNRc.setDependency(BUTTON_CFU_KEY);
+            mButtonCFNRc.setDialogTitle(R.string.labelCF);
+            mButtonCFNRc.setDialogMessage(R.string.messageCFNRc);
+        }
+        
+        if (mSubMenuVoicemailSettings != null) {
+            mSubMenuVoicemailSettings.setParentActivity(this, VOICEMAIL_PREF_ID, this);
+            mSubMenuVoicemailSettings.setDialogOnClosedListener(this);
+            mSubMenuVoicemailSettings.setDialogTitle(R.string.voicemail_settings_number_label);
+        }
+        
         // set the listener for the CLIR list preference so we can issue CLIR commands.
-        mButtonCLIR.setOnPreferenceChangeListener(this);
+        if (mButtonCLIR != null ) {
+            mButtonCLIR.setOnPreferenceChangeListener(this);
+        }
 
         // create intent to bring up contact list
         mContactListIntent = new Intent(Intent.ACTION_GET_CONTENT);
@@ -1337,7 +1363,9 @@ public class CallFeaturesSetting extends PreferenceActivity
 
             // reset other button state
             setButtonCLIRValue(icicle.getInt(BUTTON_CLIR_KEY));
-            mButtonCW.setChecked(icicle.getBoolean(BUTTON_CW_KEY));
+            if (mButtonCW != null) {
+                mButtonCW.setChecked(icicle.getBoolean(BUTTON_CW_KEY));
+            }
 
             // set app state
             mAppState = (AppState) icicle.getSerializable(APP_STATE_KEY);
@@ -1369,12 +1397,24 @@ public class CallFeaturesSetting extends PreferenceActivity
         if (DBG) log("onSaveInstanceState: saving relevant UI state.");
 
         // save button state
-        outState.putInt(BUTTON_CLIR_KEY, mButtonCLIR.findIndexOfValue(mButtonCLIR.getValue()));
-        outState.putBoolean(BUTTON_CW_KEY, mButtonCW.isChecked());
-        outState.putBoolean(BUTTON_CFU_KEY, mButtonCFU.isToggled());
-        outState.putBoolean(BUTTON_CFB_KEY, mButtonCFB.isToggled());
-        outState.putBoolean(BUTTON_CFNRY_KEY, mButtonCFNRy.isToggled());
-        outState.putBoolean(BUTTON_CFNRC_KEY, mButtonCFNRc.isToggled());
+        if (mButtonCLIR != null) {
+            outState.putInt(BUTTON_CLIR_KEY, mButtonCLIR.findIndexOfValue(mButtonCLIR.getValue()));
+        }
+        if (mButtonCW != null) {
+            outState.putBoolean(BUTTON_CW_KEY, mButtonCW.isChecked());
+        }
+        if (mButtonCFU != null) {
+            outState.putBoolean(BUTTON_CFU_KEY, mButtonCFU.isToggled());
+        }
+        if (mButtonCFB != null) {
+            outState.putBoolean(BUTTON_CFB_KEY, mButtonCFB.isToggled());
+        }
+        if (mButtonCFNRy != null) {
+            outState.putBoolean(BUTTON_CFNRY_KEY, mButtonCFNRy.isToggled());
+        }
+        if (mButtonCFNRc != null) {
+            outState.putBoolean(BUTTON_CFNRC_KEY, mButtonCFNRc.isToggled());
+        }
 
         // save number state
         outState.putString(SUMMARY_CFU_KEY, mDialingNumCFU);
index d0432ef..c476598 100644 (file)
@@ -51,6 +51,13 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
+import com.android.internal.telephony.IExtendedNetworkService;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.content.ComponentName;
+import android.os.RemoteException;
+
+
 /**
  * Misc utilities for the Phone app.
  */
@@ -90,6 +97,11 @@ public class PhoneUtils {
     /** Phone state changed event*/
     private static final int PHONE_STATE_CHANGED = -1;
 
+    // Extended network service interface instance
+    private static IExtendedNetworkService mNwService = null;
+    // used to cancel MMI command after 15 seconds timeout for NWService requirement
+    private static Message mMmiTimeoutCbMsg = null;
+
     /**
      * Handler that tracks the connections and updates the value of the
      * Mute settings for each connection as needed.
@@ -148,6 +160,19 @@ public class PhoneUtils {
             }
         }
     }
+    
+
+    private static ServiceConnection ExtendedNetworkServiceConnection = new ServiceConnection() {
+        public void onServiceConnected(ComponentName name, IBinder iBinder) {
+            if (DBG) log("Extended NW onServiceConnected");
+            mNwService = IExtendedNetworkService.Stub.asInterface(iBinder);
+        }
+
+        public void onServiceDisconnected(ComponentName arg0) {
+            if (DBG) log("Extended NW onServiceDisconnected");
+            mNwService = null;
+        }    
+    };
 
     /**
      * Register the ConnectionHandler with the phone, to receive connection events
@@ -158,6 +183,12 @@ public class PhoneUtils {
         }
 
         phone.registerForPhoneStateChanged(mConnectionHandler, PHONE_STATE_CHANGED, phone);
+        // Extended NW service
+        Intent intent = new Intent("com.android.ussd.IExtendedNetworkService");
+        phone.getContext().bindService(intent, 
+                ExtendedNetworkServiceConnection, Context.BIND_AUTO_CREATE);
+        if (DBG) log("Extended NW bindService IExtendedNetworkService");
+
     }
 
     /** This class is never instantiated. */
@@ -317,7 +348,17 @@ public class PhoneUtils {
             // Presently, null is returned for MMI codes
             if (cn == null) {
                 if (DBG) log("dialed MMI code: " + number);
-                status = CALL_STATUS_DIALED_MMI;
+                status = CALL_STATUS_DIALED_MMI;   
+                // Set dialed MMI command to service
+                if (mNwService != null) {
+                    try {
+                        mNwService.setMmiString(number);
+                        if (DBG) log("Extended NW bindService setUssdString (" + number + ")");
+                    } catch (RemoteException e) {
+                        mNwService = null;
+                    }
+                }
+
             } else {
                 PhoneUtils.setAudioControlState(PhoneUtils.AUDIO_OFFHOOK);
 
@@ -450,6 +491,36 @@ public class PhoneUtils {
         //
         // Anything that is NOT a USSD request is a normal MMI request,
         // which will bring up a toast (desribed above).
+        // Optional code for Extended USSD running prompt
+        if (mNwService != null) {
+            if (DBG) log("running USSD code, displaying indeterminate progress.");
+            // create the indeterminate progress dialog and display it.
+            ProgressDialog pd = new ProgressDialog(context);
+            CharSequence textmsg = "";
+            try {
+                textmsg = mNwService.getMmiRunningText();
+                
+            } catch (RemoteException e) {
+                mNwService = null;
+                textmsg = context.getText(R.string.ussdRunning);            
+            }
+            if (DBG) log("Extended NW displayMMIInitiate (" + textmsg+ ")");
+            pd.setMessage(textmsg);
+            pd.setCancelable(false);
+            pd.setIndeterminate(true);
+            pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+            pd.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
+            pd.show();
+            // trigger a 15 seconds timeout to clear this progress dialog
+            mMmiTimeoutCbMsg = buttonCallbackMessage;
+            try {
+                mMmiTimeoutCbMsg.getTarget().sendMessageDelayed(buttonCallbackMessage, 15000);
+            } catch(NullPointerException e) {
+                mMmiTimeoutCbMsg = null;
+            }
+            return pd;              
+        }
+
         boolean isCancelable = (mmiCode != null) && mmiCode.isCancelable();
 
         if (!isCancelable) {
@@ -491,6 +562,16 @@ public class PhoneUtils {
         MmiCode.State state = mmiCode.getState();
 
         if (DBG) log("displayMMIComplete: state=" + state);
+        // Clear timeout trigger message
+        if(mMmiTimeoutCbMsg != null) {
+            try{
+                mMmiTimeoutCbMsg.getTarget().removeMessages(mMmiTimeoutCbMsg.what);
+                if (DBG) log("Extended NW displayMMIComplete removeMsg");
+            } catch (NullPointerException e) {
+            }
+            mMmiTimeoutCbMsg = null;
+        }
+
 
         switch (state) {
             case PENDING:
@@ -560,6 +641,18 @@ public class PhoneUtils {
             if (state != MmiCode.State.PENDING) {
                 if (DBG) log("MMI code has finished running.");
 
+                // Replace response message with Extended Mmi wording
+                if (mNwService != null) {
+                    try {
+                        text = mNwService.getUserMessage(text);
+                    } catch (RemoteException e) {
+                        mNwService = null;
+                    }
+                    if (DBG) log("Extended NW displayMMIInitiate (" + text + ")");
+                    if (text == null)
+                        return;
+                }
+
                 // displaying system alert dialog on the screen instead of
                 // using another activity to display the message.  This
                 // places the message at the forefront of the UI.
@@ -690,6 +783,17 @@ public class PhoneUtils {
             }
         }
 
+        //clear timeout message and pre-set MMI command
+        if (mNwService != null) {
+            try {
+                mNwService.clearMmiString();
+            } catch (RemoteException e) {
+                mNwService = null;
+            }            
+        }
+        if (mMmiTimeoutCbMsg != null) {
+            mMmiTimeoutCbMsg = null;
+        }
         return canceled;
     }