Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c51fcb97 authored by pkanwar's avatar pkanwar Committed by Pankaj Kanwar
Browse files

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

Test: will be added in a subsequent CL.
Bug: 30973910
Change-Id: Ie92441b6435775d9b6d74f9a0777064d9839d6dc
Merged-In: Ie92441b6435775d9b6d74f9a0777064d9839d6dc
parent 91d5655e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -168,6 +168,16 @@
            </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>

        <activity android:name="com.android.server.telecom.testapps.SelfManagedCallingActivity"
                  android:label="@string/selfManagedCallingActivityLabel"
                  android:process="com.android.server.telecom.testapps.SelfMangingCallingApp"
+32 −0
Original line number Diff line number Diff line
<?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>
+3 −0
Original line number Diff line number Diff line
@@ -88,4 +88,7 @@
        <item>The FCC has mandated that I respond... I will do so begrudgingly</item>
        <item>😂😂😂💯</item>
    </string-array>

    <string name="UssdUiAppLabel">Test Ussd UI</string>
    <string name="placeUssdButton">Send USSD</string>
</resources>
+80 −0
Original line number Diff line number Diff line
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