Refersh saved Wi-Fi networks

- Refresh existing saved networks with the same key of WifiEntry

- Update Wi-Fi icon when connection status changes

Bug: 290644817
Bug: 291032267
Bug: 293468313
Bug: 294866208
Test: Manual test
make RunSettingsRoboTests ROBOTEST_FILTER=WifiEntryPreferenceTest
make RunSettingsRoboTests ROBOTEST_FILTER=SavedAccessPointsPreferenceController2Test

Change-Id: Ifadfb7c46edf8eda32e4ff5dcb6bb3ff086447c8
This commit is contained in:
Weng Su
2023-08-07 20:50:17 +08:00
parent 857778a856
commit 1962145282
4 changed files with 113 additions and 76 deletions

View File

@@ -19,7 +19,9 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -97,6 +99,9 @@ public class WifiEntryPreferenceTest {
when(mMockWifiEntry.getTitle()).thenReturn(MOCK_TITLE);
when(mMockWifiEntry.getSummary(false /* concise */)).thenReturn(MOCK_SUMMARY);
when(mMockWifiEntry.getLevel()).thenReturn(0);
when(mMockWifiEntry.shouldShowXLevelIcon()).thenReturn(false);
when(mMockWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED);
when(mMockIconInjector.getIcon(false /* showX */, 0)).thenReturn(mMockDrawable0);
when(mMockIconInjector.getIcon(false /* showX */, 1)).thenReturn(mMockDrawable1);
@@ -115,7 +120,7 @@ public class WifiEntryPreferenceTest {
when(mMockIconInjector.getIcon(true /* showX */, 4))
.thenReturn(mMockShowXDrawable4);
mPref = new WifiEntryPreference(mContext, mMockWifiEntry, mMockIconInjector);
mPref = spy(new WifiEntryPreference(mContext, mMockWifiEntry, mMockIconInjector));
}
@Test
@@ -137,6 +142,27 @@ public class WifiEntryPreferenceTest {
assertThat(pref.getIcon()).isEqualTo(mMockDrawable0);
}
@Test
public void setWifiEntry_connectedStateChanged_setIconAndSummary() {
when(mMockWifiEntry.getLevel()).thenReturn(4);
when(mMockWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
mPref.setWifiEntry(mMockWifiEntry);
verify(mPref).setIcon(any());
verify(mPref).setSummary(anyString());
// Only the connection state changes.
when(mMockWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED);
reset(mPref);
mPref.setWifiEntry(mMockWifiEntry);
// The icon and summary should be set in case.
verify(mPref).setIcon(any());
verify(mPref).setSummary(anyString());
}
@Test
public void titleChanged_refresh_shouldUpdateTitle() {
final String updatedTitle = "updated title";
@@ -254,6 +280,8 @@ public class WifiEntryPreferenceTest {
@Test
public void updateIcon_shouldSetTintListForDrawable() {
reset(mMockDrawable4);
mPref.updateIcon(false /* showX */, 4 /* level */);
verify(mMockDrawable4).setTintList(any());