Merge "Update configurator intent to be public"

This commit is contained in:
Salvador Martinez
2019-01-28 17:35:41 +00:00
committed by Android (Google) Code Review
10 changed files with 92 additions and 33 deletions

View File

@@ -3048,7 +3048,7 @@
<intent-filter> <intent-filter>
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"/> <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.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"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
</activity> </activity>

View File

@@ -133,7 +133,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network); mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
mChooseDifferentNetwork.setOnClickListener(v -> mChooseDifferentNetwork.setOnClickListener(v ->
mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork()); mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork()
);
mButtonLeft = view.findViewById(R.id.button_left); mButtonLeft = view.findViewById(R.id.button_left);
mButtonLeft.setText(R.string.cancel); mButtonLeft.setText(R.string.cancel);

View File

@@ -61,6 +61,10 @@ public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFrag
* WifiDppChooseSavedWifiNetworkFragment. */ * WifiDppChooseSavedWifiNetworkFragment. */
final FragmentManager fragmentManager = getChildFragmentManager(); final FragmentManager fragmentManager = getChildFragmentManager();
final WifiNetworkListFragment fragment = new WifiNetworkListFragment(); final WifiNetworkListFragment fragment = new WifiNetworkListFragment();
final Bundle args = getArguments();
if (args != null) {
fragment.setArguments(args);
}
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.wifi_network_list_container, fragment, fragmentTransaction.replace(R.id.wifi_network_list_container, fragment,
TAG_FRAGMENT_WIFI_NETWORK_LIST); TAG_FRAGMENT_WIFI_NETWORK_LIST);

View File

