Misc fixes

- align wifi connection dialog edittext to viewStart
- Generate a random password when wifi tether password is null

Change-Id: Ia5ca6098c9ef4641cb4f8b4e2b126da061e62830
Fixes: 67749595
Fixes: 64967301
Test: robotests
This commit is contained in:
Fan Zhang
2017-11-14 10:22:26 -08:00
parent e1ead4d3d0
commit cb4fb095d7
7 changed files with 58 additions and 4 deletions

View File

@@ -218,6 +218,7 @@
<item name="android:paddingStart">4dip</item>
<item name="android:layout_marginStart">4dip</item>
<item name="android:textSize">18sp</item>
<item name="android:textAlignment">viewStart</item>
</style>
<style name="wifi_section">

View File

@@ -28,6 +28,7 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto;
@@ -40,6 +41,7 @@ import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class WifiTetherSettings extends RestrictedDashboardFragment
implements WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
@@ -156,6 +158,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
config.SSID = mSSIDPreferenceController.getSSID();
config.preSharedKey = mPasswordPreferenceController.getPassword();
ensureWifiConfigHasPassword(config);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.apBand = mApBandPreferenceController.getBandIndex();
@@ -176,6 +179,15 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
.updateDisplay();
}
@VisibleForTesting
static void ensureWifiConfigHasPassword(WifiConfiguration config) {
if (TextUtils.isEmpty(config.preSharedKey)) {
String randomUUID = UUID.randomUUID().toString();
//first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
}
}
@VisibleForTesting
class TetherChangeReceiver extends BroadcastReceiver {
@Override

View File

@@ -42,7 +42,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiTetherApBandPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -43,7 +43,7 @@ import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiTetherPasswordPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -59,7 +59,7 @@ import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {
WifiTetherPreferenceControllerTest.ShadowWifiTetherSettings.class,
WifiTetherPreferenceControllerTest.ShadowWifiTetherSwitchBarController.class,

View File

@@ -42,7 +42,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiTetherSSIDPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -0,0 +1,41 @@
/*
* 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.settings.wifi.tether;
import static com.google.common.truth.Truth.assertThat;
import android.net.wifi.WifiConfiguration;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class WifiTetherSettingsTest {
@Test
public void ensureWifiConfigHasPassword_shouldGeneratePassword() {
WifiConfiguration config = new WifiConfiguration();
WifiTetherSettings.ensureWifiConfigHasPassword(config);
assertThat(config.preSharedKey).isNotEmpty();
}
}