[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:
Arc Wang
2019-11-04 17:03:15 +08:00
parent b4a6245d8d
commit 75dc89b122
25 changed files with 4704 additions and 38 deletions

View File

@@ -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(
mPrivacySettingsSpinner.getSelectedItemPosition());
int macValue;
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
macValue = WifiPrivacyPreferenceController2.translatePrefValueToMacRandomizedValue(
mPrivacySettingsSpinner.getSelectedItemPosition());
} else {
macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
mPrivacySettingsSpinner.getSelectedItemPosition());
}
config.macRandomizationSetting = macValue;
}

View File

@@ -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,17 +130,31 @@ public class WifiConnectionPreferenceController extends AbstractPreferenceContro
mPreference.refresh();
mPreference.setOrder(order);
mPreference.setOnPreferenceClickListener(pref -> {
Bundle args = new Bundle();
mPreference.getAccessPoint().saveWifiState(args);
new SubSettingLauncher(mPrefContext)
.setTitleRes(R.string.pref_title_network_details)
.setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(args)
.setSourceMetricsCategory(mMetricsCategory)
.launch();
return true;
});
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);
new SubSettingLauncher(mPrefContext)
.setTitleRes(R.string.pref_title_network_details)
.setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(args)
.setSourceMetricsCategory(mMetricsCategory)
.launch();
return true;
});
}
mPreferenceGroup.addPreference(mPreference);
}
}

View File

@@ -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;

View File

@@ -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,12 +955,21 @@ public class WifiSettings extends RestrictedSettingsFragment
? accessPoint.getTitle()
: context.getText(R.string.pref_title_network_details);
new SubSettingLauncher(getContext())
.setTitleText(title)
.setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(pref.getExtras())
.setSourceMetricsCategory(getMetricsCategory())
.launch();
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())
.setArguments(pref.getExtras())
.setSourceMetricsCategory(getMetricsCategory())
.launch();
}
}
private Network getCurrentWifiNetwork() {

View File

@@ -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);

View File

@@ -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

View File

@@ -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));
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
};
}

View File

@@ -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());
}
}

View File

@@ -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)
.setTitleRes(R.string.pref_title_network_details)
.setDestination(WifiNetworkDetailsFragment.class.getName())
.setArguments(extras)
.setSourceMetricsCategory(SettingsEnums.WIFI)
.toIntent();
return getActivityAction(requestCode, intent, icon, title);
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;
}