Refer to the last Hotspot password when generating the password

- Query the last Hotspot password when security type is SECURITY_TYPE_OPEN and it will be used when the user changes to another security type

- If the last hotspot password is an empty string, then generate random password

Bug: 201789473
Test: manual test
atest -c WifiHotspotRepositoryTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherPasswordPreferenceControllerTest

Change-Id: Id3a846099238433e7b6c8b934fa26a74df0dcb61
This commit is contained in:
Weng Su
2023-02-22 10:32:11 +08:00
parent 1acdb1452d
commit d7bbd4505c
10 changed files with 303 additions and 13 deletions

View File

@@ -35,7 +35,9 @@ import android.net.wifi.WifiManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.repository.WifiHotspotRepository;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before;
@@ -65,6 +67,8 @@ public class WifiTetherPasswordPreferenceControllerTest {
private PreferenceScreen mScreen;
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@Mock
private WifiHotspotRepository mWifiHotspotRepository;
private WifiTetherPasswordPreferenceController mController;
private ValidatedEditTextPreference mPreference;
@@ -73,6 +77,10 @@ public class WifiTetherPasswordPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.getWifiFeatureProvider().getWifiHotspotRepository())
.thenReturn(mWifiHotspotRepository);
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
mConfig = new SoftApConfiguration.Builder().setSsid("test_1234")
.setPassphrase(INITIAL_PASSWORD, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)
@@ -91,6 +99,11 @@ public class WifiTetherPasswordPreferenceControllerTest {
mMetricsFeatureProvider);
}
@Test
public void constructor_shouldQueryLastPasswordIfNeeded() {
verify(mWifiHotspotRepository).queryLastPasswordIfNeeded();
}
@Test
public void displayPreference_shouldStylePreference() {
mController.displayPreference(mScreen);