Show Hotspot informations in Network details settings

- Show Hotspot device type in hearder icon

- Show Hotspot device details informations.
  - Internet source (network type)
  - Battery

Bug: 297346368
Test: manual test
atest -c WifiNetworkDetailsFragmentTest \
         WifiDetailPreferenceController2Test
atest -c SharedConnectivityRepositoryTest \
         WifiNetworkDetailsViewModelTest

Change-Id: I4bd090e00681911c8fac469289fd818237b8c518
This commit is contained in:
Weng Su
2023-08-29 01:48:54 +08:00
parent 84c4ec936a
commit 25e20caf00
10 changed files with 721 additions and 45 deletions

View File

@@ -15,8 +15,13 @@
*/
package com.android.settings.wifi.details2;
import static android.net.wifi.sharedconnectivity.app.NetworkProviderInfo.DEVICE_TYPE_PHONE;
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
@@ -83,6 +88,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.ActionButtonsPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.wifitrackerlib.HotspotNetworkEntry;
import com.android.wifitrackerlib.NetworkDetailsTracker;
import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiEntry.ConnectCallback;
@@ -524,12 +530,12 @@ public class WifiDetailPreferenceController2Test {
}
@Test
public void entityHeader_shouldNotHaveIconSetForNotInRangeNetwork() {
public void entityHeader_shouldHaveIconSetForNotInRangeNetwork() {
setUpForNotInRangeNetwork();
displayAndResume();
verify(mMockHeaderController, never()).setIcon(any(Drawable.class));
verify(mMockHeaderController).setIcon(any(Drawable.class));
}
@Test
@@ -1814,6 +1820,71 @@ public class WifiDetailPreferenceController2Test {
assertThat(info.getDisplayName().toString()).isEqualTo("sim2");
}
@Test
public void refreshEntryHeaderIcon_entityHeaderControllerNull_doNothing() {
setUpSpyController();
mController.mEntityHeaderController = null;
mController.refreshEntryHeaderIcon();
verify(mController, never()).getWifiDrawable(any());
}
@Test
public void refreshEntryHeaderIcon_entityHeaderControllerNotNull_setIcon() {
setUpSpyController();
mController.mEntityHeaderController = mMockHeaderController;
mController.refreshEntryHeaderIcon();
verify(mController).getWifiDrawable(any());
verify(mMockHeaderController).setIcon(any(Drawable.class));
}
@Test
public void getWifiDrawable_withHotspotNetworkEntry_returnHotspotDrawable() {
setUpSpyController();
HotspotNetworkEntry entry = mock(HotspotNetworkEntry.class);
when(entry.getDeviceType()).thenReturn(DEVICE_TYPE_PHONE);
mController.getWifiDrawable(entry);
verify(mContext).getDrawable(getHotspotIconResource(DEVICE_TYPE_PHONE));
}
@Test
public void getWifiDrawable_withWifiEntryNotShowXLevelIcon_getIconWithInternet() {
setUpSpyController();
when(mMockWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_MAX);
when(mMockWifiEntry.shouldShowXLevelIcon()).thenReturn(false);
mController.getWifiDrawable(mMockWifiEntry);
verify(mMockIconInjector).getIcon(eq(false) /* noInternet */, anyInt());
}
@Test
public void getWifiDrawable_withWifiEntryShowXLevelIcon_getIconWithNoInternet() {
setUpSpyController();
when(mMockWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_MAX);
when(mMockWifiEntry.shouldShowXLevelIcon()).thenReturn(true);
mController.getWifiDrawable(mMockWifiEntry);
verify(mMockIconInjector).getIcon(eq(true) /* noInternet */, anyInt());
verify(mMockIconInjector).getIcon(eq(true) /* noInternet */, anyInt());
}
@Test
public void setSignalStrengthTitle_prefNotNull_setPrefTitle() {
setUpSpyController();
mController.displayPreference(mMockScreen);
mController.setSignalStrengthTitle(R.string.hotspot_connection_strength);
verify(mMockSignalStrengthPref).setTitle(R.string.hotspot_connection_strength);
}
private SubscriptionInfo mockSubscriptionInfo(int subId, String displayName, int carrierId) {
SubscriptionInfo info = mock(SubscriptionInfo.class);
when(info.getSubscriptionId()).thenReturn(subId);