Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java +38 −0 Original line number Diff line number Diff line Loading @@ -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. * <p> * 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}. * <p> * 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. * <p> Loading Loading @@ -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. * Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +2 −6 Original line number Diff line number Diff line Loading @@ -47,9 +47,6 @@ import java.util.concurrent.atomic.AtomicReference; public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.InternetViewHolder> { 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 Loading Loading @@ -169,11 +166,10 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } mWifiListLayout.setOnClickListener(v -> { 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); Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +2 −3 Original line number Diff line number Diff line Loading @@ -112,7 +112,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; Loading Loading @@ -853,8 +852,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) { Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java +38 −0 Original line number Diff line number Diff line Loading @@ -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. * <p> * 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}. * <p> * 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. * <p> Loading Loading @@ -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. * Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +2 −6 Original line number Diff line number Diff line Loading @@ -47,9 +47,6 @@ import java.util.concurrent.atomic.AtomicReference; public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.InternetViewHolder> { 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 Loading Loading @@ -169,11 +166,10 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } mWifiListLayout.setOnClickListener(v -> { 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); Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +2 −3 Original line number Diff line number Diff line Loading @@ -112,7 +112,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; Loading Loading @@ -853,8 +852,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) { Loading