Revert "[Wi-Fi] Apply WifiTrackerLib objects in Wi-Fi Slice"
This reverts commit 7b1aded2a6.
Reason for revert: Settings is crashing for WiFi selection in SetupWizard on wembley
Bug: 161434533
Change-Id: I1d90e9bae1b31862fba674db0d7497e43f987a7f
Test: Locally reverted, reflashed, and was able to select WiFi without Settings crashing.
Exempt-From-Owner-Approval: Revert to clear up P0 while all owners are outside of work hours
This commit is contained in:
@@ -18,8 +18,10 @@ 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;
|
||||
@@ -35,7 +37,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.wifitrackerlib.WifiEntry;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
/**
|
||||
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
|
||||
@@ -50,12 +52,8 @@ 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
|
||||
@@ -86,17 +84,16 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled,
|
||||
WifiSliceItem wifiSliceItem) {
|
||||
final ListBuilder.RowBuilder builder = super.getHeaderRow(isWifiEnabled, wifiSliceItem);
|
||||
builder.setTitleItem(getHeaderIcon(isWifiEnabled, wifiSliceItem), ListBuilder.ICON_IMAGE);
|
||||
protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final ListBuilder.RowBuilder builder = super.getHeaderRow(isWifiEnabled, accessPoint);
|
||||
builder.setTitleItem(getHeaderIcon(isWifiEnabled, accessPoint), ListBuilder.ICON_IMAGE);
|
||||
if (sApRowCollapsed) {
|
||||
builder.setSubtitle(getHeaderSubtitle(wifiSliceItem));
|
||||
builder.setSubtitle(getSubtitle(accessPoint));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
private IconCompat getHeaderIcon(boolean isWifiEnabled, WifiSliceItem wifiSliceItem) {
|
||||
private IconCompat getHeaderIcon(boolean isWifiEnabled, AccessPoint accessPoint) {
|
||||
final Drawable drawable;
|
||||
final int tint;
|
||||
if (!isWifiEnabled) {
|
||||
@@ -106,8 +103,7 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
} else {
|
||||
// get icon of medium signal strength
|
||||
drawable = mContext.getDrawable(com.android.settingslib.Utils.getWifiIconResource(2));
|
||||
if (wifiSliceItem != null
|
||||
&& wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) {
|
||||
if (isNetworkConnected(accessPoint)) {
|
||||
tint = Utils.getColorAccentDefaultColor(mContext);
|
||||
} else {
|
||||
tint = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
|
||||
@@ -117,16 +113,49 @@ public class ContextualWifiSlice extends WifiSlice {
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
}
|
||||
|
||||
private CharSequence getHeaderSubtitle(WifiSliceItem wifiSliceItem) {
|
||||
if (wifiSliceItem == null
|
||||
|| wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_DISCONNECTED) {
|
||||
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) {
|
||||
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 NetworkInfo networkInfo = accessPoint.getNetworkInfo();
|
||||
if (networkInfo == null) {
|
||||
return mContext.getText(R.string.disconnected);
|
||||
}
|
||||
return mContext.getString(R.string.wifi_connected_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());
|
||||
}
|
||||
|
||||
private boolean hasWorkingNetwork() {
|
||||
|
||||
Reference in New Issue
Block a user