[Wi-Fi] Replace WifiTracker with WifiPickerTracker in WifiSettings

WifiSettings uses WifiTracker in SettingsLib while WifiSettings2
uses WifiPickerTracker in WifiSettingsLib.

1. Remove WifiSettings.
2. Rename WifiSettings2 to WifiSettings.
3. Remove the files only used in the removed WifiSettings.
   (Saved networks files are not included)

Bug: 152571756
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi
      atest WifiSettingsUiTest
Change-Id: I800b434c8049121db115cff87d51e164e4529999
This commit is contained in:
Arc Wang
2020-05-11 21:30:42 +08:00
parent 29d45e2d6b
commit 41f23de712
20 changed files with 737 additions and 3265 deletions

View File

@@ -34,7 +34,10 @@ import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.wifi.dpp.WifiDppUtils;
public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase,
/**
* A full screen UI component for users to edit and add a Wi-Fi network.
*/
public class AddNetworkFragment extends InstrumentedFragment implements WifiConfigUiBase2,
View.OnClickListener {
final static String WIFI_CONFIG_KEY = "wifi_config_key";
@@ -46,7 +49,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
private WifiConfigController mUIController;
private WifiConfigController2 mUIController;
private Button mSubmitBtn;
private Button mCancelBtn;
@@ -76,7 +79,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
mSubmitBtn.setOnClickListener(this);
mCancelBtn.setOnClickListener(this);
ssidScannerButton.setOnClickListener(this);
mUIController = new WifiConfigController(this, rootView, null, getMode());
mUIController = new WifiConfigController2(this, rootView, null, getMode());
return rootView;
}
@@ -124,7 +127,7 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
}
@Override
public WifiConfigController getController() {
public WifiConfigController2 getController() {
return mUIController;
}

View File

@@ -1,91 +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;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.Network;
import android.net.NetworkCapabilities;
import com.android.internal.util.Preconditions;
/** Listens for changes to NetworkCapabilities to update the ConnectedAccessPointPreference. */
class CaptivePortalNetworkCallback extends NetworkCallback {
private final ConnectedAccessPointPreference mConnectedApPreference;
private final Network mNetwork;
private boolean mIsCaptivePortal;
CaptivePortalNetworkCallback(
Network network, ConnectedAccessPointPreference connectedApPreference) {
mNetwork = Preconditions.checkNotNull(network);
mConnectedApPreference = Preconditions.checkNotNull(connectedApPreference);
}
@Override
public final void onLost(Network network) {
if (mNetwork.equals(network)) {
setIsCaptivePortal(false);
}
}
@Override
public final void onCapabilitiesChanged(Network network,
NetworkCapabilities networkCapabilities) {
if (mNetwork.equals(network)) {
boolean isCaptivePortal = WifiUtils.canSignIntoNetwork(networkCapabilities);
setIsCaptivePortal(isCaptivePortal);
mConnectedApPreference.setCaptivePortal(isCaptivePortal);
}
}
/**
* Called when captive portal capability changes for the current network. Default implementation
* is a no-op. Use {@link CaptivePortalNetworkCallback#isCaptivePortal()} to read new
* capability.
*/
public void onCaptivePortalCapabilityChanged() {}
private void setIsCaptivePortal(boolean isCaptivePortal) {
if (isCaptivePortal == mIsCaptivePortal) {
return;
}
mIsCaptivePortal = isCaptivePortal;
onCaptivePortalCapabilityChanged();
}
/**
* Returns true if the supplied network and preference are not null and are the same as the
* originally supplied values.
*/
public final boolean isSameNetworkAndPreference(
Network network, ConnectedAccessPointPreference connectedApPreference) {
return mNetwork.equals(network) && mConnectedApPreference == connectedApPreference;
}
/**
* Returns true if the most recent update to the NetworkCapabilities indicates a captive portal
* network and the Network was not lost in the interim.
*/
public final boolean isCaptivePortal() {
return mIsCaptivePortal;
}
/** Returns the currently associated network. */
public final Network getNetwork() {
return mNetwork;
}
}

View File

@@ -1,178 +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;
import android.app.ActionBar;
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
import com.android.settingslib.wifi.AccessPoint;
/**
* Detail page for configuring Wi-Fi network.
*
* The AccessPoint should be saved to the argument when launching this class 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 ConfigureWifiEntryFragment}.
*/
public class ConfigureAccessPointFragment extends InstrumentedFragment implements WifiConfigUiBase {
public static final String NETWORK_CONFIG_KEY = "network_config_key";
private static final int SUBMIT_BUTTON_ID = android.R.id.button1;
private static final int CANCEL_BUTTON_ID = android.R.id.button2;
private WifiConfigController mUiController;
private Button mSubmitBtn;
private Button mCancelBtn;
private AccessPoint mAccessPoint;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mAccessPoint = new AccessPoint(context, getArguments());
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_WIFI_CONFIGURE_NETWORK;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.wifi_add_network_view,
container, false /* attachToRoot */);
final Button neutral = rootView.findViewById(android.R.id.button3);
if (neutral != null) {
neutral.setVisibility(View.GONE);
}
mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID);
mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID);
mSubmitBtn.setOnClickListener(view -> handleSubmitAction());
mCancelBtn.setOnClickListener(view -> handleCancelAction());
mUiController = new WifiConfigController(this, rootView, mAccessPoint,
getMode(), false /* requestFocus */);
/**
* For this add AccessPoint UI, need to remove the Home button, so set related feature as
* false.
*/
final ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
}
return rootView;
}
@Override
public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
mUiController.updatePassword();
}
@Override
public int getMode() {
return WifiConfigUiBase.MODE_CONNECT;
}
@Override
public WifiConfigController getController() {
return mUiController;
}
@Override
public void dispatchSubmit() {
handleSubmitAction();
}
@Override
public void setTitle(int id) {
getActivity().setTitle(id);
}
@Override
public void setTitle(CharSequence title) {
getActivity().setTitle(title);
}
@Override
public void setSubmitButton(CharSequence text) {
mSubmitBtn.setText(text);
}
@Override
public void setCancelButton(CharSequence text) {
mCancelBtn.setText(text);
}
@Override
public void setForgetButton(CharSequence text) {
// AddNetwork doesn't need forget button.
}
@Override
public Button getSubmitButton() {
return mSubmitBtn;
}
@Override
public Button getCancelButton() {
return mCancelBtn;
}
@Override
public Button getForgetButton() {
// AddNetwork doesn't need forget button.
return null;
}
@VisibleForTesting
void handleSubmitAction() {
final Intent intent = new Intent();
final Activity activity = getActivity();
intent.putExtra(NETWORK_CONFIG_KEY, mUiController.getConfig());
activity.setResult(Activity.RESULT_OK, intent);
activity.finish();
}
@VisibleForTesting
void handleCancelAction() {
final Activity activity = getActivity();
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
}
}

