Merge "[Wi-Fi] Replace WifiTracker with WifiPickerTracker in WifiSettings"

This commit is contained in:
Arc Wang
2020-05-18 05:58:33 +00:00
committed by Android (Google) Code Review
20 changed files with 737 additions and 3265 deletions

View File

@@ -150,7 +150,6 @@ import com.android.settings.wifi.ConfigureWifiSettings;
import com.android.settings.wifi.WifiAPITest;
import com.android.settings.wifi.WifiInfo;
import com.android.settings.wifi.WifiSettings;
import com.android.settings.wifi.WifiSettings2;
import com.android.settings.wifi.calling.WifiCallingDisclaimerFragment;
import com.android.settings.wifi.calling.WifiCallingSettings;
import com.android.settings.wifi.p2p.WifiP2pSettings;
@@ -168,7 +167,6 @@ public class SettingsGateway {
AdvancedConnectedDeviceDashboardFragment.class.getName(),
CreateShortcut.class.getName(),
WifiSettings.class.getName(),
WifiSettings2.class.getName(),
ConfigureWifiSettings.class.getName(),
SavedAccessPointsWifiSettings.class.getName(),
SavedAccessPointsWifiSettings2.class.getName(),
@@ -323,7 +321,6 @@ public class SettingsGateway {
SupportDashboardActivity.class.getName(),
// Home page > Network & Internet
Settings.WifiSettingsActivity.class.getName(),
Settings.WifiSettings2Activity.class.getName(),
Settings.DataUsageSummaryActivity.class.getName(),
// Home page > Connected devices
Settings.BluetoothSettingsActivity.class.getName(),

View File

@@ -20,14 +20,12 @@ 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;
@@ -63,20 +61,11 @@ public class WifiPanel implements PanelContent {
public Intent getSeeMoreIntent() {
final String screenTitle =
mContext.getText(R.string.wifi_settings).toString();
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,
final Intent 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;

View File

@@ -35,7 +35,7 @@ import com.android.settings.security.SecuritySettings;
import com.android.settings.security.screenlock.ScreenLockSettings;
import com.android.settings.system.SystemDashboardFragment;
import com.android.settings.wallpaper.WallpaperSuggestionActivity;
import com.android.settings.wifi.WifiSettings2;
import com.android.settings.wifi.WifiSettings;
import java.util.Map;
@@ -55,7 +55,7 @@ public class CustomSiteMapRegistry {
CUSTOM_SITE_MAP.put(
WallpaperSuggestionActivity.class.getName(), DisplaySettings.class.getName());
CUSTOM_SITE_MAP.put(
WifiSettings2.class.getName(), NetworkDashboardFragment.class.getName());
WifiSettings.class.getName(), NetworkDashboardFragment.class.getName());
CUSTOM_SITE_MAP.put(PowerUsageAdvanced.class.getName(), PowerUsageSummary.class.getName());
CUSTOM_SITE_MAP.put(RecentLocationRequestSeeAllFragment.class.getName(),
LocationSettings.class.getName());

View File

@@ -32,7 +32,6 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@@ -46,8 +45,6 @@ import androidx.preference.PreferenceGroup;
import com.android.settings.R;
import com.android.settings.Settings.TetherSettingsActivity;
import com.android.settings.Settings.WifiSettings2Activity;
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -190,15 +187,6 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
Log.d(TAG, "Skipping non-system app: " + info.activityInfo);
continue;
}
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
if (info.activityInfo.name.endsWith(WifiSettingsActivity.class.getSimpleName())) {
continue;
}
} else {
if (info.activityInfo.name.endsWith(WifiSettings2Activity.class.getSimpleName())) {
continue;
}
}
shortcuts.add(info);
}
Collections.sort(shortcuts, SHORTCUT_COMPARATOR);

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