@@ -21,6 +21,7 @@ import android.app.Activity;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting; 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_PRE_SHARED_KEY}
* {@code WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID} * {@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} * QR code in {@code WifiDppUtils.EXTRA_QR_CODE}
*/ */
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
@@ -62,8 +63,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
"android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"; "android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER";
public static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR = public static final String ACTION_CONFIGURATOR_QR_CODE_GENERATOR =
"android.settings.WIFI_DPP_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 // Key for Bundle usage
private static final String KEY_QR_CODE = "key_qr_code"; 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 */ /** The Wi-Fi network which will be configured */
private WifiNetworkConfig mWifiNetworkConfig; 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; private WifiQrCode mWifiDppQrCode;
/** Secret extra that allows fake networks to show in UI for testing purposes */
private boolean mIsTest;
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
@@ -139,8 +140,9 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
showQrCodeGeneratorFragment(); showQrCodeGeneratorFragment();
} }
break; break;
case ACTION_PROCESS_WIFI_DPP_QR_CODE: case Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE:
String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE); String qrCode = intent.getStringExtra(Settings.EXTRA_QR_CODE);
mIsTest = intent.getBooleanExtra(WifiDppUtils.EXTRA_TEST, false);
mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode); mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode);
final boolean isDppSupported = WifiDppUtils.isWifiDppEnabled(this); final boolean isDppSupported = WifiDppUtils.isWifiDppEnabled(this);
if (!isDppSupported) { if (!isDppSupported) {
@@ -164,12 +166,17 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
} }
private void showQrCodeScannerFragment(boolean addToBackStack) { 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 // 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; return;
} }
final WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment(); if (fragment == null) {
fragment = new WifiDppQrCodeScannerFragment();
}
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment, fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -181,13 +188,15 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
} }
private void showQrCodeGeneratorFragment() { private void showQrCodeGeneratorFragment() {
WifiDppQrCodeGeneratorFragment fragment =
(WifiDppQrCodeGeneratorFragment) mFragmentManager.findFragmentByTag(
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
// Avoid to replace the same fragment during configuration change // Avoid to replace the same fragment during configuration change
if (mFragmentManager.findFragmentByTag( if (fragment != null && fragment.isVisible()) {
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR) != null) {
return; return;
} }
final WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment(); fragment = new WifiDppQrCodeGeneratorFragment();
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment, fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -196,14 +205,22 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
} }
private void showChooseSavedWifiNetworkFragment(boolean addToBackStack) { 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 // Avoid to replace the same fragment during configuration change
if (mFragmentManager.findFragmentByTag( if (fragment != null && fragment.isVisible()) {
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK) != null) {
return; return;
} }
final WifiDppChooseSavedWifiNetworkFragment fragment = if (fragment == null) {
new WifiDppChooseSavedWifiNetworkFragment(); fragment = new WifiDppChooseSavedWifiNetworkFragment();
if (mIsTest) {
Bundle bundle = new Bundle();
bundle.putBoolean(WifiDppUtils.EXTRA_TEST, true);
fragment.setArguments(bundle);
}
}
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment, fragmentTransaction.replace(R.id.fragment_container, fragment,
@@ -215,14 +232,19 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
} }
private void showAddDeviceFragment(boolean addToBackStack) { private void showAddDeviceFragment(boolean addToBackStack) {
WifiDppAddDeviceFragment fragment =
(WifiDppAddDeviceFragment) mFragmentManager.findFragmentByTag(
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE);
// Avoid to replace the same fragment during configuration change // Avoid to replace the same fragment during configuration change
if (mFragmentManager.findFragmentByTag( if (mFragmentManager.findFragmentByTag(
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE) != null) { WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE) != null) {
return; return;
} }
final WifiDppAddDeviceFragment fragment = if (fragment == null) {
new WifiDppAddDeviceFragment(); fragment = new WifiDppAddDeviceFragment();
}
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment, fragmentTransaction.replace(R.id.fragment_container, fragment,

View File

@@ -29,6 +29,8 @@ import java.util.List;
/** /**
* Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity * Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity
*
* @see WifiQrCode
*/ */
public class WifiDppUtils { public class WifiDppUtils {
/** /**
@@ -67,8 +69,9 @@ public class WifiDppUtils {
/** The data corresponding to {@code WifiConfiguration} networkId */ /** The data corresponding to {@code WifiConfiguration} networkId */
public static final String EXTRA_WIFI_NETWORK_ID = "networkId"; public static final String EXTRA_WIFI_NETWORK_ID = "networkId";
/** @see WifiQrCode */ /** Used by {@link android.provider.Settings#ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE} to
public static final String EXTRA_QR_CODE = "qrCode"; * 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. * Returns whether the user can share the network represented by this preference with QR code.

View File

@@ -42,6 +42,9 @@ import androidx.annotation.VisibleForTesting;
* EXTRA_QR_CODE * EXTRA_QR_CODE
*/ */
public class WifiNetworkConfig { public class WifiNetworkConfig {
static final String FAKE_SSID = "fake network";
static final String FAKE_PASSWORD = "password";
private static final String TAG = "WifiNetworkConfig"; private static final String TAG = "WifiNetworkConfig";
private String mSecurity; private String mSecurity;

View File

@@ -55,11 +55,14 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
private PreferenceCategory mAccessPointsPreferenceCategory; private PreferenceCategory mAccessPointsPreferenceCategory;
private AccessPointPreference.UserBadgeCache mUserBadgeCache; private AccessPointPreference.UserBadgeCache mUserBadgeCache;
private Preference mAddPreference; private Preference mAddPreference;
// Only shows up if mIsTest == true
private Preference mFakeNetworkPreference;
private WifiManager mWifiManager; private WifiManager mWifiManager;
private WifiTracker mWifiTracker; private WifiTracker mWifiTracker;
private WifiManager.ActionListener mSaveListener; private WifiManager.ActionListener mSaveListener;
private boolean mIsTest;
@VisibleForTesting @VisibleForTesting
boolean mUseConnectedAccessPointDirectly; boolean mUseConnectedAccessPointDirectly;
@@ -99,6 +102,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
getSettingsLifecycle(), /* includeSaved */true, /* includeScans */ true); getSettingsLifecycle(), /* includeSaved */true, /* includeScans */ true);
mWifiManager = mWifiTracker.getManager(); mWifiManager = mWifiTracker.getManager();
final Bundle args = getArguments();
if (args != null) {
mIsTest = args.getBoolean(WifiDppUtils.EXTRA_TEST, false);
}
mSaveListener = new WifiManager.ActionListener() { mSaveListener = new WifiManager.ActionListener() {
@Override @Override
public void onSuccess() { public void onSuccess() {
@@ -138,6 +146,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference( mAccessPointsPreferenceCategory = (PreferenceCategory) findPreference(
PREF_KEY_ACCESS_POINTS); 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 = new Preference(getPrefContext());
mAddPreference.setIcon(R.drawable.ic_menu_add); mAddPreference.setIcon(R.drawable.ic_menu_add);
mAddPreference.setTitle(R.string.wifi_add_network); mAddPreference.setTitle(R.string.wifi_add_network);
@@ -218,6 +231,16 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
} }
} else if (preference == mAddPreference) { } else if (preference == mAddPreference) {
launchAddNetworkFragment(); 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 { } else {
return super.onPreferenceTreeClick(preference); return super.onPreferenceTreeClick(preference);
} }
@@ -314,6 +337,11 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
removeCachedPrefs(mAccessPointsPreferenceCategory); removeCachedPrefs(mAccessPointsPreferenceCategory);
mAddPreference.setOrder(index); mAddPreference.setOrder(index);
mAccessPointsPreferenceCategory.addPreference(mAddPreference); mAccessPointsPreferenceCategory.addPreference(mAddPreference);
if (mIsTest) {
mFakeNetworkPreference.setOrder(index + 1);
mAccessPointsPreferenceCategory.addPreference(mFakeNetworkPreference);
}
} }
private AccessPointPreference createAccessPointPreference(AccessPoint accessPoint) { private AccessPointPreference createAccessPointPreference(AccessPoint accessPoint) {

View File

@@ -29,6 +29,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.Settings;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.test.InstrumentationRegistry; import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule; import androidx.test.rule.ActivityTestRule;
@@ -88,9 +89,8 @@ public class WifiDppChooseSavedWifiNetworkFragmentTest {
@Test @Test
public void clickCancelButton_processWifiDppQrCodeIntent_shouldFinish() { public void clickCancelButton_processWifiDppQrCodeIntent_shouldFinish() {
final Intent intent = final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
new Intent(WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE); intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent); final WifiDppConfiguratorActivity hostActivity = mActivityRule.launchActivity(intent);
onView(withText(resourceString(CANCEL))).perform(click()); onView(withText(resourceString(CANCEL))).perform(click());

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.provider.Settings;
import androidx.test.rule.ActivityTestRule; import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
@@ -65,9 +66,8 @@ public class WifiDppConfiguratorActivityTest {
@Test @Test
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() { public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
Intent intent = new Intent( Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE); intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
mActivityRule.launchActivity(intent); mActivityRule.launchActivity(intent);
@@ -138,9 +138,8 @@ public class WifiDppConfiguratorActivityTest {
public void rotateScreen_shouldGetCorrectWifiNetworkConfig() { public void rotateScreen_shouldGetCorrectWifiNetworkConfig() {
WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid", "password", WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid", "password",
/* hiddenSsid */ false, /* networkId */ 0); /* hiddenSsid */ false, /* networkId */ 0);
Intent intent = new Intent( Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE); intent.putExtra(Settings.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
// setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation // setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
mActivityRule.launchActivity(intent); mActivityRule.launchActivity(intent);

View File

@@ -103,8 +103,7 @@ public class WifiNetworkListFragmentTest {
/** Launch the activity via an Intent with a String extra. */ /** Launch the activity via an Intent with a String extra. */
private void launchActivity(String extraName, String extraValue) { private void launchActivity(String extraName, String extraValue) {
final Intent intent = new Intent( final Intent intent = new Intent(Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_QR_CODE);
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
if (extraName != null && extraValue != null) { if (extraName != null && extraValue != null) {
intent.putExtra(extraName, extraValue); intent.putExtra(extraName, extraValue);
} }
@@ -168,7 +167,7 @@ public class WifiNetworkListFragmentTest {
setupConnectedAccessPoint(); setupConnectedAccessPoint();
when(mWifiTracker.isConnected()).thenReturn(true); 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); callOnWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check( onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(