Loading res/values/strings.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -10458,6 +10458,8 @@ <string name="network_connection_timeout_dialog_ok">Try again</string> <string name="network_connection_timeout_dialog_ok">Try again</string> <!-- Message for Network connection error state Dialog [CHAR LIMIT=NONE] --> <!-- Message for Network connection error state Dialog [CHAR LIMIT=NONE] --> <string name="network_connection_errorstate_dialog_message">Something came up. The application has cancelled the request to choose a device.</string> <string name="network_connection_errorstate_dialog_message">Something came up. The application has cancelled the request to choose a device.</string> <!-- Toast message when connection is successful [CHAR LIMIT=30] --> <string name="network_connection_connect_successful">Connection successful</string> <!-- Summary for bluetooth devices count in Bluetooth devices slice. [CHAR LIMIT=NONE] --> <!-- Summary for bluetooth devices count in Bluetooth devices slice. [CHAR LIMIT=NONE] --> <plurals name="show_bluetooth_devices"> <plurals name="show_bluetooth_devices"> src/com/android/settings/wifi/NetworkRequestDialogFragment.java +19 −42 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.wifi; package com.android.settings.wifi; import android.app.Activity; import android.app.Dialog; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.Context; Loading @@ -37,6 +38,7 @@ import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.BaseAdapter; import android.widget.ProgressBar; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting; Loading Loading @@ -66,15 +68,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp /** Message sent to us to stop scanning wifi and pop up timeout dialog. */ /** Message sent to us to stop scanning wifi and pop up timeout dialog. */ private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0; private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0; /** Message sent to us to finish activity. */ private static final int MESSAGE_FINISH_ACTIVITY = 1; /** Spec defines there should be 5 wifi ap on the list at most. */ /** Spec defines there should be 5 wifi ap on the list at most. */ private static final int MAX_NUMBER_LIST_ITEM = 5; private static final int MAX_NUMBER_LIST_ITEM = 5; /** Holding time to let user be aware that selected wifi ap is connected */ private static final int DELAY_TIME_USER_AWARE_CONNECTED_MS = 1 * 1000; /** Delayed time to stop scanning wifi. */ /** Delayed time to stop scanning wifi. */ private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000; private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000; Loading Loading @@ -185,7 +181,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp public void onDestroy() { public void onDestroy() { super.onDestroy(); super.onDestroy(); mHandler.removeMessages(MESSAGE_FINISH_ACTIVITY); if (mFilterWifiTracker != null) { if (mFilterWifiTracker != null) { mFilterWifiTracker.onDestroy(); mFilterWifiTracker.onDestroy(); mFilterWifiTracker = null; mFilterWifiTracker = null; Loading Loading @@ -216,10 +211,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp switch (msg.what) { switch (msg.what) { case MESSAGE_STOP_SCAN_WIFI_LIST: case MESSAGE_STOP_SCAN_WIFI_LIST: removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.TIME_OUT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.TIME_OUT); break; case MESSAGE_FINISH_ACTIVITY: stopScanningAndMaybePopErrorDialog(/* ERROR_DIALOG_TYPE */ null); break; break; default: default: // Do nothing. // Do nothing. Loading @@ -228,19 +220,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } }; }; protected void stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE type) { protected void stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE type) { // Dismisses current dialog. // Dismisses current dialog. final Dialog dialog = getDialog(); final Dialog dialog = getDialog(); if (dialog != null && dialog.isShowing()) { if (dialog != null && dialog.isShowing()) { dismiss(); dismiss(); } } if (type == null) { // If no error, finishes activity. if (getActivity() != null) { getActivity().finish(); } } else { // Throws error dialog. // Throws error dialog. final NetworkRequestErrorDialogFragment fragment = NetworkRequestErrorDialogFragment final NetworkRequestErrorDialogFragment fragment = NetworkRequestErrorDialogFragment .newInstance(); .newInstance(); Loading @@ -251,8 +237,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp NetworkRequestDialogFragment.class.getSimpleName()); NetworkRequestDialogFragment.class.getSimpleName()); } } } @Override @Override public int getMetricsCategory() { public int getMetricsCategory() { return SettingsEnums.WIFI_SCANNING_NEEDED_DIALOG; return SettingsEnums.WIFI_SCANNING_NEEDED_DIALOG; Loading Loading @@ -313,7 +297,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp @Override @Override public void onAbort() { public void onAbort() { stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.ABORT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT); } } @Override @Override Loading Loading @@ -361,24 +345,17 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp @Override @Override public void onUserSelectionConnectSuccess(WifiConfiguration wificonfiguration) { public void onUserSelectionConnectSuccess(WifiConfiguration wificonfiguration) { // Removes the progress icon. final Activity activity = getActivity(); final Dialog dialog = getDialog(); if (activity != null) { if (dialog != null) { Toast.makeText(activity, R.string.network_connection_connect_successful, final View view = dialog.findViewById(R.id.network_request_title_progress); Toast.LENGTH_SHORT).show(); if (view != null) { activity.finish(); view.setVisibility(View.GONE); } } } } // Posts delay to finish self since connection is success. mHandler.removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); mHandler.sendEmptyMessageDelayed(MESSAGE_FINISH_ACTIVITY, DELAY_TIME_USER_AWARE_CONNECTED_MS); } @Override @Override public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) { public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) { stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.ABORT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT); } } private final class FilterWifiTracker { private final class FilterWifiTracker { Loading tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java +8 −14 Original line number Original line Diff line number Diff line Loading @@ -119,7 +119,7 @@ public class NetworkRequestDialogFragmentTest { ERROR_DIALOG_TYPE errorType = null; ERROR_DIALOG_TYPE errorType = null; @Override @Override public void stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE type) { public void stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE type) { bCalledStopAndPop = true; bCalledStopAndPop = true; errorType = type; errorType = type; } } Loading Loading @@ -152,25 +152,19 @@ public class NetworkRequestDialogFragmentTest { } } @Test @Test public void updateAccessPointList_onUserSelectionConnectSuccess_shouldCloseTheDialog() { public void updateAccessPointList_onUserSelectionConnectSuccess_shouldFinishActivity() { // Assert // Assert FakeNetworkRequestDialogFragment fakeFragment = new FakeNetworkRequestDialogFragment(); final FragmentActivity spyActivity = spy(mActivity); FakeNetworkRequestDialogFragment spyFakeFragment = spy(fakeFragment); when(networkRequestDialogFragment.getActivity()).thenReturn(spyActivity); networkRequestDialogFragment.show(spyActivity.getSupportFragmentManager(), "onUserSelectionConnectSuccess"); List<AccessPoint> accessPointList = createAccessPointList(); when(spyFakeFragment.getAccessPointList()).thenReturn(accessPointList); spyFakeFragment.show(mActivity.getSupportFragmentManager(), null); // Action // Action WifiConfiguration config = new WifiConfiguration(); final WifiConfiguration config = new WifiConfiguration(); config.SSID = "Test AP 3"; config.SSID = "Test AP 3"; spyFakeFragment.onUserSelectionConnectSuccess(config); networkRequestDialogFragment.onUserSelectionConnectSuccess(config); // Check // Check ShadowLooper.getShadowMainLooper().runToEndOfTasks(); verify(spyActivity).finish(); assertThat(fakeFragment.bCalledStopAndPop).isTrue(); assertThat(fakeFragment.errorType).isNull(); } } @Test @Test Loading Loading
res/values/strings.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -10458,6 +10458,8 @@ <string name="network_connection_timeout_dialog_ok">Try again</string> <string name="network_connection_timeout_dialog_ok">Try again</string> <!-- Message for Network connection error state Dialog [CHAR LIMIT=NONE] --> <!-- Message for Network connection error state Dialog [CHAR LIMIT=NONE] --> <string name="network_connection_errorstate_dialog_message">Something came up. The application has cancelled the request to choose a device.</string> <string name="network_connection_errorstate_dialog_message">Something came up. The application has cancelled the request to choose a device.</string> <!-- Toast message when connection is successful [CHAR LIMIT=30] --> <string name="network_connection_connect_successful">Connection successful</string> <!-- Summary for bluetooth devices count in Bluetooth devices slice. [CHAR LIMIT=NONE] --> <!-- Summary for bluetooth devices count in Bluetooth devices slice. [CHAR LIMIT=NONE] --> <plurals name="show_bluetooth_devices"> <plurals name="show_bluetooth_devices">
src/com/android/settings/wifi/NetworkRequestDialogFragment.java +19 −42 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.wifi; package com.android.settings.wifi; import android.app.Activity; import android.app.Dialog; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums; import android.content.Context; import android.content.Context; Loading @@ -37,6 +38,7 @@ import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.BaseAdapter; import android.widget.ProgressBar; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting; Loading Loading @@ -66,15 +68,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp /** Message sent to us to stop scanning wifi and pop up timeout dialog. */ /** Message sent to us to stop scanning wifi and pop up timeout dialog. */ private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0; private static final int MESSAGE_STOP_SCAN_WIFI_LIST = 0; /** Message sent to us to finish activity. */ private static final int MESSAGE_FINISH_ACTIVITY = 1; /** Spec defines there should be 5 wifi ap on the list at most. */ /** Spec defines there should be 5 wifi ap on the list at most. */ private static final int MAX_NUMBER_LIST_ITEM = 5; private static final int MAX_NUMBER_LIST_ITEM = 5; /** Holding time to let user be aware that selected wifi ap is connected */ private static final int DELAY_TIME_USER_AWARE_CONNECTED_MS = 1 * 1000; /** Delayed time to stop scanning wifi. */ /** Delayed time to stop scanning wifi. */ private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000; private static final int DELAY_TIME_STOP_SCAN_MS = 30 * 1000; Loading Loading @@ -185,7 +181,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp public void onDestroy() { public void onDestroy() { super.onDestroy(); super.onDestroy(); mHandler.removeMessages(MESSAGE_FINISH_ACTIVITY); if (mFilterWifiTracker != null) { if (mFilterWifiTracker != null) { mFilterWifiTracker.onDestroy(); mFilterWifiTracker.onDestroy(); mFilterWifiTracker = null; mFilterWifiTracker = null; Loading Loading @@ -216,10 +211,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp switch (msg.what) { switch (msg.what) { case MESSAGE_STOP_SCAN_WIFI_LIST: case MESSAGE_STOP_SCAN_WIFI_LIST: removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.TIME_OUT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.TIME_OUT); break; case MESSAGE_FINISH_ACTIVITY: stopScanningAndMaybePopErrorDialog(/* ERROR_DIALOG_TYPE */ null); break; break; default: default: // Do nothing. // Do nothing. Loading @@ -228,19 +220,13 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp } } }; }; protected void stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE type) { protected void stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE type) { // Dismisses current dialog. // Dismisses current dialog. final Dialog dialog = getDialog(); final Dialog dialog = getDialog(); if (dialog != null && dialog.isShowing()) { if (dialog != null && dialog.isShowing()) { dismiss(); dismiss(); } } if (type == null) { // If no error, finishes activity. if (getActivity() != null) { getActivity().finish(); } } else { // Throws error dialog. // Throws error dialog. final NetworkRequestErrorDialogFragment fragment = NetworkRequestErrorDialogFragment final NetworkRequestErrorDialogFragment fragment = NetworkRequestErrorDialogFragment .newInstance(); .newInstance(); Loading @@ -251,8 +237,6 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp NetworkRequestDialogFragment.class.getSimpleName()); NetworkRequestDialogFragment.class.getSimpleName()); } } } @Override @Override public int getMetricsCategory() { public int getMetricsCategory() { return SettingsEnums.WIFI_SCANNING_NEEDED_DIALOG; return SettingsEnums.WIFI_SCANNING_NEEDED_DIALOG; Loading Loading @@ -313,7 +297,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp @Override @Override public void onAbort() { public void onAbort() { stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.ABORT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT); } } @Override @Override Loading Loading @@ -361,24 +345,17 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp @Override @Override public void onUserSelectionConnectSuccess(WifiConfiguration wificonfiguration) { public void onUserSelectionConnectSuccess(WifiConfiguration wificonfiguration) { // Removes the progress icon. final Activity activity = getActivity(); final Dialog dialog = getDialog(); if (activity != null) { if (dialog != null) { Toast.makeText(activity, R.string.network_connection_connect_successful, final View view = dialog.findViewById(R.id.network_request_title_progress); Toast.LENGTH_SHORT).show(); if (view != null) { activity.finish(); view.setVisibility(View.GONE); } } } } // Posts delay to finish self since connection is success. mHandler.removeMessages(MESSAGE_STOP_SCAN_WIFI_LIST); mHandler.sendEmptyMessageDelayed(MESSAGE_FINISH_ACTIVITY, DELAY_TIME_USER_AWARE_CONNECTED_MS); } @Override @Override public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) { public void onUserSelectionConnectFailure(WifiConfiguration wificonfiguration) { stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE.ABORT); stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE.ABORT); } } private final class FilterWifiTracker { private final class FilterWifiTracker { Loading
tests/robotests/src/com/android/settings/wifi/NetworkRequestDialogFragmentTest.java +8 −14 Original line number Original line Diff line number Diff line Loading @@ -119,7 +119,7 @@ public class NetworkRequestDialogFragmentTest { ERROR_DIALOG_TYPE errorType = null; ERROR_DIALOG_TYPE errorType = null; @Override @Override public void stopScanningAndMaybePopErrorDialog(ERROR_DIALOG_TYPE type) { public void stopScanningAndPopErrorDialog(ERROR_DIALOG_TYPE type) { bCalledStopAndPop = true; bCalledStopAndPop = true; errorType = type; errorType = type; } } Loading Loading @@ -152,25 +152,19 @@ public class NetworkRequestDialogFragmentTest { } } @Test @Test public void updateAccessPointList_onUserSelectionConnectSuccess_shouldCloseTheDialog() { public void updateAccessPointList_onUserSelectionConnectSuccess_shouldFinishActivity() { // Assert // Assert FakeNetworkRequestDialogFragment fakeFragment = new FakeNetworkRequestDialogFragment(); final FragmentActivity spyActivity = spy(mActivity); FakeNetworkRequestDialogFragment spyFakeFragment = spy(fakeFragment); when(networkRequestDialogFragment.getActivity()).thenReturn(spyActivity); networkRequestDialogFragment.show(spyActivity.getSupportFragmentManager(), "onUserSelectionConnectSuccess"); List<AccessPoint> accessPointList = createAccessPointList(); when(spyFakeFragment.getAccessPointList()).thenReturn(accessPointList); spyFakeFragment.show(mActivity.getSupportFragmentManager(), null); // Action // Action WifiConfiguration config = new WifiConfiguration(); final WifiConfiguration config = new WifiConfiguration(); config.SSID = "Test AP 3"; config.SSID = "Test AP 3"; spyFakeFragment.onUserSelectionConnectSuccess(config); networkRequestDialogFragment.onUserSelectionConnectSuccess(config); // Check // Check ShadowLooper.getShadowMainLooper().runToEndOfTasks(); verify(spyActivity).finish(); assertThat(fakeFragment.bCalledStopAndPop).isTrue(); assertThat(fakeFragment.errorType).isNull(); } } @Test @Test Loading