Merge "[Provider Model] Fix WiFi reconfiguration issue" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4ff1762d34
@@ -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>
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user