[Wi-Fi] Create WifiNetworkDetailsFragment related version 2 files for WifiTracker2 development
Create below version 2 files for WifiTracker2 development, we can check the feature flag only a few times and easily remove version 1 files in the future. src/com/android/settings/wifi/details2/ src/com/android/settings/wifi/savedaccesspoints2/ tests/robotests/src/com/android/settings/wifi/details2/ tests/robotests/src/com/android/settings/wifi/savedaccesspoints2/ Bug: 143326832 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi.details2 make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi.savedaccesspoints2 Change-Id: I4d2caf1ce313871605252395764b02747240f217
This commit is contained in:
33
res/xml/wifi_display_saved_access_points2.xml
Normal file
33
res/xml/wifi_display_saved_access_points2.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="saved_access_points"
|
||||
android:title="@string/wifi_saved_access_points_label">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="subscribed_access_points_category"
|
||||
android:title="@string/wifi_subscribed_access_points_tab"
|
||||
settings:controller="com.android.settings.wifi.savedaccesspoints2.SubscribedAccessPointsPreferenceController2"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="saved_access_points_category"
|
||||
android:title="@string/wifi_saved_access_points_tab"
|
||||
settings:controller="com.android.settings.wifi.savedaccesspoints2.SavedAccessPointsPreferenceController2"/>
|
||||
|
||||
</PreferenceScreen>
|
48
res/xml/wifi_settings2.xml
Normal file
48
res/xml/wifi_settings2.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/wifi_settings"
|
||||
settings:keywords="@string/keywords_wifi">
|
||||
|
||||
<com.android.settings.wifi.LinkablePreference
|
||||
android:key="wifi_status_message"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="connected_access_point"
|
||||
android:layout="@layout/preference_category_no_label"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="access_points"
|
||||
android:layout="@layout/preference_category_no_label"/>
|
||||
|
||||
<Preference
|
||||
android:key="configure_settings"
|
||||
android:title="@string/wifi_configure_settings_preference_title"
|
||||
settings:allowDividerAbove="true"
|
||||
android:fragment="com.android.settings.wifi.ConfigureWifiSettings"/>
|
||||
|
||||
<Preference
|
||||
android:key="saved_networks"
|
||||
android:title="@string/wifi_saved_access_points_label"
|
||||
android:fragment="com.android.settings.wifi.savedaccesspoints2.SavedAccessPointsWifiSettings2"/>
|
||||
|
||||
<com.android.settings.datausage.DataUsagePreference
|
||||
android:key="wifi_data_usage"
|
||||
android:title="@string/wifi_data_usage"/>
|
||||
</PreferenceScreen>
|
@@ -146,6 +146,7 @@ import com.android.settings.wifi.calling.WifiCallingDisclaimerFragment;
|
||||
import com.android.settings.wifi.calling.WifiCallingSettings;
|
||||
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
||||
import com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings;
|
||||
import com.android.settings.wifi.savedaccesspoints2.SavedAccessPointsWifiSettings2;
|
||||
import com.android.settings.wifi.tether.WifiTetherSettings;
|
||||
|
||||
public class SettingsGateway {
|
||||
@@ -161,6 +162,7 @@ public class SettingsGateway {
|
||||
WifiSettings2.class.getName(),
|
||||
ConfigureWifiSettings.class.getName(),
|
||||
SavedAccessPointsWifiSettings.class.getName(),
|
||||
SavedAccessPointsWifiSettings2.class.getName(),
|
||||
TetherSettings.class.getName(),
|
||||
WifiP2pSettings.class.getName(),
|
||||
WifiTetherSettings.class.getName(),
|
||||
|
@@ -20,12 +20,14 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settings.wifi.WifiSettings2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -61,11 +63,20 @@ public class WifiPanel implements PanelContent {
|
||||
public Intent getSeeMoreIntent() {
|
||||
final String screenTitle =
|
||||
mContext.getText(R.string.wifi_settings).toString();
|
||||
final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
Intent intent;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
WifiSettings2.class.getName(),
|
||||
null /* key */,
|
||||
screenTitle,
|
||||
SettingsEnums.WIFI);
|
||||
} else {
|
||||
intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
WifiSettings.class.getName(),
|
||||
null /* key */,
|
||||
screenTitle,
|
||||
SettingsEnums.WIFI);
|
||||
}
|
||||
intent.setClassName(mContext.getPackageName(), SubSettings.class.getName());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
|
@@ -44,6 +44,7 @@ import android.text.InputType;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@@ -70,6 +71,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import com.android.settings.ProxySelector;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.wifi.details.WifiPrivacyPreferenceController;
|
||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -289,9 +291,14 @@ public class WifiConfigController implements TextWatcher,
|
||||
? HIDDEN_NETWORK
|
||||
: NOT_HIDDEN_NETWORK);
|
||||
|
||||
final int prefMacValue =
|
||||
WifiPrivacyPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
config.macRandomizationSetting);
|
||||
int prefMacValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
prefMacValue = WifiPrivacyPreferenceController2
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
} else {
|
||||
prefMacValue = WifiPrivacyPreferenceController
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
}
|
||||
mPrivacySettingsSpinner.setSelection(prefMacValue);
|
||||
|
||||
if (config.getIpAssignment() == IpAssignment.STATIC) {
|
||||
@@ -843,9 +850,14 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
|
||||
if (mPrivacySettingsSpinner != null) {
|
||||
final int macValue =
|
||||
WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
|
||||
int macValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
macValue = WifiPrivacyPreferenceController2.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
} else {
|
||||
macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
}
|
||||
config.macRandomizationSetting = macValue;
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -25,6 +26,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
@@ -128,6 +130,19 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
||||
mPreference.refresh();
|
||||
mPreference.setOrder(order);
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(mPrefContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
mPreference.setOnPreferenceClickListener(pref -> {
|
||||
Bundle args = new Bundle();
|
||||
mPreference.getAccessPoint().saveWifiState(args);
|
||||
new SubSettingLauncher(mPrefContext)
|
||||
.setTitleRes(R.string.pref_title_network_details)
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(args)
|
||||
.setSourceMetricsCategory(mMetricsCategory)
|
||||
.launch();
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
mPreference.setOnPreferenceClickListener(pref -> {
|
||||
Bundle args = new Bundle();
|
||||
mPreference.getAccessPoint().saveWifiState(args);
|
||||
@@ -139,6 +154,7 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
|
||||
.launch();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
mPreferenceGroup.addPreference(mPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
@@ -24,6 +25,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
||||
import com.android.settings.wifi.savedaccesspoints.SavedAccessPointsWifiSettings;
|
||||
import com.android.settings.wifi.savedaccesspoints2.SavedAccessPointsWifiSettings2;
|
||||
|
||||
public class WifiPickerActivity extends SettingsActivity implements ButtonBarHandler {
|
||||
|
||||
@@ -39,9 +41,18 @@ public class WifiPickerActivity extends SettingsActivity implements ButtonBarHan
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
boolean isSavedAccessPointsWifiSettings;
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
isSavedAccessPointsWifiSettings =
|
||||
SavedAccessPointsWifiSettings2.class.getName().equals(fragmentName);
|
||||
} else {
|
||||
isSavedAccessPointsWifiSettings =
|
||||
SavedAccessPointsWifiSettings.class.getName().equals(fragmentName);
|
||||
}
|
||||
|
||||
if (WifiSettings.class.getName().equals(fragmentName)
|
||||
|| WifiP2pSettings.class.getName().equals(fragmentName)
|
||||
|| SavedAccessPointsWifiSettings.class.getName().equals(fragmentName)) {
|
||||
|| isSavedAccessPointsWifiSettings) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -68,6 +68,7 @@ import com.android.settings.location.ScanningSettings;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.SwitchBarController;
|
||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -954,6 +955,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
? accessPoint.getTitle()
|
||||
: context.getText(R.string.pref_title_network_details);
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
new SubSettingLauncher(getContext())
|
||||
.setTitleText(title)
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(pref.getExtras())
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.launch();
|
||||
} else {
|
||||
new SubSettingLauncher(getContext())
|
||||
.setTitleText(title)
|
||||
.setDestination(WifiNetworkDetailsFragment.class.getName())
|
||||
@@ -961,6 +970,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.launch();
|
||||
}
|
||||
}
|
||||
|
||||
private Network getCurrentWifiNetwork() {
|
||||
return mWifiManager != null ? mWifiManager.getCurrentNetwork() : null;
|
||||
|
@@ -190,7 +190,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
private void addPreferences() {
|
||||
addPreferencesFromResource(R.xml.wifi_settings);
|
||||
addPreferencesFromResource(R.xml.wifi_settings2);
|
||||
|
||||
mConnectedWifiEntryPreferenceCategory = findPreference(PREF_KEY_CONNECTED_ACCESS_POINTS);
|
||||
mWifiEntryPreferenceCategory = findPreference(PREF_KEY_ACCESS_POINTS);
|
||||
|
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
/**
|
||||
* {@link BasePreferenceController} that launches Wi-Fi Easy Connect configurator flow
|
||||
*/
|
||||
public class AddDevicePreferenceController2 extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "AddDevicePreferenceController2";
|
||||
|
||||
private static final String KEY_ADD_DEVICE = "add_device_to_network";
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
public AddDevicePreferenceController2(Context context) {
|
||||
super(context, KEY_ADD_DEVICE);
|
||||
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate with an {@link AccessPoint}.
|
||||
*/
|
||||
public AddDevicePreferenceController2 init(AccessPoint accessPoint) {
|
||||
mAccessPoint = accessPoint;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mAccessPoint)) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_ADD_DEVICE.equals(preference.getKey())) {
|
||||
WifiDppUtils.showLockScreen(mContext, () -> launchWifiDppConfiguratorQrCodeScanner());
|
||||
return true; /* click is handled */
|
||||
}
|
||||
|
||||
return false; /* click is not handled */
|
||||
}
|
||||
|
||||
private void launchWifiDppConfiguratorQrCodeScanner() {
|
||||
final Intent intent = WifiDppUtils.getConfiguratorQrCodeScannerIntentOrNull(mContext,
|
||||
mWifiManager, mAccessPoint);
|
||||
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "Launch Wi-Fi QR code scanner with a wrong Wi-Fi network!");
|
||||
} else {
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import android.app.backup.BackupManager;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* {@link AbstractPreferenceController} that controls whether the wifi network is metered or not
|
||||
*/
|
||||
public class WifiMeteredPreferenceController2 extends BasePreferenceController implements
|
||||
Preference.OnPreferenceChangeListener, WifiDialog.WifiDialogListener {
|
||||
|
||||
private static final String KEY_WIFI_METERED = "metered";
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private WifiManager mWifiManager;
|
||||
private Preference mPreference;
|
||||
|
||||
public WifiMeteredPreferenceController2(Context context, WifiConfiguration wifiConfiguration) {
|
||||
super(context, KEY_WIFI_METERED);
|
||||
mWifiConfiguration = wifiConfiguration;
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final DropDownPreference dropDownPreference = (DropDownPreference) preference;
|
||||
final int meteredOverride = getMeteredOverride();
|
||||
dropDownPreference.setValue(Integer.toString(meteredOverride));
|
||||
updateSummary(dropDownPreference, meteredOverride);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mWifiConfiguration != null) {
|
||||
mWifiConfiguration.meteredOverride = Integer.parseInt((String) newValue);
|
||||
}
|
||||
mWifiManager.updateNetwork(mWifiConfiguration);
|
||||
// Stage the backup of the SettingsProvider package which backs this up
|
||||
BackupManager.dataChanged("com.android.providers.settings");
|
||||
updateSummary((DropDownPreference) preference, getMeteredOverride());
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getMeteredOverride() {
|
||||
if (mWifiConfiguration != null) {
|
||||
// Wrap the meteredOverride since robolectric cannot recognize it
|
||||
return mWifiConfiguration.meteredOverride;
|
||||
}
|
||||
return WifiConfiguration.METERED_OVERRIDE_NONE;
|
||||
}
|
||||
|
||||
private void updateSummary(DropDownPreference preference, int meteredOverride) {
|
||||
preference.setSummary(preference.getEntries()[meteredOverride]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
if (dialog.getController() != null) {
|
||||
final WifiConfiguration newConfig = dialog.getController().getConfig();
|
||||
if (newConfig == null || mWifiConfiguration == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newConfig.meteredOverride != mWifiConfiguration.meteredOverride) {
|
||||
mWifiConfiguration = newConfig;
|
||||
onPreferenceChange(mPreference, String.valueOf(newConfig.meteredOverride));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.wifi.WifiConfigUiBase;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Detail page for the currently connected wifi network.
|
||||
*
|
||||
* <p>The AccessPoint should be saved to the intent Extras when launching this class via
|
||||
* {@link AccessPoint#saveWifiState(Bundle)} in order to properly render this page.
|
||||
*/
|
||||
public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
||||
WifiDialog.WifiDialogListener {
|
||||
|
||||
private static final String TAG = "WifiNetworkDetailsFrg2";
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private WifiDetailPreferenceController2 mWifiDetailPreferenceController2;
|
||||
private List<WifiDialog.WifiDialogListener> mWifiDialogListeners = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
mAccessPoint = new AccessPoint(context, getArguments());
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.WIFI_NETWORK_DETAILS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.wifi_network_details_fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == WIFI_DIALOG_ID) {
|
||||
return SettingsEnums.DIALOG_WIFI_AP_EDIT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
if (getActivity() == null || mWifiDetailPreferenceController2 == null
|
||||
|| mAccessPoint == null) {
|
||||
return null;
|
||||
}
|
||||
return WifiDialog.createModal(getActivity(), this, mAccessPoint,
|
||||
WifiConfigUiBase.MODE_MODIFY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.wifi_modify);
|
||||
item.setIcon(com.android.internal.R.drawable.ic_mode_edit);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case Menu.FIRST:
|
||||
if (!mWifiDetailPreferenceController2.canModifyNetwork()) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
|
||||
RestrictedLockUtilsInternal.getDeviceOwner(getContext()));
|
||||
} else {
|
||||
showDialog(WIFI_DIALOG_ID);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
|
||||
|
||||
mWifiDetailPreferenceController2 = WifiDetailPreferenceController2.newInstance(
|
||||
mAccessPoint,
|
||||
cm,
|
||||
context,
|
||||
this,
|
||||
new Handler(Looper.getMainLooper()), // UI thread.
|
||||
getSettingsLifecycle(),
|
||||
context.getSystemService(WifiManager.class),
|
||||
mMetricsFeatureProvider);
|
||||
|
||||
controllers.add(mWifiDetailPreferenceController2);
|
||||
controllers.add(new AddDevicePreferenceController2(context).init(mAccessPoint));
|
||||
|
||||
final WifiMeteredPreferenceController2 meteredPreferenceController2 =
|
||||
new WifiMeteredPreferenceController2(context, mAccessPoint.getConfig());
|
||||
controllers.add(meteredPreferenceController2);
|
||||
|
||||
final WifiPrivacyPreferenceController2 privacyController2 =
|
||||
new WifiPrivacyPreferenceController2(context);
|
||||
privacyController2.setWifiConfiguration(mAccessPoint.getConfig());
|
||||
privacyController2.setIsEphemeral(mAccessPoint.isEphemeral());
|
||||
privacyController2.setIsPasspoint(
|
||||
mAccessPoint.isPasspoint() || mAccessPoint.isPasspointConfig());
|
||||
controllers.add(privacyController2);
|
||||
|
||||
// Sets callback listener for wifi dialog.
|
||||
mWifiDialogListeners.add(mWifiDetailPreferenceController2);
|
||||
mWifiDialogListeners.add(privacyController2);
|
||||
mWifiDialogListeners.add(meteredPreferenceController2);
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
for (WifiDialog.WifiDialogListener listener : mWifiDialogListeners) {
|
||||
listener.onSubmit(dialog);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
/**
|
||||
* {@link AbstractPreferenceController} that controls whether the wifi network is mac randomized
|
||||
* or not
|
||||
*/
|
||||
public class WifiPrivacyPreferenceController2 extends BasePreferenceController implements
|
||||
Preference.OnPreferenceChangeListener, WifiDialog.WifiDialogListener {
|
||||
|
||||
private static final String KEY_WIFI_PRIVACY = "privacy";
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private WifiManager mWifiManager;
|
||||
private boolean mIsEphemeral = false;
|
||||
private boolean mIsPasspoint = false;
|
||||
private Preference mPreference;
|
||||
|
||||
public WifiPrivacyPreferenceController2(Context context) {
|
||||
super(context, KEY_WIFI_PRIVACY);
|
||||
mWifiConfiguration = null;
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
public void setWifiConfiguration(WifiConfiguration wifiConfiguration) {
|
||||
mWifiConfiguration = wifiConfiguration;
|
||||
}
|
||||
|
||||
public void setIsEphemeral(boolean isEphemeral) {
|
||||
mIsEphemeral = isEphemeral;
|
||||
}
|
||||
|
||||
public void setIsPasspoint(boolean isPasspoint) {
|
||||
mIsPasspoint = isPasspoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mWifiManager.isConnectedMacRandomizationSupported()
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final DropDownPreference dropDownPreference = (DropDownPreference) preference;
|
||||
final int randomizationLevel = getRandomizationValue();
|
||||
dropDownPreference.setValue(Integer.toString(randomizationLevel));
|
||||
updateSummary(dropDownPreference, randomizationLevel);
|
||||
|
||||
// Makes preference not selectable, when this is a ephemeral network.
|
||||
if (mIsEphemeral || mIsPasspoint) {
|
||||
preference.setSelectable(false);
|
||||
dropDownPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mWifiConfiguration != null) {
|
||||
mWifiConfiguration.macRandomizationSetting = Integer.parseInt((String) newValue);
|
||||
mWifiManager.updateNetwork(mWifiConfiguration);
|
||||
|
||||
// To activate changing, we need to reconnect network. WiFi will auto connect to
|
||||
// current network after disconnect(). Only needed when this is connected network.
|
||||
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (wifiInfo != null && wifiInfo.getNetworkId() == mWifiConfiguration.networkId) {
|
||||
mWifiManager.disconnect();
|
||||
}
|
||||
}
|
||||
updateSummary((DropDownPreference) preference, Integer.parseInt((String) newValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getRandomizationValue() {
|
||||
if (mWifiConfiguration != null) {
|
||||
return mWifiConfiguration.macRandomizationSetting;
|
||||
}
|
||||
return WifiConfiguration.RANDOMIZATION_PERSISTENT;
|
||||
}
|
||||
|
||||
private static final int PREF_RANDOMIZATION_PERSISTENT = 0;
|
||||
private static final int PREF_RANDOMIZATION_NONE = 1;
|
||||
|
||||
/**
|
||||
* Returns preference index value.
|
||||
*
|
||||
* @param macRandomized is mac randomized value
|
||||
* @return index value of preference
|
||||
*/
|
||||
public static int translateMacRandomizedValueToPrefValue(int macRandomized) {
|
||||
return (macRandomized == WifiConfiguration.RANDOMIZATION_PERSISTENT)
|
||||
? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mac randomized value.
|
||||
*
|
||||
* @param prefMacRandomized is preference index value
|
||||
* @return mac randomized value
|
||||
*/
|
||||
public static int translatePrefValueToMacRandomizedValue(int prefMacRandomized) {
|
||||
return (prefMacRandomized == PREF_RANDOMIZATION_PERSISTENT)
|
||||
? WifiConfiguration.RANDOMIZATION_PERSISTENT : WifiConfiguration.RANDOMIZATION_NONE;
|
||||
}
|
||||
|
||||
private void updateSummary(DropDownPreference preference, int macRandomized) {
|
||||
// Translates value here to set RANDOMIZATION_PERSISTENT as first item in UI for better UX.
|
||||
final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized);
|
||||
preference.setSummary(preference.getEntries()[prefMacRandomized]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
if (dialog.getController() != null) {
|
||||
final WifiConfiguration newConfig = dialog.getController().getConfig();
|
||||
if (newConfig == null || mWifiConfiguration == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newConfig.macRandomizationSetting != mWifiConfiguration.macRandomizationSetting) {
|
||||
mWifiConfiguration = newConfig;
|
||||
onPreferenceChange(mPreference, String.valueOf(newConfig.macRandomizationSetting));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.AccessPointPreference.UserBadgeCache;
|
||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller that manages a PreferenceGroup, which contains a list of saved access points.
|
||||
*/
|
||||
public class SavedAccessPointsPreferenceController2 extends BasePreferenceController implements
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
protected final WifiManager mWifiManager;
|
||||
private final UserBadgeCache mUserBadgeCache;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
private SavedAccessPointsWifiSettings2 mHost;
|
||||
@VisibleForTesting
|
||||
List<AccessPoint> mAccessPoints;
|
||||
|
||||
public SavedAccessPointsPreferenceController2(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(context.getPackageManager());
|
||||
mWifiManager = context.getSystemService(WifiManager.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@link SavedAccessPointsWifiSettings2} for click callback action.
|
||||
*/
|
||||
public SavedAccessPointsPreferenceController2 setHost(SavedAccessPointsWifiSettings2 host) {
|
||||
mHost = host;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mAccessPoints.size() > 0 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
mPreferenceGroup = screen.findPreference(getPreferenceKey());
|
||||
refreshSavedAccessPoints();
|
||||
updatePreference();
|
||||
super.displayPreference(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (mHost != null) {
|
||||
final Preference preferenceInGroup =
|
||||
mPreferenceGroup.findPreference(preference.getKey());
|
||||
mHost.showWifiPage((AccessPointPreference) preferenceInGroup);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void refreshSavedAccessPoints() {
|
||||
mAccessPoints = WifiSavedConfigUtils.getAllConfigs(mContext, mWifiManager).stream()
|
||||
.filter(accessPoint -> !accessPoint.isPasspointConfig())
|
||||
.sorted(SavedNetworkComparator2.INSTANCE)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void updatePreference() {
|
||||
mPreferenceGroup.removeAll();
|
||||
for (AccessPoint accessPoint : mAccessPoints) {
|
||||
final String key = accessPoint.getKey();
|
||||
|
||||
final AccessPointPreference preference = new AccessPointPreference(accessPoint,
|
||||
mContext, mUserBadgeCache, true /* forSavedNetworks */);
|
||||
preference.setKey(key);
|
||||
preference.setIcon(null);
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
|
||||
mPreferenceGroup.addPreference(preference);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
|
||||
/**
|
||||
* UI to manage saved networks/access points.
|
||||
*/
|
||||
public class SavedAccessPointsWifiSettings2 extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "SavedAccessPoints2";
|
||||
|
||||
@VisibleForTesting
|
||||
Bundle mAccessPointSavedState;
|
||||
private AccessPoint mSelectedAccessPoint;
|
||||
|
||||
// Instance state key
|
||||
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.WIFI_SAVED_ACCESS_POINTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.wifi_display_saved_access_points2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
use(SavedAccessPointsPreferenceController2.class)
|
||||
.setHost(this);
|
||||
use(SubscribedAccessPointsPreferenceController2.class)
|
||||
.setHost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
||||
mAccessPointSavedState =
|
||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||
} else {
|
||||
mAccessPointSavedState = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (mAccessPointSavedState != null) {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
use(SavedAccessPointsPreferenceController2.class).displayPreference(screen);
|
||||
use(SubscribedAccessPointsPreferenceController2.class).displayPreference(screen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows {@link WifiNetworkDetailsFragment2} for assigned {@link AccessPointPreference}.
|
||||
*/
|
||||
public void showWifiPage(@Nullable AccessPointPreference accessPoint) {
|
||||
removeDialog(WifiSettings.WIFI_DIALOG_ID);
|
||||
|
||||
if (accessPoint != null) {
|
||||
// Save the access point and edit mode
|
||||
mSelectedAccessPoint = accessPoint.getAccessPoint();
|
||||
} else {
|
||||
// No access point is selected. Clear saved state.
|
||||
mSelectedAccessPoint = null;
|
||||
mAccessPointSavedState = null;
|
||||
}
|
||||
|
||||
if (mSelectedAccessPoint == null) {
|
||||
mSelectedAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
|
||||
}
|
||||
final Bundle savedState = new Bundle();
|
||||
mSelectedAccessPoint.saveWifiState(savedState);
|
||||
|
||||
new SubSettingLauncher(getContext())
|
||||
.setTitleText(mSelectedAccessPoint.getTitle())
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(savedState)
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
// If the dialog is showing (indicated by the existence of mSelectedAccessPoint), then we
|
||||
// save its state.
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mAccessPointSavedState = new Bundle();
|
||||
mSelectedAccessPoint.saveWifiState(mAccessPointSavedState);
|
||||
outState.putBundle(SAVE_DIALOG_ACCESS_POINT_STATE, mAccessPointSavedState);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import android.icu.text.Collator;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* For {@link AccessPoint} sorting before desplaying.
|
||||
*/
|
||||
public final class SavedNetworkComparator2 {
|
||||
public static final Comparator<AccessPoint> INSTANCE =
|
||||
new Comparator<AccessPoint>() {
|
||||
final Collator mCollator = Collator.getInstance();
|
||||
|
||||
@Override
|
||||
public int compare(AccessPoint ap1, AccessPoint ap2) {
|
||||
return mCollator.compare(
|
||||
nullToEmpty(ap1.getTitle()), nullToEmpty(ap2.getTitle()));
|
||||
}
|
||||
|
||||
private String nullToEmpty(String string) {
|
||||
return (string == null) ? "" : string;
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller that manages a PreferenceGroup, which contains a list of subscribed access points.
|
||||
*/
|
||||
public class SubscribedAccessPointsPreferenceController2 extends
|
||||
SavedAccessPointsPreferenceController2 {
|
||||
|
||||
public SubscribedAccessPointsPreferenceController2(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshSavedAccessPoints() {
|
||||
mAccessPoints = WifiSavedConfigUtils.getAllConfigs(mContext, mWifiManager).stream()
|
||||
.filter(accessPoint -> accessPoint.isPasspointConfig())
|
||||
.sorted(SavedNetworkComparator2.INSTANCE)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@@ -38,6 +38,7 @@ import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
@@ -54,8 +55,10 @@ import com.android.settings.slices.SliceBackgroundWorker;
|
||||
import com.android.settings.slices.SliceBuilderUtils;
|
||||
import com.android.settings.wifi.WifiDialogActivity;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settings.wifi.WifiSettings2;
|
||||
import com.android.settings.wifi.WifiUtils;
|
||||
import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
|
||||
import com.android.settings.wifi.details2.WifiNetworkDetailsFragment2;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -247,13 +250,24 @@ public class WifiSlice implements CustomSliceable {
|
||||
accessPoint.saveWifiState(extras);
|
||||
|
||||
if (accessPoint.isActive()) {
|
||||
final Intent intent = new SubSettingLauncher(mContext)
|
||||
Intent intent;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
intent = new SubSettingLauncher(mContext)
|
||||
.setTitleRes(R.string.pref_title_network_details)
|
||||
.setDestination(WifiNetworkDetailsFragment2.class.getName())
|
||||
.setArguments(extras)
|
||||
.setSourceMetricsCategory(SettingsEnums.WIFI)
|
||||
.toIntent();
|
||||
return getActivityAction(requestCode, intent, icon, title);
|
||||
} else {
|
||||
intent = new SubSettingLauncher(mContext)
|
||||
.setTitleRes(R.string.pref_title_network_details)
|
||||
.setDestination(WifiNetworkDetailsFragment.class.getName())
|
||||
.setArguments(extras)
|
||||
.setSourceMetricsCategory(SettingsEnums.WIFI)
|
||||
.toIntent();
|
||||
return getActivityAction(requestCode, intent, icon, title);
|
||||
}
|
||||
} else if (WifiUtils.getConnectingType(accessPoint) != WifiUtils.CONNECT_TYPE_OTHERS) {
|
||||
final Intent intent = new Intent(mContext, ConnectToWifiHandler.class)
|
||||
.putExtra(WifiDialogActivity.KEY_ACCESS_POINT_STATE, extras);
|
||||
@@ -317,11 +331,21 @@ public class WifiSlice implements CustomSliceable {
|
||||
public Intent getIntent() {
|
||||
final String screenTitle = mContext.getText(R.string.wifi_settings).toString();
|
||||
final Uri contentUri = new Uri.Builder().appendPath(KEY_WIFI).build();
|
||||
final Intent intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
|
||||
Intent intent;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
WifiSettings2.class.getName(), KEY_WIFI, screenTitle,
|
||||
SettingsEnums.DIALOG_WIFI_AP_EDIT)
|
||||
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
|
||||
.setData(contentUri);
|
||||
} else {
|
||||
intent = SliceBuilderUtils.buildSearchResultPageIntent(mContext,
|
||||
WifiSettings.class.getName(), KEY_WIFI, screenTitle,
|
||||
SettingsEnums.DIALOG_WIFI_AP_EDIT)
|
||||
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
|
||||
.setData(contentUri);
|
||||
}
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiMeteredPreferenceController2Test {
|
||||
|
||||
private static final int METERED_OVERRIDE_NONE = 0;
|
||||
private static final int METERED_OVERRIDE_METERED = 1;
|
||||
private static final int METERED_OVERRIDE_NOT_METERED = 2;
|
||||
|
||||
@Mock
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
|
||||
private WifiMeteredPreferenceController2 mPreferenceController;
|
||||
private Context mContext;
|
||||
private DropDownPreference mDropDownPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mPreferenceController = spy(
|
||||
new WifiMeteredPreferenceController2(mContext, mWifiConfiguration));
|
||||
mDropDownPreference = new DropDownPreference(mContext);
|
||||
mDropDownPreference.setEntries(R.array.wifi_metered_entries);
|
||||
mDropDownPreference.setEntryValues(R.array.wifi_metered_values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiMetered_setCorrectValue() {
|
||||
doReturn(METERED_OVERRIDE_METERED).when(mPreferenceController).getMeteredOverride();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as metered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiNotMetered_setCorrectValue() {
|
||||
doReturn(METERED_OVERRIDE_NOT_METERED).when(mPreferenceController).getMeteredOverride();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as unmetered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiAuto_setCorrectValue() {
|
||||
doReturn(METERED_OVERRIDE_NONE).when(mPreferenceController).getMeteredOverride();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo("Detect automatically");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testController_resilientToNullConfig() {
|
||||
mPreferenceController = spy(new WifiMeteredPreferenceController2(mContext, null));
|
||||
|
||||
mPreferenceController.getMeteredOverride();
|
||||
mPreferenceController.onPreferenceChange(mDropDownPreference, 1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.details2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiPrivacyPreferenceController2Test {
|
||||
|
||||
private static final int PRIVACY_RANDOMIZED = WifiConfiguration.RANDOMIZATION_PERSISTENT;
|
||||
private static final int PRIVACY_TRUSTED = WifiConfiguration.RANDOMIZATION_NONE;
|
||||
|
||||
@Mock
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
|
||||
private WifiPrivacyPreferenceController2 mPreferenceController;
|
||||
private Context mContext;
|
||||
private DropDownPreference mDropDownPreference;
|
||||
private String[] mPerferenceStrings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
WifiPrivacyPreferenceController2 preferenceController =
|
||||
new WifiPrivacyPreferenceController2(mContext);
|
||||
preferenceController.setWifiConfiguration(mWifiConfiguration);
|
||||
mPreferenceController = spy(preferenceController);
|
||||
mDropDownPreference = new DropDownPreference(mContext);
|
||||
mDropDownPreference.setEntries(R.array.wifi_privacy_entries);
|
||||
mDropDownPreference.setEntryValues(R.array.wifi_privacy_values);
|
||||
|
||||
mPerferenceStrings = mContext.getResources().getStringArray(R.array.wifi_privacy_entries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiPrivacy_setCorrectValue() {
|
||||
doReturn(PRIVACY_TRUSTED).when(mPreferenceController).getRandomizationValue();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
int prefValue = mPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
PRIVACY_TRUSTED);
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo(mPerferenceStrings[prefValue]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wifiNotMetered_setCorrectValue() {
|
||||
doReturn(PRIVACY_RANDOMIZED).when(mPreferenceController).getRandomizationValue();
|
||||
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
int prefValue = mPreferenceController.translateMacRandomizedValueToPrefValue(
|
||||
PRIVACY_RANDOMIZED);
|
||||
assertThat(mDropDownPreference.getEntry()).isEqualTo(mPerferenceStrings[prefValue]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testController_resilientToNullConfig() {
|
||||
mPreferenceController = spy(new WifiPrivacyPreferenceController2(mContext));
|
||||
|
||||
mPreferenceController.getRandomizationValue();
|
||||
mPreferenceController.onPreferenceChange(mDropDownPreference, "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isNotEphemeralNetwork_shouldBeSelectable() {
|
||||
mPreferenceController.setIsEphemeral(false);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isEphemeralNetwork_shouldNotSelectable() {
|
||||
mPreferenceController.setIsEphemeral(true);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isNotPasspointNetwork_shouldBeSelectable() {
|
||||
mPreferenceController.setIsPasspoint(false);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isPasspointNetwork_shouldNotSelectable() {
|
||||
mPreferenceController.setIsPasspoint(true);
|
||||
mPreferenceController.updateState(mDropDownPreference);
|
||||
|
||||
assertThat(mDropDownPreference.isSelectable()).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowAccessPoint;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowWifiManager.class})
|
||||
public class SavedAccessPointsPreferenceController2Test {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
|
||||
private Context mContext;
|
||||
private WifiManager mWifiManager;
|
||||
private SavedAccessPointsWifiSettings2 mSettings;
|
||||
private SavedAccessPointsPreferenceController2 mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
mSettings = spy(new SavedAccessPointsWifiSettings2());
|
||||
mController = spy(new SavedAccessPointsPreferenceController2(mContext, "test_key"));
|
||||
mController.setHost(mSettings);
|
||||
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreferenceCategory);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailability_noSavedAccessPoint_shouldNotAvailable() {
|
||||
mController.mAccessPoints = new ArrayList<>();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailability_oneSavedAccessPoint_shouldAvailable() {
|
||||
final AccessPoint accessPoint = new AccessPoint(mContext, new Bundle() /* savedState */);
|
||||
mController.mAccessPoints = new ArrayList<AccessPoint>(Arrays.asList(accessPoint));
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void displayPreference_oneAccessPoint_shouldListNonSubscribedAPs() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "SSID";
|
||||
config.BSSID = "BSSID";
|
||||
config.networkId = 2;
|
||||
mWifiManager.addNetwork(config);
|
||||
|
||||
final ArgumentCaptor<AccessPointPreference> captor =
|
||||
ArgumentCaptor.forClass(AccessPointPreference.class);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mPreferenceCategory).addPreference(captor.capture());
|
||||
|
||||
final AccessPointPreference pref = captor.getValue();
|
||||
assertThat(pref.getTitle()).isEqualTo(config.SSID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void displayPreference_onePasspoint_shouldNotListSubscribedAPs() {
|
||||
mWifiManager.addOrUpdatePasspointConfiguration(
|
||||
SubscribedAccessPointsPreferenceController2Test.createMockPasspointConfiguration());
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mPreferenceCategory, never()).addPreference(any(AccessPointPreference.class));
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SavedAccessPointsWifiSettings2Test {
|
||||
|
||||
@Mock
|
||||
private SubscribedAccessPointsPreferenceController2 mSubscribedApController;
|
||||
@Mock
|
||||
private SavedAccessPointsPreferenceController2 mSavedApController;
|
||||
|
||||
private TestFragment mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mSettings = spy(new TestFragment());
|
||||
|
||||
doReturn(mSubscribedApController).when(mSettings)
|
||||
.use(SubscribedAccessPointsPreferenceController2.class);
|
||||
doReturn(mSavedApController).when(mSettings)
|
||||
.use(SavedAccessPointsPreferenceController2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyConstants() {
|
||||
assertThat(mSettings.getMetricsCategory()).isEqualTo(MetricsEvent.WIFI_SAVED_ACCESS_POINTS);
|
||||
assertThat(mSettings.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.wifi_display_saved_access_points2);
|
||||
}
|
||||
|
||||
public static class TestFragment extends SavedAccessPointsWifiSettings2 {
|
||||
|
||||
public <T extends AbstractPreferenceController> T use(Class<T> clazz) {
|
||||
return super.use(clazz);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi.savedaccesspoints2;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.hotspot2.PasspointConfiguration;
|
||||
import android.net.wifi.hotspot2.pps.HomeSp;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowAccessPoint;
|
||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowWifiManager.class})
|
||||
public class SubscribedAccessPointsPreferenceController2Test {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
|
||||
private Context mContext;
|
||||
private WifiManager mWifiManager;
|
||||
private SavedAccessPointsWifiSettings2 mSettings;
|
||||
private SubscribedAccessPointsPreferenceController2 mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mWifiManager = mContext.getSystemService(WifiManager.class);
|
||||
mSettings = spy(new SavedAccessPointsWifiSettings2());
|
||||
mController = spy(new SubscribedAccessPointsPreferenceController2(mContext, "test_key"));
|
||||
mController.setHost(mSettings);
|
||||
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreferenceCategory);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void displayPreference_oneAccessPoint_shouldNotListNonSubscribedAPs() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "SSID";
|
||||
config.BSSID = "BSSID";
|
||||
config.networkId = 2;
|
||||
mWifiManager.addNetwork(config);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mPreferenceCategory, never()).addPreference(any(AccessPointPreference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowAccessPoint.class)
|
||||
public void displayPreference_onePasspoint_shouldListSubscribedAPs() {
|
||||
mWifiManager.addOrUpdatePasspointConfiguration(createMockPasspointConfiguration());
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
final ArgumentCaptor<AccessPointPreference> captor =
|
||||
ArgumentCaptor.forClass(AccessPointPreference.class);
|
||||
verify(mPreferenceCategory).addPreference(captor.capture());
|
||||
|
||||
final AccessPointPreference pref = captor.getValue();
|
||||
assertThat(pref.getTitle()).isEqualTo("TESTPASSPOINT");
|
||||
}
|
||||
|
||||
public static PasspointConfiguration createMockPasspointConfiguration() {
|
||||
final PasspointConfiguration config = new PasspointConfiguration();
|
||||
final HomeSp homeSp = new HomeSp();
|
||||
homeSp.setFqdn("FQDN");
|
||||
homeSp.setFriendlyName("TESTPASSPOINT");
|
||||
config.setHomeSp(homeSp);
|
||||
return config;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user