[Provider Model] Avoid running changes to WiFi level

- Because getWifiDrawable() has avoided the WIFI_LEVEL_UNREACHABLE(-1)
level design.

- But it might have a chance to changes in the short time after the
level checking above.

- Use the local variable to avoid the risk of changes in WiFi level
operation.

Bug: 210369886
Test: manual test
atest -c InternetAdapterTest \
         InternetDialogControllerTest \
         InternetDialogTest

Change-Id: Id3f27ac7e4cc52fa3eea640eddd34d49863df8d2
This commit is contained in:
Weng Su
2021-12-14 17:09:34 +08:00
parent 1ff5a29afd
commit 0b2bd16cc6

View File

@@ -133,7 +133,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
}
void onBind(@NonNull WifiEntry wifiEntry) {
mWifiIcon.setImageDrawable(getWifiDrawable(wifiEntry));
mWifiIcon.setImageDrawable(
getWifiDrawable(wifiEntry.getLevel(), wifiEntry.shouldShowXLevelIcon()));
setWifiNetworkLayout(wifiEntry.getTitle(),
Html.fromHtml(wifiEntry.getSummary(false), Html.FROM_HTML_MODE_LEGACY));
@@ -170,12 +171,13 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
mWifiSummaryText.setText(summary);
}
Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) {
if (wifiEntry.getLevel() == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
Drawable getWifiDrawable(int level, boolean hasNoInternet) {
// If the Wi-Fi level is equal to WIFI_LEVEL_UNREACHABLE(-1), then a null drawable
// will be returned.
if (level == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
return null;
}
final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(),
wifiEntry.getLevel());
final Drawable drawable = mWifiIconInjector.getIcon(hasNoInternet, level);
if (drawable == null) {
return null;
}