Move generatePreferenceKey to AccessPointPreference.

This allows it to be reused in the SavedAccessPointsWifiSettings.

Bug: b/62374459
Test: make -j40 RunSettingsLibRoboTests
Change-Id: Id137f56ceafe461d217c0eee6b571ccfa4eaff1f
This commit is contained in:
Sundeep Ghuman
2017-06-26 17:13:00 -07:00
parent ce6b0b2539
commit 7c32aa3039
3 changed files with 81 additions and 0 deletions

View File

@@ -70,6 +70,19 @@ public class AccessPointPreference extends Preference {
R.string.accessibility_wifi_signal_full
};
public static String generatePreferenceKey(AccessPoint accessPoint) {
StringBuilder builder = new StringBuilder();
if (TextUtils.isEmpty(accessPoint.getBssid())) {
builder.append(accessPoint.getSsidStr());
} else {
builder.append(accessPoint.getBssid());
}
builder.append(',').append(accessPoint.getSecurity());
return builder.toString();
}
// Used for dummy pref.
public AccessPointPreference(Context context, AttributeSet attrs) {
super(context, attrs);

View File

@@ -36,6 +36,7 @@ public class TestAccessPointBuilder {
private static final int MAX_RSSI = -55;
// set some sensible defaults
private String mBssid = null;
private int mRssi = AccessPoint.UNREACHABLE_RSSI;
private int mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
private String ssid = "TestSsid";
@@ -57,6 +58,7 @@ public class TestAccessPointBuilder {
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.networkId = mNetworkId;
wifiConfig.BSSID = mBssid;
bundle.putString(AccessPoint.KEY_SSID, ssid);
bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConfig);
@@ -179,4 +181,9 @@ public class TestAccessPointBuilder {
mNetworkId = networkId;
return this;
}
public TestAccessPointBuilder setBssid(String bssid) {
mBssid = bssid;
return this;
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2017 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.settingslib.wifi;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import com.android.settingslib.SettingLibRobolectricTestRunner;
import com.android.settingslib.TestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingLibRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccessPointPreferenceTest {
private Context mContext = RuntimeEnvironment.application;
@Test
public void generatePreferenceKey_shouldReturnSsidPlusSecurity() {
String ssid = "ssid";
int security = AccessPoint.SECURITY_WEP;
String expectedKey = ssid + ',' + security;
TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext);
builder.setSsid(ssid).setSecurity(security);
assertThat(AccessPointPreference.generatePreferenceKey(builder.build()))
.isEqualTo(expectedKey);
}
@Test
public void generatePreferenceKey_shouldReturnBssidPlusSecurity() {
String bssid = "bssid";
int security = AccessPoint.SECURITY_WEP;
String expectedKey = bssid + ',' + security;
TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext);
builder.setBssid(bssid).setSecurity(security);
assertThat(AccessPointPreference.generatePreferenceKey(builder.build()))
.isEqualTo(expectedKey);
}
}