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>
|
||||
|
||||
<!-- 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. -->
|
||||
<plurals name="wifi_saved_access_points_summary">
|
||||
<item quantity="one">1 network</item>
|
||||
|
@@ -14,7 +14,15 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/wifi_saved_access_points_titlebar">
|
||||
<PreferenceScreen
|
||||
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>
|
||||
|
@@ -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.Dialog;
|
||||
import android.content.Context;
|
||||
import android.icu.text.Collator;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
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.WifiDialog;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.AccessPointPreference;
|
||||
import com.android.settingslib.wifi.WifiSavedConfigUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
private static final String TAG = "SavedAccessPoints";
|
||||
@VisibleForTesting
|
||||
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
|
||||
final WifiManager.ActionListener mForgetListener = new WifiManager.ActionListener() {
|
||||
@@ -94,13 +81,14 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
public void onSuccess() {
|
||||
postUpdatePreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int reason) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Toast.makeText(activity,
|
||||
R.string.wifi_failed_save_message,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
R.string.wifi_failed_save_message,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -122,9 +110,18 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.wifi_display_saved_access_points);
|
||||
protected int getPreferenceScreenResId() {
|
||||
return 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());
|
||||
}
|
||||
|
||||
@@ -143,7 +140,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
||||
mAccessPointSavedState =
|
||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +151,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
final List<AccessPoint> accessPoints =
|
||||
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
|
||||
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
|
||||
Collections.sort(accessPoints, SavedNetworkComparator.INSTANCE);
|
||||
cacheRemoveAllPrefs(preferenceScreen);
|
||||
|
||||
final int accessPointsSize = accessPoints.size();
|
||||
@@ -174,7 +171,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
removeCachedPrefs(preferenceScreen);
|
||||
|
||||
if(getPreferenceScreen().getPreferenceCount() < 1) {
|
||||
if (getPreferenceScreen().getPreferenceCount() < 1) {
|
||||
Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -27,6 +29,8 @@ import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.ActionListener;
|
||||
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.wifi.WifiConfigController;
|
||||
import com.android.settings.wifi.WifiDialog;
|
||||
@@ -107,4 +111,11 @@ public class SavedAccessPointsWifiSettingsTest {
|
||||
verify(mockWifiManager)
|
||||
.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