Provide an API to make USSD calls and read the responses.
Test: will be added in a subsequent CL.
Bug: 30973910
Change-Id: Ie92441b6435775d9b6d74f9a0777064d9839d6dc
diff --git a/testapps/AndroidManifest.xml b/testapps/AndroidManifest.xml
index 7327e43..c1eb258 100644
--- a/testapps/AndroidManifest.xml
+++ b/testapps/AndroidManifest.xml
@@ -146,5 +146,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <activity android:name="com.android.server.telecom.testapps.TestUssdActivity"
+ android:label="@string/UssdUiAppLabel"
+ android:launchMode="singleInstance">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
diff --git a/testapps/res/layout/testussd_main.xml b/testapps/res/layout/testussd_main.xml
new file mode 100644
index 0000000..b4d67b0
--- /dev/null
+++ b/testapps/res/layout/testussd_main.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+ <EditText
+ android:id="@+id/number"
+ android:inputType="number"
+ android:layout_width="200dp"
+ android:layout_height="wrap_content" />
+ <Button
+ android:id="@+id/place_ussd_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/placeUssdButton" />
+</LinearLayout>
diff --git a/testapps/res/values/donottranslate_strings.xml b/testapps/res/values/donottranslate_strings.xml
index 599d5cc..83d1ef3 100644
--- a/testapps/res/values/donottranslate_strings.xml
+++ b/testapps/res/values/donottranslate_strings.xml
@@ -45,4 +45,8 @@
<string name="holdButton">Hold</string>
<string name="inCallUiAppLabel">Test InCall UI</string>
+
+ <string name="UssdUiAppLabel">Test Ussd UI</string>
+
+ <string name="placeUssdButton">Send USSD</string>
</resources>
diff --git a/testapps/src/com/android/server/telecom/testapps/TestUssdActivity.java b/testapps/src/com/android/server/telecom/testapps/TestUssdActivity.java
new file mode 100644
index 0000000..3b1f4e9
--- /dev/null
+++ b/testapps/src/com/android/server/telecom/testapps/TestUssdActivity.java
@@ -0,0 +1,80 @@
+package com.android.server.telecom.testapps;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+import android.telephony.TelephonyManager;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.EditText;
+import android.widget.Toast;
+
+public class TestUssdActivity extends Activity {
+
+ private EditText mUssdNumberView;
+ private static Context context;
+ public static final String LOG_TAG = "TestUssdActivity";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ TestUssdActivity.context = getApplicationContext();
+
+ setContentView(R.layout.testussd_main);
+ findViewById(R.id.place_ussd_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+
+ placeUssdRequest();
+ }
+ });
+
+ mUssdNumberView = (EditText) findViewById(R.id.number);
+ }
+
+ public static final class OnReceiveUssdResponseCallback extends
+ TelephonyManager.OnReceiveUssdResponseCallback {
+
+ OnReceiveUssdResponseCallback() {
+ }
+
+ public void onReceiveUssdResponse(String req, CharSequence message) {
+ Log.i(LOG_TAG, "USSD Success:::" + req + "," + message);
+ showToast("USSD Response Successly received for code:" + req + "," + message);
+ }
+
+ public void onReceiveUssdResponseFailed(String req, int resultCode) {
+ Log.i(LOG_TAG, "USSD Fail:::" + req + "," + resultCode);
+ showToast("USSD Response failed for code:" + req + "," + resultCode);
+ }
+ }
+
+ private void placeUssdRequest() {
+
+ String mUssdNumber = mUssdNumberView.getText().toString();
+ if (mUssdNumber.equals("") || mUssdNumber == null) {
+ mUssdNumber = "932";
+ }
+ mUssdNumber = "#" + mUssdNumber + "#";
+ final TelephonyManager telephonyManager =
+ (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+ try {
+ Handler h = new Handler(Looper.getMainLooper());
+ OnReceiveUssdResponseCallback receiveUssdResponseCallback =
+ new OnReceiveUssdResponseCallback();
+
+ telephonyManager.sendUssdRequest(mUssdNumber, receiveUssdResponseCallback, h);
+
+ } catch (SecurityException e) {
+ showToast("Permission check failed");
+ return;
+ }
+ }
+
+ private static void showToast(String message) {
+ Toast.makeText(TestUssdActivity.context, message, Toast.LENGTH_SHORT).show();
+ }
+}
\ No newline at end of file