diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java index 4ab6542d567a8..9ef6bdf0fb411 100644 --- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java @@ -42,6 +42,31 @@ public class WifiUtils { private static final int INVALID_RSSI = -127; + /** + * The intent action shows Wi-Fi dialog to connect Wi-Fi network. + *

+ * Input: The calling package should put the chosen + * com.android.wifitrackerlib.WifiEntry#getKey() to a string extra in the request bundle into + * the {@link #EXTRA_CHOSEN_WIFI_ENTRY_KEY}. + *

+ * Output: Nothing. + */ + @VisibleForTesting + static final String ACTION_WIFI_DIALOG = "com.android.settings.WIFI_DIALOG"; + + /** + * Specify a key that indicates the WifiEntry to be configured. + */ + @VisibleForTesting + static final String EXTRA_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key"; + + /** + * The lookup key for a boolean that indicates whether a chosen WifiEntry request to connect to. + * {@code true} means a chosen WifiEntry request to connect to. + */ + @VisibleForTesting + static final String EXTRA_CONNECT_FOR_CALLER = "connect_for_caller"; + /** * The intent action shows network details settings to allow configuration of Wi-Fi. *

@@ -324,6 +349,19 @@ public class WifiUtils { return config.meteredOverride != WifiConfiguration.METERED_OVERRIDE_NONE; } + /** + * Returns the Intent for Wi-Fi dialog. + * + * @param key The Wi-Fi entry key + * @param connectForCaller True if a chosen WifiEntry request to connect to + */ + public static Intent getWifiDialogIntent(String key, boolean connectForCaller) { + final Intent intent = new Intent(ACTION_WIFI_DIALOG); + intent.putExtra(EXTRA_CHOSEN_WIFI_ENTRY_KEY, key); + intent.putExtra(EXTRA_CONNECT_FOR_CALLER, connectForCaller); + return intent; + } + /** * Returns the Intent for Wi-Fi network details settings. * diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java index e7b3fe9ab8da9..69561055ff7fd 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java @@ -155,6 +155,27 @@ public class WifiUtilsTest { assertThat(WifiUtils.isMeteredOverridden(mWifiConfig)).isTrue(); } + @Test + public void getWifiDialogIntent_returnsCorrectValues() { + String key = "test_key"; + + // Test that connectForCaller is true. + Intent intent = WifiUtils.getWifiDialogIntent(key, true /* connectForCaller */); + + assertThat(intent.getAction()).isEqualTo(WifiUtils.ACTION_WIFI_DIALOG); + assertThat(intent.getStringExtra(WifiUtils.EXTRA_CHOSEN_WIFI_ENTRY_KEY)).isEqualTo(key); + assertThat(intent.getBooleanExtra(WifiUtils.EXTRA_CONNECT_FOR_CALLER, true)) + .isEqualTo(true /* connectForCaller */); + + // Test that connectForCaller is false. + intent = WifiUtils.getWifiDialogIntent(key, false /* connectForCaller */); + + assertThat(intent.getAction()).isEqualTo(WifiUtils.ACTION_WIFI_DIALOG); + assertThat(intent.getStringExtra(WifiUtils.EXTRA_CHOSEN_WIFI_ENTRY_KEY)).isEqualTo(key); + assertThat(intent.getBooleanExtra(WifiUtils.EXTRA_CONNECT_FOR_CALLER, true)) + .isEqualTo(false /* connectForCaller */); + } + @Test public void getWifiDetailsSettingsIntent_returnsCorrectValues() { final String key = "test_key"; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java index 4fe155cfaeb97..af39eb4844dbf 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java @@ -47,9 +47,6 @@ import java.util.concurrent.atomic.AtomicReference; public class InternetAdapter extends RecyclerView.Adapter { private static final String TAG = "InternetAdapter"; - private static final String ACTION_WIFI_DIALOG = "com.android.settings.WIFI_DIALOG"; - private static final String EXTRA_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key"; - private static final String EXTRA_CONNECT_FOR_CALLER = "connect_for_caller"; private final InternetDialogController mInternetDialogController; @Nullable @@ -169,11 +166,10 @@ public class InternetAdapter extends RecyclerView.Adapter { if (wifiEntry.shouldEditBeforeConnect()) { - final Intent intent = new Intent(ACTION_WIFI_DIALOG); + final Intent intent = WifiUtils.getWifiDialogIntent(wifiEntry.getKey(), + true /* connectForCaller */); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - intent.putExtra(EXTRA_CHOSEN_WIFI_ENTRY_KEY, wifiEntry.getKey()); - intent.putExtra(EXTRA_CONNECT_FOR_CALLER, false); mContext.startActivity(intent); } mInternetDialogController.connect(wifiEntry); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java index f89b7a3c09719..28041fc5ae49d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java @@ -111,7 +111,6 @@ public class InternetDialogController implements AccessPointController.AccessPoi "android.settings.NETWORK_PROVIDER_SETTINGS"; private static final String ACTION_WIFI_SCANNING_SETTINGS = "android.settings.WIFI_SCANNING_SETTINGS"; - private static final String EXTRA_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key"; public static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT); public static final int NO_CELL_DATA_TYPE_ICON = 0; private static final int SUBTITLE_TEXT_WIFI_IS_OFF = R.string.wifi_is_off; @@ -856,8 +855,8 @@ public class InternetDialogController implements AccessPointController.AccessPoi } if (status == WifiEntry.ConnectCallback.CONNECT_STATUS_FAILURE_NO_CONFIG) { - final Intent intent = new Intent("com.android.settings.WIFI_DIALOG") - .putExtra(EXTRA_CHOSEN_WIFI_ENTRY_KEY, mWifiEntry.getKey()); + final Intent intent = WifiUtils.getWifiDialogIntent(mWifiEntry.getKey(), + true /* connectForCaller */); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mActivityStarter.startActivity(intent, false /* dismissShade */); } else if (status == CONNECT_STATUS_FAILURE_UNKNOWN) {