View File

@@ -1,99 +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;
import android.content.Context;
import android.view.View;
import androidx.annotation.DrawableRes;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settingslib.wifi.AccessPoint;
/**
* An AP preference for the currently connected AP.
*
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
* future, please develop in {@link ConnectedWifiEntryPreference}.
*/
public class ConnectedAccessPointPreference extends LongPressAccessPointPreference implements
View.OnClickListener {
private OnGearClickListener mOnGearClickListener;
private boolean mIsCaptivePortal;
public ConnectedAccessPointPreference(AccessPoint accessPoint, Context context,
UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks,
Fragment fragment) {
super(accessPoint, context, cache, forSavedNetworks, iconResId, fragment);
}
@Override
protected int getWidgetLayoutResourceId() {
return R.layout.preference_widget_gear_optional_background;
}
@Override
public void refresh() {
super.refresh();
setShowDivider(mIsCaptivePortal);
if (mIsCaptivePortal) {
setSummary(R.string.wifi_tap_to_sign_in);
}
}
public void setOnGearClickListener(OnGearClickListener l) {
mOnGearClickListener = l;
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final View gear = holder.findViewById(R.id.settings_button);
gear.setOnClickListener(this);
final View gearNoBg = holder.findViewById(R.id.settings_button_no_background);
gearNoBg.setVisibility(mIsCaptivePortal ? View.INVISIBLE : View.VISIBLE);
gear.setVisibility(mIsCaptivePortal ? View.VISIBLE : View.INVISIBLE);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.settings_button) {
if (mOnGearClickListener != null) {
mOnGearClickListener.onGearClick(this);
}
}
}
public void setCaptivePortal(boolean isCaptivePortal) {
if (mIsCaptivePortal != isCaptivePortal) {
mIsCaptivePortal = isCaptivePortal;
refresh();
}
}
public interface OnGearClickListener {
void onGearClick(ConnectedAccessPointPreference p);
}
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright (C) 2015 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;
import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceViewHolder;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPointPreference;
/**
* An AP preference for the currently connected AP.
*
* Migrating from Wi-Fi SettingsLib to to WifiTrackerLib, this object will be removed in the near
* future, please develop in {@link com.android.settingslib.wifi.LongPressWifiEntryPreference}.
*/
public class LongPressAccessPointPreference extends AccessPointPreference {
private final Fragment mFragment;
public LongPressAccessPointPreference(AccessPoint accessPoint, Context context,
UserBadgeCache cache, boolean forSavedNetworks, int iconResId, Fragment fragment) {
super(accessPoint, context, cache, iconResId, forSavedNetworks);
mFragment = fragment;
}
@Override
public void onBindViewHolder(final PreferenceViewHolder view) {
super.onBindViewHolder(view);
if (mFragment != null) {
view.itemView.setOnCreateContextMenuListener(mFragment);
view.itemView.setTag(this);
view.itemView.setLongClickable(true);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff