Merge "Show "Not available" summary when hotspot speed is unavailable" into udc-d1-dev
diff --git a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
index 6764214..af8eb47 100644
--- a/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
+++ b/src/com/android/settings/wifi/repository/WifiHotspotRepository.java
@@ -623,9 +623,11 @@
 
     @VisibleForTesting
     class SoftApCallback implements WifiManager.SoftApCallback {
+        private static final String TAG = "SoftApCallback";
+
         @Override
         public void onStateChanged(int state, int failureReason) {
-            log("onStateChanged(), state:" + state + ", failureReason:" + failureReason);
+            Log.d(TAG, "onStateChanged(), state:" + state + ", failureReason:" + failureReason);
             mWifiApState = state;
             if (!mIsRestarting) {
                 return;
diff --git a/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java b/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java
index f5066bd..a5e12d8 100644
--- a/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettings.java
@@ -108,15 +108,17 @@
             if (radioButton == null) {
                 continue;
             }
-            if (radioButton.isChecked() != speedInfo.mIsChecked) {
-                radioButton.setChecked(speedInfo.mIsChecked);
+            if (!speedInfo.mIsVisible) {
+                radioButton.setVisible(false);
+                continue;
             }
-            if (radioButton.isEnabled() != speedInfo.mIsEnabled) {
-                radioButton.setEnabled(speedInfo.mIsEnabled);
+            radioButton.setEnabled(speedInfo.mIsEnabled);
+            radioButton.setChecked(speedInfo.mIsChecked);
+            if (speedInfo.mSummary != null) {
+                radioButton.setSummary(speedInfo.mSummary);
             }
-            if (radioButton.isVisible() != speedInfo.mIsVisible) {
-                radioButton.setVisible(speedInfo.mIsVisible);
-            }
+            // setVisible at the end to avoid UI flickering
+            radioButton.setVisible(true);
         }
     }
 
diff --git a/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java b/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java
index f04669a..e7eb3a6 100644
--- a/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java
+++ b/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModel.java
@@ -22,12 +22,15 @@
 import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
 
 import android.app.Application;
+import android.util.Log;
 
+import androidx.annotation.VisibleForTesting;
 import androidx.lifecycle.AndroidViewModel;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.Observer;
 
+import com.android.settings.R;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.wifi.repository.WifiHotspotRepository;
 
@@ -41,6 +44,12 @@
  */
 public class WifiHotspotSpeedViewModel extends AndroidViewModel {
     private static final String TAG = "WifiHotspotSpeedViewModel";
+    @VisibleForTesting
+    static final int RES_SPEED_5G_SUMMARY = R.string.wifi_hotspot_speed_5g_summary;
+    @VisibleForTesting
+    static final int RES_SPEED_6G_SUMMARY = R.string.wifi_hotspot_speed_6g_summary;
+    @VisibleForTesting
+    static final int RES_SUMMARY_UNAVAILABLE = R.string.wifi_hotspot_speed_summary_unavailable;
 
     protected final WifiHotspotRepository mWifiHotspotRepository;
     protected Map<Integer, SpeedInfo> mSpeedInfoMap = new HashMap<>();
@@ -75,14 +84,18 @@
     }
 
     protected void on6gAvailableChanged(Boolean available) {
-        log("on6gAvailableChanged(), available:" + available);
+        Log.d(TAG, "on6gAvailableChanged(), available:" + available);
         mSpeedInfo6g.mIsEnabled = available;
+        mSpeedInfo6g.mSummary = getApplication()
+                .getString(available ? RES_SPEED_6G_SUMMARY : RES_SUMMARY_UNAVAILABLE);
         updateSpeedInfoMapData();
     }
 
     protected void on5gAvailableChanged(Boolean available) {
-        log("on5gAvailableChanged(), available:" + available);
+        Log.d(TAG, "on5gAvailableChanged(), available:" + available);
         mSpeedInfo5g.mIsEnabled = available;
+        mSpeedInfo5g.mSummary = getApplication()
+                .getString(available ? RES_SPEED_5G_SUMMARY : RES_SUMMARY_UNAVAILABLE);
 
         boolean showDualBand = mWifiHotspotRepository.isDualBand() && available;
         log("on5gAvailableChanged(), showDualBand:" + showDualBand);
@@ -144,6 +157,7 @@
         Boolean mIsChecked;
         boolean mIsEnabled;
         boolean mIsVisible;
+        String mSummary;
 
         public SpeedInfo(boolean isChecked, boolean isEnabled, boolean isVisible) {
             this.mIsChecked = isChecked;
@@ -157,6 +171,7 @@
                     .append("isChecked:").append(mIsChecked)
                     .append(",isEnabled:").append(mIsEnabled)
                     .append(",isVisible:").append(mIsVisible)
+                    .append(",mSummary:").append(mSummary)
                     .append('}').toString();
         }
     }
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java
index 969f992..31f4c09 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiHotspotSpeedSettingsTest.java
@@ -25,8 +25,10 @@
 import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_5GHZ;
 import static com.android.settings.wifi.tether.WifiHotspotSpeedSettings.KEY_SPEED_6GHZ;
 
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.anyBoolean;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -89,98 +91,156 @@
 
     @Test
     public void onSpeedInfoMapDataChanged_checkedSpeed2g_checkedToRadioButton2g() {
-        mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+        mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
         updateSpeedInfoMap();
-        mockRadioButton(true, false, true);
+        mockRadioButton(false, false, false);
         mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(false, true, false);
+        verifyRadioButton(true, true, true);
     }
 
     @Test
     public void onSpeedInfoMapDataChanged_uncheckedSpeed2g_uncheckedToRadioButton2g() {
-        mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+        mSpeedInfo2g = new WifiHotspotSpeedViewModel.SpeedInfo(false, false, true);
         updateSpeedInfoMap();
-        mockRadioButton(false, true, false);
+        mockRadioButton(true, true, true);
         mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(true, false, true);
+        verifyRadioButton(false, false, true);
     }
 
     @Test
     public void onSpeedInfoMapDataChanged_checkedSpeed5g_checkedToRadioButton5g() {
-        mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+        mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
         updateSpeedInfoMap();
-        mockRadioButton(true, false, true);
+        mockRadioButton(false, false, false);
         mSettings.mSpeedPreferenceMap.put(SPEED_5GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(false, true, false);
+        verifyRadioButton(true, true, true);
     }
 
     @Test
     public void onSpeedInfoMapDataChanged_uncheckedSpeed5g_uncheckedToRadioButton5g() {
-        mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+        mSpeedInfo5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, false, true);
         updateSpeedInfoMap();
-        mockRadioButton(false, true, false);
+        mockRadioButton(true, true, true);
         mSettings.mSpeedPreferenceMap.put(SPEED_5GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(true, false, true);
+        verifyRadioButton(false, false, true);
     }
 
     @Test
     public void onSpeedInfoMapDataChanged_checkedSpeed2g5g_checkedToRadioButton2g5g() {
-        mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+        mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
         updateSpeedInfoMap();
-        mockRadioButton(true, false, true);
+        mockRadioButton(false, false, false);
         mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ_5GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(false, true, false);
+        verifyRadioButton(true, true, true);
     }
 
     @Test
-    public void onSpeedInfoMapDataChanged_uncheckedSpeed25g_uncheckedToRadioButton25g() {
-        mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+    public void onSpeedInfoMapDataChanged_uncheckedSpeed2g5g_uncheckedToRadioButton2g5g() {
+        mSpeedInfo2g5g = new WifiHotspotSpeedViewModel.SpeedInfo(false, false, true);
         updateSpeedInfoMap();
-        mockRadioButton(false, true, false);
+        mockRadioButton(true, true, true);
         mSettings.mSpeedPreferenceMap.put(SPEED_2GHZ_5GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(true, false, true);
+        verifyRadioButton(false, false, true);
     }
 
     @Test
     public void onSpeedInfoMapDataChanged_checkedSpeed6g_checkedToRadioButton6g() {
-        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(false, true, false);
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
         updateSpeedInfoMap();
+        mockRadioButton(false, false, false);
+        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+        verifyRadioButton(true, true, true);
+    }
+
+    @Test
+    public void onSpeedInfoMapDataChanged_uncheckedSpeed6g_uncheckedToRadioButton6g() {
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(false, false, true);
+        updateSpeedInfoMap();
+        mockRadioButton(true, true, true);
+        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+        verifyRadioButton(false, false, true);
+    }
+
+    @Test
+    public void onSpeedInfoMapDataChanged_setVisibleFalse_setVisibleOnly() {
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, false);
+        mSpeedInfo6g.mSummary = "summary";
+        mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
+        mockRadioButton(true, true, true);
+        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+        verify(mRadioButton).setVisible(false);
+        verify(mRadioButton, never()).setChecked(anyBoolean());
+        verify(mRadioButton, never()).setEnabled(anyBoolean());
+        verify(mRadioButton, never()).setSummary(anyString());
+    }
+
+    @Test
+    public void onSpeedInfoMapDataChanged_setVisibleTrue_setAllProperties() {
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
+        mSpeedInfo6g.mSummary = "summary";
+        mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
+        mockRadioButton(true, true, true);
+        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+        verify(mRadioButton).setVisible(true);
+        verify(mRadioButton).setChecked(anyBoolean());
+        verify(mRadioButton).setEnabled(anyBoolean());
+        verify(mRadioButton).setSummary(anyString());
+    }
+
+    @Test
+    public void onSpeedInfoMapDataChanged_summaryIsNull_doNotSetSummary() {
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, true, true);
+        mSpeedInfo6g.mSummary = null;
+        mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
+        mockRadioButton(true, true, true);
+        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
+
+        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
+
+        verify(mRadioButton, never()).setSummary(anyString());
+    }
+
+    @Test
+    public void onSpeedInfoMapDataChanged_summaryNotNull_setSummary() {
+        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
+        mSpeedInfo6g.mSummary = "summary";
+        mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
         mockRadioButton(true, false, true);
         mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
 
         mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
 
-        verifyRadioButton(false, true, false);
-    }
-
-    @Test
-    public void onSpeedInfoMapDataChanged_uncheckedSpeed6g_uncheckedToRadioButton6g() {
-        mSpeedInfo6g = new WifiHotspotSpeedViewModel.SpeedInfo(true, false, true);
-        updateSpeedInfoMap();
-        mockRadioButton(false, true, false);
-        mSettings.mSpeedPreferenceMap.put(SPEED_6GHZ, mRadioButton);
-
-        mSettings.onSpeedInfoMapDataChanged(mSpeedInfoMap);
-
-        verifyRadioButton(true, false, true);
+        verify(mRadioButton).setSummary(mSpeedInfo6g.mSummary);
     }
 
     @Test
diff --git a/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java
index 3a1a927..f52478e 100644
--- a/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java
+++ b/tests/unit/src/com/android/settings/wifi/tether/WifiHotspotSpeedViewModelTest.java
@@ -20,6 +20,9 @@
 import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
 import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
 import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedViewModel.RES_SPEED_5G_SUMMARY;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedViewModel.RES_SPEED_6G_SUMMARY;
+import static com.android.settings.wifi.tether.WifiHotspotSpeedViewModel.RES_SUMMARY_UNAVAILABLE;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -128,7 +131,9 @@
         mViewModel.on6gAvailableChanged(true);
 
         verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
-        assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsEnabled).isTrue();
+        WifiHotspotSpeedViewModel.SpeedInfo speedInfo = mViewModel.mSpeedInfoMap.get(SPEED_6GHZ);
+        assertThat(speedInfo.mIsEnabled).isTrue();
+        assertThat(speedInfo.mSummary).isEqualTo(mContext.getString(RES_SPEED_6G_SUMMARY));
     }
 
     @Test
@@ -139,7 +144,9 @@
         mViewModel.on6gAvailableChanged(false);
 
         verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
-        assertThat(mViewModel.mSpeedInfoMap.get(SPEED_6GHZ).mIsEnabled).isFalse();
+        WifiHotspotSpeedViewModel.SpeedInfo speedInfo = mViewModel.mSpeedInfoMap.get(SPEED_6GHZ);
+        assertThat(speedInfo.mIsEnabled).isFalse();
+        assertThat(speedInfo.mSummary).isEqualTo(mContext.getString(RES_SUMMARY_UNAVAILABLE));
     }
 
     @Test
@@ -150,7 +157,9 @@
         mViewModel.on5gAvailableChanged(true);
 
         verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
-        assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsEnabled).isTrue();
+        WifiHotspotSpeedViewModel.SpeedInfo speedInfo = mViewModel.mSpeedInfoMap.get(SPEED_5GHZ);
+        assertThat(speedInfo.mIsEnabled).isTrue();
+        assertThat(speedInfo.mSummary).isEqualTo(mContext.getString(RES_SPEED_5G_SUMMARY));
     }
 
     @Test
@@ -161,7 +170,9 @@
         mViewModel.on5gAvailableChanged(false);
 
         verify(mSpeedInfoMapData).setValue(mViewModel.mSpeedInfoMap);
-        assertThat(mViewModel.mSpeedInfoMap.get(SPEED_5GHZ).mIsEnabled).isFalse();
+        WifiHotspotSpeedViewModel.SpeedInfo speedInfo = mViewModel.mSpeedInfoMap.get(SPEED_5GHZ);
+        assertThat(speedInfo.mIsEnabled).isFalse();
+        assertThat(speedInfo.mSummary).isEqualTo(mContext.getString(RES_SUMMARY_UNAVAILABLE));
     }
 
     @Test