Merge "Add function to launch the Network details settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
aad915ca43
@@ -20,10 +20,12 @@ import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_
|
||||
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.getMaxNetworkSelectionDisableReason;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -36,6 +38,23 @@ public class WifiUtils {
|
||||
|
||||
private static final int INVALID_RSSI = -127;
|
||||
|
||||
/**
|
||||
* The intent action shows network details settings to allow configuration of Wi-Fi.
|
||||
* <p>
|
||||
* In some cases, a matching Activity may not exist, so ensure you
|
||||
* safeguard against this.
|
||||
* <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 #KEY_CHOSEN_WIFIENTRY_KEY}.
|
||||
* <p>
|
||||
* Output: Nothing.
|
||||
*/
|
||||
public static final String ACTION_WIFI_DETAILS_SETTINGS =
|
||||
"android.settings.WIFI_DETAILS_SETTINGS";
|
||||
public static final String KEY_CHOSEN_WIFIENTRY_KEY = "key_chosen_wifientry_key";
|
||||
public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
|
||||
|
||||
static final int[] WIFI_PIE = {
|
||||
com.android.internal.R.drawable.ic_wifi_signal_0,
|
||||
com.android.internal.R.drawable.ic_wifi_signal_1,
|
||||
@@ -278,4 +297,17 @@ public class WifiUtils {
|
||||
public static boolean isMeteredOverridden(WifiConfiguration config) {
|
||||
return config.meteredOverride != WifiConfiguration.METERED_OVERRIDE_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Intent for Wi-Fi network details settings.
|
||||
*
|
||||
* @param key The Wi-Fi entry key
|
||||
*/
|
||||
public static Intent getWifiDetailsSettingsIntent(String key) {
|
||||
final Intent intent = new Intent(ACTION_WIFI_DETAILS_SETTINGS);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_CHOSEN_WIFIENTRY_KEY, key);
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle);
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkKey;
|
||||
import android.net.RssiCurve;
|
||||
import android.net.ScoredNetwork;
|
||||
@@ -148,6 +149,17 @@ public class WifiUtilsTest {
|
||||
assertThat(WifiUtils.isMeteredOverridden(mWifiConfig)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiDetailsSettingsIntent_returnsCorrectValues() {
|
||||
final String key = "test_key";
|
||||
|
||||
final Intent intent = WifiUtils.getWifiDetailsSettingsIntent(key);
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(WifiUtils.ACTION_WIFI_DETAILS_SETTINGS);
|
||||
final Bundle bundle = intent.getBundleExtra(WifiUtils.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key);
|
||||
}
|
||||
|
||||
private static ArrayList<ScanResult> buildScanResultCache() {
|
||||
ArrayList<ScanResult> scanResults = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
Reference in New Issue
Block a user