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

Commit e8ac034b authored by pkanwar's avatar pkanwar
Browse files

resolve merge conflicts of fa4d17b5 to oc-dev-plus-aosp

BUG: 35606429
Test: manual

Change-Id: Ic0c0aa2cfb5e72ac8eb810b92fa29e0777cb7cd1
parents 72edf508 fa4d17b5
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CONTROL_INCALL_EXPERIENCE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
@@ -178,6 +179,16 @@
            </intent-filter>
          </activity>

        <activity android:name="com.android.server.telecom.testapps.TestCertActivity"
                android:label="@string/KeyUiAppLabel"
                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"
+18 −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.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"/>
+36 −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/text"
        android:inputType="text"
        android:layout_width="200dp"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/get_key_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/getKeyButton" />
     <ListView
        android:id="@+id/keylist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@

    <string name="placeUssdButton">Send USSD</string>

    <string name="KeyUiAppLabel">Get Key UI</string>

    <string name="getKeyButton">Get Key Json</string>

    <!-- String for button in SelfManagedCallingActivity. -->
    <string name="checkIfPermittedBeforeCallingButton">Check if calls permitted before calling</string>

+229 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */
package com.android.server.telecom.testapps;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.ImsiEncryptionInfo;
import android.text.TextUtils;
import android.util.Log;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;

import android.util.Base64;

public class TestCertActivity extends Activity {

    private EditText mCertUrlView;
    public static final String LOG_TAG = "TestCertActivity";

    private ProgressDialog progressDialog;
    private ArrayList<String> keyList = new ArrayList<String>();

    // URL to get the json
    private String mURL = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testcert_main);
        findViewById(R.id.get_key_button).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                new GetKeys().execute();
            }
        });

        mCertUrlView = (EditText) findViewById(R.id.text);
        mCertUrlView.setText(mURL);
    }

    /**
     * Class to get json by making HTTP call
     */
    private class GetKeys extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialog = new ProgressDialog(TestCertActivity.this);
            progressDialog.setMessage("Downloading...");
            progressDialog.setCancelable(false);
            progressDialog.show();
        }

        public String getCertificateList() {
            String response = null;
            String mURL = mCertUrlView.getText().toString();
            try {
                URL url = new URL(mURL);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                // read the response
                InputStream in = new BufferedInputStream(conn.getInputStream());
                response = convertToString(in);
            } catch (ProtocolException e) {
                Log.e(LOG_TAG, "ProtocolException: " + e.getMessage());
            } catch (MalformedURLException e) {
                Log.e(LOG_TAG, "MalformedURLException: " + e.getMessage());
            } catch (IOException e) {
                Log.e(LOG_TAG, "IOException: " + e.getMessage());
            } catch (Exception e) {
                Log.e(LOG_TAG, "Exception: " + e.getMessage());
            }
            return response;
        }

        private String convertToString(InputStream is) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();

            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append('\n');
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }

        private void savePublicKey(String key, int type, String identifier) {
            byte[] keyBytes = Base64.decode(key.getBytes(), Base64.DEFAULT);
            final TelephonyManager telephonyManager =
                    (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

            String mcc = "";
            String mnc = "";
            String networkOperator = telephonyManager.getNetworkOperator();

            if (!TextUtils.isEmpty(networkOperator)) {
                mcc = networkOperator.substring(0, 3);
                mnc = networkOperator.substring(3);
                Log.i(LOG_TAG, "using values for mnc, mcc: " + mnc + "," + mcc);
            }

            ImsiEncryptionInfo imsiEncryptionInfo = new ImsiEncryptionInfo(mcc,
                    mnc, type, identifier, keyBytes, new Date());
            telephonyManager.setCarrierInfoForImsiEncryption(imsiEncryptionInfo);
            keyList.add(imsiEncryptionInfo.getKeyType() + "," +
                    imsiEncryptionInfo.getKeyIdentifier());
            Log.i(LOG_TAG,"calling telephonymanager complete");
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            // Making a request to url and getting response
            String jsonStr = getCertificateList();
            Log.d(LOG_TAG, "Response from url: " + jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);
                    // Getting JSON Array node
                    JSONArray certificates = jsonObj.getJSONArray("certificates");

                    // looping through the certificates
                    for (int i = 0; i < certificates.length(); i++) {
                        JSONObject cert = certificates.getJSONObject(i);
                        String key = cert.getString("key");
                        int type = cert.getInt("type");
                        String identifier = cert.getString("identifier");
                        savePublicKey(key, type, identifier);
                    }
                } catch (final JSONException e) {
                    Log.e(LOG_TAG, "Json parsing error: " + e.getMessage());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "Json parsing error: " + e.getMessage(),
                                    Toast.LENGTH_LONG)
                                    .show();
                        }
                    });
                }
            } else {
                Log.e(LOG_TAG, "Unable to get JSON from server " + mURL);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(),
                                "Unable to get JSON from server!",
                                Toast.LENGTH_LONG)
                                .show();
                    }
                });
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {

            super.onPostExecute(result);
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            ListView listView = (ListView) findViewById(R.id.keylist);
            ArrayAdapter arrayAdapter =
                    new ArrayAdapter(TestCertActivity.this, R.layout.key_list, keyList);
            listView.setAdapter(arrayAdapter);
        }
    }
}