Provide an API to make USSD calls and read the responses.

Test: will be added in a subsequent CL.
Bug: 30973910
Change-Id: I59ac8eb2ea4e63e72a3807f59d7ac65f034dc6fe
Merged-In: I59ac8eb2ea4e63e72a3807f59d7ac65f034dc6fe
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 04ee155..395dd88 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -319,7 +319,7 @@
         <!-- "Mobile network settings" screen, used on both
              non-voice-capable tablets and regular phone devices. -->
         <activity android:name="MobileNetworkSettings"
-            android:label="@string/settings_label"
+            android:label="@string/mobile_networks"
             android:theme="@style/NetworkOperatorsSettingsTheme">
             <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 38bfa50..9d16bad 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -153,6 +153,7 @@
     private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
     private static final int CMD_GET_ALLOWED_CARRIERS = 45;
     private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
+    private static final int CMD_HANDLE_USSD_REQUEST = 47;
     private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
     private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
 
@@ -264,6 +265,22 @@
             IccAPDUArgument iccArgument;
 
             switch (msg.what) {
+                 case CMD_HANDLE_USSD_REQUEST: {
+                     request = (MainThreadRequest) msg.obj;
+                     final Phone phone = getPhoneFromRequest(request);
+                     Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
+                     String ussdRequest =  ussdObject.first;
+                     ResultReceiver wrappedCallback = ussdObject.second;
+                     request.result = phone != null ?
+                             phone.handleUssdRequest(ussdRequest, wrappedCallback)
+                             :false;
+                     // Wake up the requesting thread
+                     synchronized (request) {
+                         request.notifyAll();
+                     }
+                     break;
+                }
+
                 case CMD_HANDLE_PIN_MMI: {
                     request = (MainThreadRequest) msg.obj;
                     final Phone phone = getPhoneFromRequest(request);
@@ -1527,6 +1544,17 @@
         return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
     }
 
+    public void handleUssdRequest(String ussdRequest, ResultReceiver wrappedCallback) {
+      enforceCallPermission();
+      int subId = getDefaultSubscription();
+      if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+          return;
+      }
+      Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
+      sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
+    };
+
+
     public boolean handlePinMmiForSubscriber(int subId, String dialString) {
         enforceModifyPermission();
         if (!SubscriptionManager.isValidSubscriptionId(subId)) {