Don't allow a zero-length device name to work.

Technically, if a device has a zero-length device name, the bug will
resurface. The EditText validator doesn't trigger on opening -- only
when the text is edited. A zero-length device name is flagged as being
invalid, but that fails if the text box starts empty.

By pre-filling it with the previous device name, we can ensure that, as
long as a zero-length device name is never set, it can never be set.

Change-Id: I0d28aaae09f99b7d697b753835ba39c0c06644a1
Fixes: 73127912
Test: Robotest
(cherry picked from commit b216550944)
This commit is contained in:
Daniel Nishi
2018-03-12 16:44:27 -07:00
parent 8b63a03278
commit 103b4d4619
2 changed files with 11 additions and 1 deletions

View File

@@ -54,7 +54,9 @@ public class DeviceNamePreferenceController extends BasePreferenceController
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ValidatedEditTextPreference) screen.findPreference(PREF_KEY);
mPreference.setSummary(getSummary());
final CharSequence deviceName = getSummary();
mPreference.setSummary(deviceName);
mPreference.setText(deviceName.toString());
mPreference.setValidator(this);
}

View File

@@ -123,4 +123,12 @@ public class DeviceNamePreferenceControllerTest {
verify(mWifiManager).setWifiApConfiguration(captor.capture());
assertThat(captor.getValue().SSID).isEqualTo(TESTING_STRING);
}
@Test
public void displayPreference_defaultDeviceNameIsModelNameOnPreference() {
mController.displayPreference(mScreen);
assertThat(mPreference.getText()).isEqualTo(Build.MODEL);
}
}