Get entitlement configuration from intent extra

Tethering resource configuration is move from framwork to tethering
module. The resource would not be accessible from outside of tethering
module.
List the replacements of framework resources usage and intent extra:
1. R.string.config_mobile_hotspot_provision_response
    --> android.net.extra.TETHER_PROVISIONING_RESPONSE.
2. R.string.config_mobile_hotspot_provision_app_no_ui
    --> android.net.extra.TETHER_UI_PROVISIONING_APP_NAME
3. R.array.config_mobile_hotspot_provision_app
    --> android.net.extra.TETHER_SILENT_PROVISIONING_ACTION
Besides, the current active subId would put in
android.net.extra.TETHER_SUBID

Note: They are not APIs because of API freeze. Now both tethering module
and Settings define these strings independently. Will replace hard code
string as tethering module-lib APIs in b/159085857.

Also move the entitlement response intent registeration from onCreated
to onStartCommand, this can avoid wrong intent registeration if subId
changed between onCreate and when the intent arrived.

Bug: 146918263
Test: atest TetherServiceTest
      atest TetherProvisioningActivityTest

Change-Id: I3d06df01302a9c1f0893712d9250fe394dc66588
This commit is contained in:
markchien
2020-06-07 17:56:02 +08:00
committed by Mark Chien
parent e5c9b113b6
commit e22bd7a2e8
4 changed files with 119 additions and 73 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.network;
import static android.net.TetheringConstants.EXTRA_ADD_TETHER_TYPE;
import static android.net.TetheringConstants.EXTRA_PROVISION_CALLBACK;
import static android.net.TetheringConstants.EXTRA_RUN_PROVISION;
import static android.net.TetheringManager.TETHERING_INVALID;
import static android.net.TetheringManager.TETHER_ERROR_NO_ERROR;
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
@@ -28,7 +27,6 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.os.UserHandle;
@@ -37,8 +35,6 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.Utils;
/**
* Activity which acts as a proxy to the tether provisioning app for sanity checks and permission
* restrictions. Specifically, the provisioning apps require
@@ -53,7 +49,10 @@ public class TetherProvisioningActivity extends Activity {
@VisibleForTesting
static final int PROVISION_REQUEST = 0;
@VisibleForTesting
static final String EXTRA_SUBID = "subId";
static final String EXTRA_TETHER_SUBID = "android.net.extra.TETHER_SUBID";
@VisibleForTesting
public static final String EXTRA_TETHER_UI_PROVISIONING_APP_NAME =
"android.net.extra.TETHER_UI_PROVISIONING_APP_NAME";
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -62,7 +61,8 @@ public class TetherProvisioningActivity extends Activity {
final int tetherType = getIntent().getIntExtra(EXTRA_ADD_TETHER_TYPE, TETHERING_INVALID);
final int tetherSubId = getIntent().getIntExtra(EXTRA_SUBID, INVALID_SUBSCRIPTION_ID);
final int tetherSubId = getIntent().getIntExtra(
EXTRA_TETHER_SUBID, INVALID_SUBSCRIPTION_ID);
final int subId = SubscriptionManager.getActiveDataSubscriptionId();
if (tetherSubId != subId) {
Log.e(TAG, "This Provisioning request is outdated, current subId: " + subId);
@@ -70,11 +70,11 @@ public class TetherProvisioningActivity extends Activity {
finish();
return;
}
String[] provisionApp = getIntent().getStringArrayExtra(EXTRA_RUN_PROVISION);
if (provisionApp == null || provisionApp.length < 2) {
final Resources res = Utils.getResourcesForSubId(this, subId);
provisionApp = res.getStringArray(
com.android.internal.R.array.config_mobile_hotspot_provision_app);
String[] provisionApp = getIntent().getStringArrayExtra(
EXTRA_TETHER_UI_PROVISIONING_APP_NAME);
if (provisionApp == null || provisionApp.length != 2) {
Log.e(TAG, "Unexpected provision app configuration");
return;
}
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(provisionApp[0], provisionApp[1]);