Convert SavedAccessPoints to DashboardFragment (step 1)
Change-Id: I5d8fa8497e04c9314dead9af7534df4507ffd591 Bug: 64806699 Test: robotest
This commit is contained in:
@@ -2112,8 +2112,6 @@
|
|||||||
<string name="wifi_forget_dialog_message">All passwords for this network will be deleted</string>
|
<string name="wifi_forget_dialog_message">All passwords for this network will be deleted</string>
|
||||||
|
|
||||||
<!-- Wi-Fi Advanced Settings --> <skip />
|
<!-- Wi-Fi Advanced Settings --> <skip />
|
||||||
<!-- Wi-Fi settings screen, Saved networks, settings section. This is a header shown above Saved networks wifi settings. [CHAR LIMIT=30] -->
|
|
||||||
<string name="wifi_saved_access_points_titlebar">Saved networks</string>
|
|
||||||
<!-- Wi-Fi settings screen, Saved networks summary. This shows below the "Saved networks" item and indicates the number of networks a user has saved. -->
|
<!-- Wi-Fi settings screen, Saved networks summary. This shows below the "Saved networks" item and indicates the number of networks a user has saved. -->
|
||||||
<plurals name="wifi_saved_access_points_summary">
|
<plurals name="wifi_saved_access_points_summary">
|
||||||
<item quantity="one">1 network</item>
|
<item quantity="one">1 network</item>
|
||||||
|
@@ -14,7 +14,15 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen
|
||||||
android:title="@string/wifi_saved_access_points_titlebar">
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:key="saved_access_points"
|
||||||
|
android:title="@string/wifi_saved_access_points_label">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="saved_access_points_category"
|
||||||
|
android:layout="@layout/preference_category_no_label"
|
||||||
|
settings:controller="com.android.settings.wifi.savedaccesspoints.SavedAccessPointsPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.savedaccesspoints;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller that manages a PrferenceGroup, which contains a list of saved access points.
|
||||||
|
*/
|
||||||
|
public class SavedAccessPointsPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
public SavedAccessPointsPreferenceController(Context context,
|
||||||
|
String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
@@ -20,51 +20,38 @@ import android.annotation.Nullable;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.icu.text.Collator;
|
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.wifi.WifiConfigUiBase;
|
import com.android.settings.wifi.WifiConfigUiBase;
|
||||||
import com.android.settings.wifi.WifiDialog;
|
import com.android.settings.wifi.WifiDialog;
|
||||||
import com.android.settings.wifi.WifiSettings;
|
import com.android.settings.wifi.WifiSettings;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
import com.android.settingslib.wifi.AccessPointPreference;
|
import com.android.settingslib.wifi.AccessPointPreference;
|
||||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI to manage saved networks/access points.
|
* UI to manage saved networks/access points.
|
||||||
* TODO(b/64806699): convert to {@link DashboardFragment} with {@link PreferenceController}s
|
|
||||||
*/
|
*/
|
||||||
public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
public class SavedAccessPointsWifiSettings extends DashboardFragment
|
||||||
implements WifiDialog.WifiDialogListener {
|
implements WifiDialog.WifiDialogListener {
|
||||||
private static final String TAG = "SavedAccessPoints";
|
private static final String TAG = "SavedAccessPoints";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int MSG_UPDATE_PREFERENCES = 1;
|
static final int MSG_UPDATE_PREFERENCES = 1;
|
||||||
private static final Comparator<AccessPoint> SAVED_NETWORK_COMPARATOR =
|
|
||||||
new Comparator<AccessPoint>() {
|
|
||||||
final Collator mCollator = Collator.getInstance();
|
|
||||||
@Override
|
|
||||||
public int compare(AccessPoint ap1, AccessPoint ap2) {
|
|
||||||
return mCollator.compare(
|
|
||||||
nullToEmpty(ap1.getConfigName()), nullToEmpty(ap2.getConfigName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nullToEmpty(String string) {
|
|
||||||
return (string == null) ? "" : string;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final WifiManager.ActionListener mForgetListener = new WifiManager.ActionListener() {
|
final WifiManager.ActionListener mForgetListener = new WifiManager.ActionListener() {
|
||||||
@@ -94,6 +81,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
postUpdatePreference();
|
postUpdatePreference();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(int reason) {
|
public void onFailure(int reason) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
@@ -122,9 +110,18 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
protected int getPreferenceScreenResId() {
|
||||||
super.onCreate(savedInstanceState);
|
return R.xml.wifi_display_saved_access_points;
|
||||||
addPreferencesFromResource(R.xml.wifi_display_saved_access_points);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +151,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
final List<AccessPoint> accessPoints =
|
final List<AccessPoint> accessPoints =
|
||||||
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
|
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
|
||||||
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
|
Collections.sort(accessPoints, SavedNetworkComparator.INSTANCE);
|
||||||
cacheRemoveAllPrefs(preferenceScreen);
|
cacheRemoveAllPrefs(preferenceScreen);
|
||||||
|
|
||||||
final int accessPointsSize = accessPoints.size();
|
final int accessPointsSize = accessPoints.size();
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.savedaccesspoints;
|
||||||
|
|
||||||
|
import android.icu.text.Collator;
|
||||||
|
|
||||||
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public final class SavedNetworkComparator {
|
||||||
|
public static final Comparator<AccessPoint> INSTANCE =
|
||||||
|
new Comparator<AccessPoint>() {
|
||||||
|
final Collator mCollator = Collator.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(AccessPoint ap1, AccessPoint ap2) {
|
||||||
|
return mCollator.compare(
|
||||||
|
nullToEmpty(ap1.getConfigName()), nullToEmpty(ap2.getConfigName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String nullToEmpty(String string) {
|
||||||
|
return (string == null) ? "" : string;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.savedaccesspoints;
|
package com.android.settings.wifi.savedaccesspoints;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -27,6 +29,8 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.net.wifi.WifiManager.ActionListener;
|
import android.net.wifi.WifiManager.ActionListener;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wifi.WifiConfigController;
|
import com.android.settings.wifi.WifiConfigController;
|
||||||
import com.android.settings.wifi.WifiDialog;
|
import com.android.settings.wifi.WifiDialog;
|
||||||
@@ -107,4 +111,11 @@ public class SavedAccessPointsWifiSettingsTest {
|
|||||||
verify(mockWifiManager)
|
verify(mockWifiManager)
|
||||||
.forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class));
|
.forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyConstants() {
|
||||||
|
assertThat(mSettings.getMetricsCategory()).isEqualTo(MetricsEvent.WIFI_SAVED_ACCESS_POINTS);
|
||||||
|
assertThat(mSettings.getPreferenceScreenResId())
|
||||||
|
.isEqualTo(R.xml.wifi_display_saved_access_points);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user