Update configurator intent to be public
This updates the settings code to use the public intent instead. Test: tests still pass Bug: WIP Change-Id: Id40f60b4c2209073aef8747faa5de4e7ff9692ae
This commit is contained in:
committed by
Arc Wang
parent
e56df8877a
commit
2611190def
@@ -3048,7 +3048,7 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"/>
|
||||
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR"/>
|
||||
<action android:name="android.settings.PROCESS_WIFI_DPP_QR_CODE"/>
|
||||
<action android:name="android.settings.PROCESS_WIFI_EASY_CONNECT_QR_CODE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
@@ -133,7 +133,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
|
||||
mChooseDifferentNetwork.setOnClickListener(v ->
|
||||
mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork());
|
||||
mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork()
|
||||
);
|
||||
|
||||
mButtonLeft = view.findViewById(R.id.button_left);
|
||||
mButtonLeft.setText(R.string.cancel);
|
||||
|
@@ -61,6 +61,10 @@ public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFrag
|
||||
* WifiDppChooseSavedWifiNetworkFragment. */
|
||||
final FragmentManager fragmentManager = getChildFragmentManager();
|
||||
final WifiNetworkListFragment fragment = new WifiNetworkListFragment();
|
||||
final Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.wifi_network_list_container, fragment,
|
||||
TAG_FRAGMENT_WIFI_NETWORK_LIST);
|
||||
|
@@ -21,6 +21,7 @@ import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -45,7 +46,7 @@ import com.android.settings.core.InstrumentedActivity;
|
||||
* {@code WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY}
|
||||
* {@code WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID}
|
||||
*
|
||||
* For intent action {@code ACTION_PROCESS_WIFI_DPP_QR_CODE}, specify Wi-Fi (DPP)
|
||||
* For intent action {@link Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE}, specify Wi-Fi (DPP)
|
||||
* QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
|
||||
*/
|
||||
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
@@ -62,8 +63,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER";
|
||||
public static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR =
|
||||
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR";
|
||||
public static final String ACTION_PROCESS_WIFI_DPP_QR_CODE =
|
||||
"android.settings.PROCESS_WIFI_DPP_QR_CODE";
|
||||
|
||||
// Key for Bundle usage
|
||||
private static final String KEY_QR_CODE = "key_qr_code";
|
||||
@@ -78,8 +77,10 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
/** The Wi-Fi network which will be configured */
|
||||
private WifiNetworkConfig mWifiNetworkConfig;
|
||||
|
||||
/** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_DPP_QR_CODE */
|
||||
/** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE */
|
||||
private WifiQrCode mWifiDppQrCode;
|
||||
/** Secret extra that allows fake networks to show in UI for testing purposes */
|
||||
private boolean mIsTest;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -139,8 +140,9 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
showQrCodeGeneratorFragment();
|
||||
}
|
||||
break;
|
||||
case ACTION_PROCESS_WIFI_DPP_QR_CODE:
|
||||
String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE);
|
||||
case Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE:
|
||||
String qrCode = intent.getStringExtra(Settings.EXTRA_QR_CODE);
|
||||
mIsTest = intent.getBooleanExtra(WifiDppUtils.EXTRA_TEST, false);
|
||||
mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode);
|
||||
final boolean isDppSupported = WifiDppUtils.isWifiDppEnabled(this);
|
||||
if (!isDppSupported) {
|
||||
@@ -164,12 +166,17 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
|
||||
private void showQrCodeScannerFragment(boolean addToBackStack) {
|
||||
WifiDppQrCodeScannerFragment fragment =
|
||||
(WifiDppQrCodeScannerFragment) mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
// Avoid to replace the same fragment during configuration change
|
||||
if (mFragmentManager.findFragmentByTag(WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER) != null) {
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
|
||||
if (fragment == null) {
|
||||
fragment = new WifiDppQrCodeScannerFragment();
|
||||
}
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
@@ -181,13 +188,15 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
|
||||
private void showQrCodeGeneratorFragment() {
|
||||
WifiDppQrCodeGeneratorFragment fragment =
|
||||
(WifiDppQrCodeGeneratorFragment) mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
|
||||
// Avoid to replace the same fragment during configuration change
|
||||
if (mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR) != null) {
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
|
||||
fragment = new WifiDppQrCodeGeneratorFragment();
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
@@ -196,14 +205,22 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
|
||||
private void showChooseSavedWifiNetworkFragment(boolean addToBackStack) {
|
||||
WifiDppChooseSavedWifiNetworkFragment fragment =
|
||||
(WifiDppChooseSavedWifiNetworkFragment) mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK);
|
||||
// Avoid to replace the same fragment during configuration change
|
||||
if (mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK) != null) {
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiDppChooseSavedWifiNetworkFragment fragment =
|
||||
new WifiDppChooseSavedWifiNetworkFragment();
|
||||
if (fragment == null) {
|
||||
fragment = new WifiDppChooseSavedWifiNetworkFragment();
|
||||
if (mIsTest) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(WifiDppUtils.EXTRA_TEST, true);
|
||||
fragment.setArguments(bundle);
|
||||
}
|
||||
}
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
@@ -215,14 +232,19 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
|
||||
private void showAddDeviceFragment(boolean addToBackStack) {
|
||||
WifiDppAddDeviceFragment fragment =
|
||||
(WifiDppAddDeviceFragment) mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE);
|
||||
|
||||
// Avoid to replace the same fragment during configuration change
|
||||
if (mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiDppAddDeviceFragment fragment =
|
||||
new WifiDppAddDeviceFragment();
|
||||
if (fragment == null) {
|
||||
fragment = new WifiDppAddDeviceFragment();
|
||||
}
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
|
@@ -29,6 +29,8 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
|
||||
*
|
||||
* @see WifiQrCode
|
||||
*/
|
||||
public class WifiDppUtils {
|
||||
/**
|
||||
@@ -67,8 +69,9 @@ public class WifiDppUtils {
|
||||
/** The data corresponding to {@code WifiConfiguration} networkId */
|
||||
public static final String EXTRA_WIFI_NETWORK_ID = "networkId";
|
||||
|
||||
/** @see WifiQrCode */
|
||||
public static final String EXTRA_QR_CODE = "qrCode";
|
||||
/** Used by {@link android.provider.Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE} to
|
||||
* indicate test mode UI should be shown. Test UI does not make API calls. Value is a boolean.*/
|
||||
public static final String EXTRA_TEST = "test";
|
||||
|
||||
/**
|
||||
* Returns whether the user can share the network represented by this preference with QR code.
|
||||
|
@@ -42,6 +42,9 @@ import androidx.annotation.VisibleForTesting;
|
||||
* EXTRA_QR_CODE
|
||||
*/
|
||||
public class WifiNetworkConfig {
|
||||
|
||||
static final String FAKE_SSID = "fake network";
|
||||
static final String FAKE_PASSWORD = "password";
|
||||
private static final String TAG = "WifiNetworkConfig";
|
||||
|
||||
private String mSecurity;
|
||||
|
@@ -55,11 +55,14 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
private PreferenceCategory mAccessPointsPreferenceCategory;
|
||||
private AccessPointPreference.UserBadgeCache mUserBadgeCache;
|
||||
private Preference mAddPreference;
|
||||
// Only shows up if mIsTest == true
|
||||
private Preference mFakeNetworkPreference;
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private WifiTracker mWifiTracker;
|
||||
|
||||
private WifiManager.ActionListener mSaveListener;
|
||||
private boolean mIsTest;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mUseConnectedAccessPointDirectly;
|
||||
@@ -99,6 +102,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
getSettingsLifecycle(), /* includeSaved */true, /* includeScans */ true);
|
||||
mWifiManager = mWifiTracker.getManager();
|
||||
|
||||
final Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
mIsTest = args.getBoolean(WifiDppUtils.EXTRA_TEST, false);
|
||||
}
|
||||
|
||||
mSaveListener = new WifiManager.ActionListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
@@ -138,6 +146,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference(
|
||||
PREF_KEY_ACCESS_POINTS);
|
||||
|
||||
mFakeNetworkPreference = new Preference(getPrefContext());
|
||||
mFakeNetworkPreference.setIcon(R.drawable.ic_wifi_signal_0);
|
||||
mFakeNetworkPreference.setKey("fake_key");
|
||||
mFakeNetworkPreference.setTitle("fake network");
|
||||
|
||||
mAddPreference = new Preference(getPrefContext());
|
||||
mAddPreference.setIcon(R.drawable.ic_menu_add);
|
||||
mAddPreference.setTitle(R.string.wifi_add_network);
|
||||
@@ -218,6 +231,16 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
}
|
||||
} else if (preference == mAddPreference) {
|
||||
launchAddNetworkFragment();
|
||||
} else if (preference == mFakeNetworkPreference) {
|
||||
if (mOnChooseNetworkListener != null) {
|
||||
mOnChooseNetworkListener.onChooseNetwork(
|
||||
new WifiNetworkConfig(
|
||||
WifiQrCode.SECURITY_WPA,
|
||||
/* ssid */ WifiNetworkConfig.FAKE_SSID,
|
||||
/* preSharedKey */ WifiNetworkConfig.FAKE_PASSWORD,
|
||||
/* hiddenSsid */ true,
|
||||
/* networkId */ WifiConfiguration.INVALID_NETWORK_ID));
|
||||
}
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
@@ -314,6 +337,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
removeCachedPrefs(mAccessPointsPreferenceCategory);
|
||||
mAddPreference.setOrder(index);
|
||||
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||
|
||||
if (mIsTest) {
|
||||
mFakeNetworkPreference.setOrder(index + 1);
|
||||
mAccessPointsPreferenceCategory.addPreference(mFakeNetworkPreference);
|
||||
}
|
||||
}
|
||||
|
||||
private AccessPointPreference createAccessPointPreference(AccessPoint accessPoint) {
|
||||
|
@@ -29,6 +29,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.provider.Settings;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
@@ -88,9 +89,8 @@ public class WifiDppChooseSavedWifiNetworkFragmentTest {
|
||||
|
||||
@Test
|
||||
public void clickCancelButton_processWifiDppQrCodeIntent_shouldFinish() {
|
||||
final Intent intent =
|
||||
new Intent(WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
|
||||
intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent);
|
||||
|
||||
onView(withText(resourceString(CANCEL))).perform(click());
|
||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import android.provider.Settings;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
@@ -65,9 +66,8 @@ public class WifiDppConfiguratorActivityTest {
|
||||
|
||||
@Test
|
||||
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
|
||||
Intent intent = new Intent(
|
||||
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
|
||||
intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
|
||||
mActivityRule.launchActivity(intent);
|
||||
|
||||
@@ -138,9 +138,8 @@ public class WifiDppConfiguratorActivityTest {
|
||||
public void rotateScreen_shouldGetCorrectWifiNetworkConfig() {
|
||||
WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid", "password",
|
||||
/* hiddenSsid */ false, /* networkId */ 0);
|
||||
Intent intent = new Intent(
|
||||
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
|
||||
intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||
|
||||
// setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
|
||||
mActivityRule.launchActivity(intent);
|
||||
|
@@ -103,8 +103,7 @@ public class WifiNetworkListFragmentTest {
|
||||
|
||||
/** Launch the activity via an Intent with a String extra. */
|
||||
private void launchActivity(String extraName, String extraValue) {
|
||||
final Intent intent = new Intent(
|
||||
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||
final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
|
||||
if (extraName != null && extraValue != null) {
|
||||
intent.putExtra(extraName, extraValue);
|
||||
}
|
||||
@@ -168,7 +167,7 @@ public class WifiNetworkListFragmentTest {
|
||||
setupConnectedAccessPoint();
|
||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||
|
||||
launchActivity(WifiDppUtils.EXTRA_QR_CODE, TEST_DPP_URL);
|
||||
launchActivity(Settings.EXTRA_QR_CODE, TEST_DPP_URL);
|
||||
callOnWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
|
||||
|
||||
onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
|
||||
|
Reference in New Issue
Block a user