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

Commit 9821b664 authored by Paul Hu's avatar Paul Hu Committed by Automerger Merge Worker
Browse files

Merge "Forward the ResultReceiver to Tethering Entitlement app" into rvc-dev am: 37318d03

Change-Id: I18618155c37e90cb08337f78a8000ccbc227419b
parents 4bd86eba 37318d03
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -21,12 +21,16 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.TetheringConstants;
import android.net.TetheringManager;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.os.UserHandle;
import android.telephony.SubscriptionManager;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

import com.android.settings.Utils;

/**
@@ -36,17 +40,18 @@ import com.android.settings.Utils;
 * with {@link android.permission.TETHER_PRIVILEGED}.
 */
public class TetherProvisioningActivity extends Activity {
    private static final int PROVISION_REQUEST = 0;
    private static final String TAG = "TetherProvisioningAct";
    private static final String EXTRA_TETHER_TYPE = "TETHER_TYPE";
    private static final String EXTRA_SUBID = "subId";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private ResultReceiver mResultReceiver;
    @VisibleForTesting
    static final int PROVISION_REQUEST = 0;
    @VisibleForTesting
    static final String EXTRA_SUBID = "subId";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra(
                ConnectivityManager.EXTRA_PROVISION_CALLBACK);

@@ -58,16 +63,22 @@ public class TetherProvisioningActivity extends Activity {
        final int subId = SubscriptionManager.getActiveDataSubscriptionId();
        if (tetherSubId != subId) {
            Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId);
            mResultReceiver.send(TetheringManager.TETHER_ERROR_PROVISIONING_FAILED, null);
            finish();
            return;
        }
        String[] provisionApp = getIntent().getStringArrayExtra(
                TetheringConstants.EXTRA_RUN_PROVISION);
        if (provisionApp == null || provisionApp.length < 2) {
            final Resources res = Utils.getResourcesForSubId(this, subId);
        final String[] provisionApp = res.getStringArray(
            provisionApp = res.getStringArray(
                    com.android.internal.R.array.config_mobile_hotspot_provision_app);

        }
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName(provisionApp[0], provisionApp[1]);
        intent.putExtra(EXTRA_TETHER_TYPE, tetherType);
        intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
        intent.putExtra(ConnectivityManager.EXTRA_PROVISION_CALLBACK, mResultReceiver);
        if (DEBUG) {
            Log.d(TAG, "Starting provisioning app: " + provisionApp[0] + "." + provisionApp[1]);
        }
@@ -75,7 +86,7 @@ public class TetherProvisioningActivity extends Activity {
        if (getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
            Log.e(TAG, "Provisioning app is configured, but not available.");
            mResultReceiver.send(ConnectivityManager.TETHER_ERROR_PROVISION_FAILED, null);
            mResultReceiver.send(TetheringManager.TETHER_ERROR_PROVISIONING_FAILED, null);
            finish();
            return;
        }
@@ -89,8 +100,8 @@ public class TetherProvisioningActivity extends Activity {
        if (requestCode == PROVISION_REQUEST) {
            if (DEBUG) Log.d(TAG, "Got result from app: " + resultCode);
            int result = resultCode == Activity.RESULT_OK ?
                    ConnectivityManager.TETHER_ERROR_NO_ERROR :
                    ConnectivityManager.TETHER_ERROR_PROVISION_FAILED;
                    TetheringManager.TETHER_ERROR_NO_ERROR :
                    TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
            mResultReceiver.send(result, null);
            finish();
        }
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ android_test {
    ],

    static_libs: [
        "androidx.test.core",
        "androidx.test.rules",
        "androidx.test.espresso.core",
        "androidx.test.espresso.contrib-nodeps",
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="SettingsUnitTests.apk" />
        <option name="test-file-name" value="InstrumentedEntitlementApp.apk" />
    </target_preparer>

    <option name="test-tag" value="SettingsUnitTests" />
+19 −0
Original line number Diff line number Diff line
// Copyright (C) 2020 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.

android_test {
    name: "InstrumentedEntitlementApp",
    srcs: ["src/**/*.java"],
    test_suites: ["device-tests"],
}
+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
 * Copyright (C) 2020 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.
 -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.test.entitlement">

    <application>
        <activity android:name=".InstrumentedEntitlementActivity"
                  android:label="InstrumentedEntitlementActivity"
                  android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Loading