[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:
135
src/com/android/settings/wifi/slice/WifiSliceItem.java
Normal file
135
src/com/android/settings/wifi/slice/WifiSliceItem.java
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.slice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
/**
|
||||
* The data set which is needed by a Wi-Fi Slice, it collects necessary data from {@link WifiEntry}
|
||||
* and provides similar getter methods for corresponding data.
|
||||
*/
|
||||
public class WifiSliceItem {
|
||||
|
||||
private final Context mContext;
|
||||
private final String mKey;
|
||||
private final String mTitle;
|
||||
private final int mSecurity;
|
||||
private final int mConnectedState;
|
||||
private final int mLevel;
|
||||
private final boolean mShouldEditBeforeConnect;
|
||||
private final String mSummary;
|
||||
|
||||
// These values must be kept within [WifiEntry.WIFI_LEVEL_MIN, WifiEntry.WIFI_LEVEL_MAX]
|
||||
private static final int[] WIFI_CONNECTION_STRENGTH = {
|
||||
R.string.accessibility_no_wifi,
|
||||
R.string.accessibility_wifi_one_bar,
|
||||
R.string.accessibility_wifi_two_bars,
|
||||
R.string.accessibility_wifi_three_bars,
|
||||
R.string.accessibility_wifi_signal_full
|
||||
};
|
||||
|
||||
public WifiSliceItem(Context context, WifiEntry wifiEntry) {
|
||||
mContext = context;
|
||||
mKey = wifiEntry.getKey();
|
||||
mTitle = wifiEntry.getTitle();
|
||||
mSecurity = wifiEntry.getSecurity();
|
||||
mConnectedState = wifiEntry.getConnectedState();
|
||||
mLevel = wifiEntry.getLevel();
|
||||
mShouldEditBeforeConnect = wifiEntry.shouldEditBeforeConnect();
|
||||
mSummary = wifiEntry.getSummary(false /* concise */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof WifiSliceItem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final WifiSliceItem otherItem = (WifiSliceItem) other;
|
||||
if (!TextUtils.equals(getKey(), otherItem.getKey())) {
|
||||
return false;
|
||||
}
|
||||
if (getConnectedState() != otherItem.getConnectedState()) {
|
||||
return false;
|
||||
}
|
||||
if (getLevel() != otherItem.getLevel()) {
|
||||
return false;
|
||||
}
|
||||
if (!TextUtils.equals(getSummary(), otherItem.getSummary())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return mKey;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public int getSecurity() {
|
||||
return mSecurity;
|
||||
}
|
||||
|
||||
public int getConnectedState() {
|
||||
return mConnectedState;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return mLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* In Wi-Fi picker, when users click a saved network, it will connect to the Wi-Fi network.
|
||||
* However, for some special cases, Wi-Fi picker should show Wi-Fi editor UI for users to edit
|
||||
* security or password before connecting. Or users will always get connection fail results.
|
||||
*/
|
||||
public boolean shouldEditBeforeConnect() {
|
||||
return mShouldEditBeforeConnect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 'NOT' concise summary, this is different from WifiEntry#getSummary().
|
||||
*/
|
||||
public String getSummary() {
|
||||
return mSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method has similar code as WifiEntryPreference#buildContentDescription().
|
||||
* TODO(b/154191825): Adds WifiEntry#getContentDescription() to replace the duplicate code.
|
||||
*/
|
||||
public CharSequence getContentDescription() {
|
||||
CharSequence contentDescription = mTitle;
|
||||
if (!TextUtils.isEmpty(mSummary)) {
|
||||
contentDescription = TextUtils.concat(contentDescription, ",", mSummary);
|
||||
}
|
||||
if (mLevel >= 0 && mLevel < WIFI_CONNECTION_STRENGTH.length) {
|
||||
contentDescription = TextUtils.concat(contentDescription, ",",
|
||||
mContext.getString(WIFI_CONNECTION_STRENGTH[mLevel]));
|
||||
}
|
||||
return TextUtils.concat(contentDescription, ",", mSecurity == WifiEntry.SECURITY_NONE
|
||||
? mContext.getString(R.string.accessibility_wifi_security_type_none)
|
||||
: mContext.getString(R.string.accessibility_wifi_security_type_secured));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user