Merge "[Wi-Fi] Remove the files which use SettingsLib Wi-Fi objects"
This commit is contained in:
committed by
Android (Google) Code Review
commit
bc7c42621b
@@ -124,7 +124,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
|
||||
|
||||
@Override
|
||||
public int getMode() {
|
||||
return WifiConfigUiBase.MODE_CONNECT;
|
||||
return WifiConfigUiBase2.MODE_CONNECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -40,7 +40,6 @@ 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;
|
||||
@@ -67,7 +66,6 @@ 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;
|
||||
@@ -294,14 +292,8 @@ public class WifiConfigController2 implements TextWatcher,
|
||||
? HIDDEN_NETWORK
|
||||
: NOT_HIDDEN_NETWORK);
|
||||
|
||||
int prefMacValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
prefMacValue = WifiPrivacyPreferenceController2
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
} else {
|
||||
prefMacValue = WifiPrivacyPreferenceController
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
}
|
||||
final int prefMacValue = WifiPrivacyPreferenceController2
|
||||
.translateMacRandomizedValueToPrefValue(config.macRandomizationSetting);
|
||||
mPrivacySettingsSpinner.setSelection(prefMacValue);
|
||||
|
||||
if (config.getIpConfiguration().getIpAssignment() == IpAssignment.STATIC) {
|
||||
@@ -814,15 +806,9 @@ public class WifiConfigController2 implements TextWatcher,
|
||||
}
|
||||
|
||||
if (mPrivacySettingsSpinner != null) {
|
||||
int macValue;
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||
macValue = WifiPrivacyPreferenceController2.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
} else {
|
||||
macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(
|
||||
mPrivacySettingsSpinner.getSelectedItemPosition());
|
||||
}
|
||||
config.macRandomizationSetting = macValue;
|
||||
config.macRandomizationSetting = WifiPrivacyPreferenceController2
|
||||
.translatePrefValueToMacRandomizedValue(mPrivacySettingsSpinner
|
||||
.getSelectedItemPosition());
|
||||
}
|
||||
|
||||
return config;
|
||||
|
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.details;
|
||||
|
||||
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.
|
||||
*
|
||||
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
|
||||
* future, please develop in
|
||||
* {@link com.android.settings.wifi.details2.AddDevicePreferenceController2}.
|
||||
*/
|
||||
public class AddDevicePreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "AddDevicePreferenceController";
|
||||
|
||||
private static final String KEY_ADD_DEVICE = "add_device_to_network";
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
public AddDevicePreferenceController(Context context) {
|
||||
super(context, KEY_ADD_DEVICE);
|
||||
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
public AddDevicePreferenceController 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.details;
|
||||
|
||||
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.
|
||||
*
|
||||
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
|
||||
* future, please develop in
|
||||
* {@link com.android.settings.wifi.details2.WifiMeteredPreferenceControlle2}.
|
||||
*/
|
||||
public class WifiMeteredPreferenceController 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 WifiMeteredPreferenceController(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.details;
|
||||
|
||||
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.
|
||||
*
|
||||
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
|
||||
* future, please develop in
|
||||
* {@link com.android.settings.wifi.details2.WifiNetworkDetailsFragment2}.
|
||||
*/
|
||||
public class WifiNetworkDetailsFragment extends DashboardFragment implements
|
||||
WifiDialog.WifiDialogListener {
|
||||
|
||||
private static final String TAG = "WifiNetworkDetailsFrg";
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private WifiDetailPreferenceController mWifiDetailPreferenceController;
|
||||
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 || mWifiDetailPreferenceController == 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 (!mWifiDetailPreferenceController.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);
|
||||
|
||||
mWifiDetailPreferenceController = WifiDetailPreferenceController.newInstance(
|
||||
mAccessPoint,
|
||||
cm,
|
||||
context,
|
||||
this,
|
||||
new Handler(Looper.getMainLooper()), // UI thread.
|
||||
getSettingsLifecycle(),
|
||||
context.getSystemService(WifiManager.class),
|
||||
mMetricsFeatureProvider);
|
||||
|
||||
controllers.add(mWifiDetailPreferenceController);
|
||||
controllers.add(new AddDevicePreferenceController(context).init(mAccessPoint));
|
||||
|
||||
final WifiMeteredPreferenceController meteredPreferenceController =
|
||||
new WifiMeteredPreferenceController(context, mAccessPoint.getConfig());
|
||||
controllers.add(meteredPreferenceController);
|
||||
|
||||
final WifiPrivacyPreferenceController privacyController =
|
||||
new WifiPrivacyPreferenceController(context);
|
||||
privacyController.setWifiConfiguration(mAccessPoint.getConfig());
|
||||
privacyController.setIsEphemeral(mAccessPoint.isEphemeral());
|
||||
privacyController.setIsPasspoint(
|
||||
mAccessPoint.isPasspoint() || mAccessPoint.isPasspointConfig());
|
||||
controllers.add(privacyController);
|
||||
|
||||
// Sets callback listener for wifi dialog.
|
||||
mWifiDialogListeners.add(mWifiDetailPreferenceController);
|
||||
mWifiDialogListeners.add(privacyController);
|
||||
mWifiDialogListeners.add(meteredPreferenceController);
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
for (WifiDialog.WifiDialogListener listener : mWifiDialogListeners) {
|
||||
listener.onSubmit(dialog);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user