Merge "Add CallService.abort in telephony." into master-nova
diff --git a/src/com/android/phone/OutgoingCallBroadcaster.java b/src/com/android/phone/OutgoingCallBroadcaster.java
index a27ea57..fe1c2ab 100644
--- a/src/com/android/phone/OutgoingCallBroadcaster.java
+++ b/src/com/android/phone/OutgoingCallBroadcaster.java
@@ -46,30 +46,35 @@
 import com.android.internal.telephony.TelephonyCapabilities;
 
 /**
- * OutgoingCallBroadcaster receives CALL and CALL_PRIVILEGED Intents, and
- * broadcasts the ACTION_NEW_OUTGOING_CALL intent which allows other
- * applications to monitor, redirect, or prevent the outgoing call.
-
+ * OutgoingCallBroadcaster receives CALL and CALL_PRIVILEGED Intents, and broadcasts the
+ * ACTION_NEW_OUTGOING_CALL intent. ACTION_NEW_OUTGOING_CALL is an ordered broadcast intent which
+ * contains the phone number being dialed. Applications can use this intent to (1) see which numbers
+ * are being dialed, (2) redirect a call (change the number being dialed), or (3) prevent a call
+ * from being placed.
+ *
  * After the other applications have had a chance to see the
  * ACTION_NEW_OUTGOING_CALL intent, it finally reaches the
  * {@link OutgoingCallReceiver}, which passes the (possibly modified)
  * intent on to the {@link SipCallOptionHandler}, which will
  * ultimately start the call using the CallController.placeCall() API.
  *
- * Emergency calls and calls where no number is present (like for a CDMA
- * "empty flash" or a nonexistent voicemail number) are exempt from being
- * broadcast.
+ * Calls where no number is present (like for a CDMA "empty flash" or a nonexistent voicemail
+ * number) are exempt from being broadcast.
+ * Calls to emergency numbers are still broadcast for informative purposes. The call is placed
+ * prior to sending ACTION_NEW_OUTGOING_CALL and cannot be redirected nor prevented.
  */
 public class OutgoingCallBroadcaster extends Activity
         implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
 
-    private static final String PERMISSION = android.Manifest.permission.PROCESS_OUTGOING_CALLS;
     private static final String TAG = "OutgoingCallBroadcaster";
     private static final boolean DBG =
             (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
     // Do not check in with VDBG = true, since that may write PII to the system log.
     private static final boolean VDBG = false;
 
+    /** Required permission for any app that wants to consume ACTION_NEW_OUTGOING_CALL. */
+    private static final String PERMISSION = android.Manifest.permission.PROCESS_OUTGOING_CALLS;
+
     public static final String ACTION_SIP_SELECT_PHONE = "com.android.phone.SIP_SELECT_PHONE";
     public static final String EXTRA_ALREADY_CALLED = "android.phone.extra.ALREADY_CALLED";
     public static final String EXTRA_ORIGINAL_URI = "android.phone.extra.ORIGINAL_URI";
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 5fe8cd4..13b1cf2 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -89,10 +89,12 @@
     private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
     private static final int CMD_NV_RESET_CONFIG = 19;
     private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
-    private static final int CMD_SET_RADIO_MODE = 21;
-    private static final int EVENT_SET_RADIO_MODE_DONE = 22;
-    private static final int CMD_SEND_ENVELOPE = 23;
-    private static final int EVENT_SEND_ENVELOPE_DONE = 24;
+    private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
+    private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
+    private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
+    private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
+    private static final int CMD_SEND_ENVELOPE = 25;
+    private static final int EVENT_SEND_ENVELOPE_DONE = 26;
 
     /** The singleton instance. */
     private static PhoneInterfaceManager sInstance;
@@ -391,6 +393,44 @@
                     handleNullReturnEvent(msg, "nvResetConfig");
                     break;
 
+                case CMD_GET_PREFERRED_NETWORK_TYPE:
+                    request = (MainThreadRequest) msg.obj;
+                    onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
+                    mPhone.getPreferredNetworkType(onCompleted);
+                    break;
+
+                case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
+                    ar = (AsyncResult) msg.obj;
+                    request = (MainThreadRequest) ar.userObj;
+                    if (ar.exception == null && ar.result != null) {
+                        request.result = ar.result;     // Integer
+                    } else {
+                        request.result = -1;
+                        if (ar.result == null) {
+                            loge("getPreferredNetworkType: Empty response");
+                        } else if (ar.exception instanceof CommandException) {
+                            loge("getPreferredNetworkType: CommandException: " +
+                                    ar.exception);
+                        } else {
+                            loge("getPreferredNetworkType: Unknown exception");
+                        }
+                    }
+                    synchronized (request) {
+                        request.notifyAll();
+                    }
+                    break;
+
+                case CMD_SET_PREFERRED_NETWORK_TYPE:
+                    request = (MainThreadRequest) msg.obj;
+                    onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
+                    int networkType = (Integer) request.argument;
+                    mPhone.setPreferredNetworkType(networkType, onCompleted);
+                    break;
+
+                case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
+                    handleNullReturnEvent(msg, "setPreferredNetworkType");
+                    break;
+
                 default:
                     Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
                     break;
@@ -1315,4 +1355,36 @@
         if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
         return success;
     }
+
+    /**
+     * Get the preferred network type.
+     * Used for device configuration by some CDMA operators.
+     *
+     * @return the preferred network type, defined in RILConstants.java.
+     */
+    @Override
+    public int getPreferredNetworkType() {
+        enforceModifyPermission();
+        if (DBG) log("getPreferredNetworkType");
+        int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null);
+        int networkType = (result != null ? result[0] : -1);
+        if (DBG) log("getPreferredNetworkType: " + networkType);
+        return networkType;
+    }
+
+    /**
+     * Set the preferred network type.
+     * Used for device configuration by some CDMA operators.
+     *
+     * @param networkType the preferred network type, defined in RILConstants.java.
+     * @return true on success; false on any failure.
+     */
+    @Override
+    public boolean setPreferredNetworkType(int networkType) {
+        enforceModifyPermission();
+        if (DBG) log("setPreferredNetworkType: type " + networkType);
+        Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
+        if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
+        return success;
+    }
 }
diff --git a/src/com/android/services/telephony/BaseTelephonyCallService.java b/src/com/android/services/telephony/BaseTelephonyCallService.java
index f8c7804..a1b1d7c 100644
--- a/src/com/android/services/telephony/BaseTelephonyCallService.java
+++ b/src/com/android/services/telephony/BaseTelephonyCallService.java
@@ -17,6 +17,7 @@
 package com.android.services.telephony;
 
 import android.net.Uri;
+import android.os.Bundle;
 import android.os.RemoteException;
 import android.telecomm.CallInfo;
 import android.telecomm.CallService;
@@ -58,7 +59,7 @@
 
     /** {@inheritDoc} */
     @Override
-    public void setIncomingCallId(String callId) {
+    public void setIncomingCallId(String callId, Bundle extras) {
         // Incoming calls not implemented yet.
     }