[Wi-Fi] Apply WifiTrackerLib objects in Wi-Fi Slice

This change uses WifiTrackerLib's WifiPickerTracker & WifiEntry
to replace SettingLib's WifiTracker & AccessPoint.

This change includes

1. WifiScanWorker has the callbacks similar to a lifecycle component
   but it's not a lifecycle component. Let WifiScanWorker implements
   LifecycleOwner and provides #getLifecycle() for WifiPickerTracker.

2. Remove captive portal related code because WifiEntry#connect will
   handle captive portal login if it's necessary.

3. Create WifiSliceItem to wrap WifiEntry because WifiEntry is an
   abstract object and it does not provide copy constructor.
   Without copy construcor, Wi-Fi Slice may show unexpected information
   when a WifiEntry is updated.

4. Use WifiTrackerLib's NetworkDetailsTracker & WifiEntry in
   WifiDialogActivity because it gets a WifiEntry key from Wi-Fi Slice.
   NetworkDetailsTracker can get the WifiEntry of th key.

Bug: 155613549
Bug: 152571756
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi.slice
      make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.wifi
Change-Id: I0718f4647cea007a9b701922f3121a388dd43918
This commit is contained in:
Arc Wang
2020-05-28 21:35:58 +08:00
parent ff5fcdc965
commit 7b1aded2a6
17 changed files with 587 additions and 928 deletions

View File

@@ -18,10 +18,8 @@ package com.android.settings.wifi.slice;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkInfo.State;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
@@ -37,7 +35,7 @@ import com.android.settings.Utils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.CustomSliceable;
import com.android.settingslib.wifi.AccessPoint;
import com.android.wifitrackerlib.WifiEntry;
/**
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
@@ -52,8 +50,12 @@ public class ContextualWifiSlice extends WifiSlice {
@VisibleForTesting
static boolean sApRowCollapsed;
private final ConnectivityManager mConnectivityManager;
public ContextualWifiSlice(Context context) {
super(context);
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
}
@Override
@@ -84,16 +86,17 @@ public class ContextualWifiSlice extends WifiSlice {
}
@Override
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled, AccessPoint accessPoint) {
final ListBuilder.RowBuilder builder = super.getHeaderRow(isWifiEnabled, accessPoint);
builder.setTitleItem(getHeaderIcon(isWifiEnabled, accessPoint), ListBuilder.ICON_IMAGE);
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled,
WifiSliceItem wifiSliceItem) {
final ListBuilder.RowBuilder builder = super.getHeaderRow(isWifiEnabled, wifiSliceItem);
builder.setTitleItem(getHeaderIcon(isWifiEnabled, wifiSliceItem), ListBuilder.ICON_IMAGE);
if (sApRowCollapsed) {
builder.setSubtitle(getSubtitle(accessPoint));
builder.setSubtitle(getHeaderSubtitle(wifiSliceItem));
}
return builder;
}
private IconCompat getHeaderIcon(boolean isWifiEnabled, AccessPoint accessPoint) {
private IconCompat getHeaderIcon(boolean isWifiEnabled, WifiSliceItem wifiSliceItem) {
final Drawable drawable;
final int tint;
if (!isWifiEnabled) {
@@ -103,7 +106,8 @@ public class ContextualWifiSlice extends WifiSlice {
} else {
// get icon of medium signal strength
drawable = mContext.getDrawable(com.android.settingslib.Utils.getWifiIconResource(2));
if (isNetworkConnected(accessPoint)) {
if (wifiSliceItem != null
&& wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) {
tint = Utils.getColorAccentDefaultColor(mContext);
} else {
tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
@@ -113,49 +117,16 @@ public class ContextualWifiSlice extends WifiSlice {
return Utils.createIconWithDrawable(drawable);
}
private boolean isNetworkConnected(AccessPoint accessPoint) {
if (accessPoint == null) {
return false;
}
final NetworkInfo networkInfo = accessPoint.getNetworkInfo();
if (networkInfo == null) {
return false;
}
return networkInfo.getState() == State.CONNECTED;
}
private CharSequence getSubtitle(AccessPoint accessPoint) {
if (isCaptivePortal()) {
final int id = mContext.getResources()
.getIdentifier("network_available_sign_in", "string", "android");
return mContext.getText(id);
}
if (accessPoint == null) {
private CharSequence getHeaderSubtitle(WifiSliceItem wifiSliceItem) {
if (wifiSliceItem == null
|| wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_DISCONNECTED) {
return mContext.getText(R.string.disconnected);
}
final NetworkInfo networkInfo = accessPoint.getNetworkInfo();
if (networkInfo == null) {
return mContext.getText(R.string.disconnected);
if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTING) {
return mContext.getString(R.string.wifi_connecting_to_message,
wifiSliceItem.getTitle());
}
final State state = networkInfo.getState();
DetailedState detailedState;
if (state == State.CONNECTING) {
detailedState = DetailedState.CONNECTING;
} else if (state == State.CONNECTED) {
detailedState = DetailedState.CONNECTED;
} else {
detailedState = networkInfo.getDetailedState();
}
final String[] formats = mContext.getResources().getStringArray(
R.array.wifi_status_with_ssid);
final int index = detailedState.ordinal();
return String.format(formats[index], accessPoint.getTitle());
return mContext.getString(R.string.wifi_connected_to_message, wifiSliceItem.getTitle());
}
private boolean hasWorkingNetwork() {