Merge "Show Instant Tether network icon" into udc-qpr-dev
diff --git a/src/com/android/settings/wifi/WifiEntryPreference.java b/src/com/android/settings/wifi/WifiEntryPreference.java
index 5b44887..7206666 100644
--- a/src/com/android/settings/wifi/WifiEntryPreference.java
+++ b/src/com/android/settings/wifi/WifiEntryPreference.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.wifi;
+import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
+
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
@@ -37,6 +39,7 @@
import com.android.settingslib.Utils;
import com.android.settingslib.wifi.WifiUtils;
import com.android.wifitrackerlib.BaseWifiTracker;
+import com.android.wifitrackerlib.HotspotNetworkEntry;
import com.android.wifitrackerlib.WifiEntry;
/**
@@ -145,13 +148,17 @@
*/
public void refresh() {
setTitle(mWifiEntry.getTitle());
- final int level = mWifiEntry.getLevel();
- final boolean showX = mWifiEntry.shouldShowXLevelIcon();
- if (level != mLevel || showX != mShowX) {
- mLevel = level;
- mShowX = showX;
- updateIcon(mShowX, mLevel);
- notifyChanged();
+ if (mWifiEntry instanceof HotspotNetworkEntry) {
+ updateHotspotIcon(((HotspotNetworkEntry) mWifiEntry).getDeviceType());
+ } else {
+ int level = mWifiEntry.getLevel();
+ boolean showX = mWifiEntry.shouldShowXLevelIcon();
+
+ if (level != mLevel || showX != mShowX) {
+ mLevel = level;
+ mShowX = showX;
+ updateIcon(mShowX, mLevel);
+ }
}
setSummary(mWifiEntry.getSummary(false /* concise */));
@@ -201,14 +208,7 @@
return accent ? android.R.attr.colorAccent : android.R.attr.colorControlNormal;
}
- @VisibleForTesting
- void updateIcon(boolean showX, int level) {
- if (level == -1) {
- setIcon(null);
- return;
- }
-
- final Drawable drawable = mIconInjector.getIcon(showX, level);
+ private void setIconWithTint(Drawable drawable) {
if (drawable != null) {
// Must use Drawable#setTintList() instead of Drawable#setTint() to show the grey
// icon when the preference is disabled.
@@ -219,6 +219,20 @@
}
}
+ @VisibleForTesting
+ void updateIcon(boolean showX, int level) {
+ if (level == -1) {
+ setIcon(null);
+ return;
+ }
+ setIconWithTint(mIconInjector.getIcon(showX, level));
+ }
+
+ @VisibleForTesting
+ void updateHotspotIcon(int deviceType) {
+ setIconWithTint(getContext().getDrawable(getHotspotIconResource(deviceType)));
+ }
+
@Nullable
private StateListDrawable getFrictionStateListDrawable() {
TypedArray frictionSld;
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java
index a60b531..316beb3 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiEntryPreferenceTest.java
@@ -18,11 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.graphics.drawable.Drawable;
+import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -31,6 +35,7 @@
import com.android.settingslib.R;
import com.android.settingslib.wifi.WifiUtils;
+import com.android.wifitrackerlib.HotspotNetworkEntry;
import com.android.wifitrackerlib.WifiEntry;
import org.junit.Before;
@@ -52,6 +57,8 @@
@Mock
private WifiEntry mMockWifiEntry;
@Mock
+ private HotspotNetworkEntry mHotspotNetworkEntry;
+ @Mock
private WifiUtils.InternetIconInjector mMockIconInjector;
@Mock
@@ -256,4 +263,26 @@
public void getSecondTargetResId_shouldNotReturnZero() {
assertThat(mPref.getSecondTargetResId()).isNotEqualTo(0);
}
+
+ @Test
+ public void refresh_itsHotspotNetworkEntry_shouldUpdateHotspotIcon() {
+ int deviceType = NetworkProviderInfo.DEVICE_TYPE_PHONE;
+ when(mHotspotNetworkEntry.getDeviceType()).thenReturn(deviceType);
+ WifiEntryPreference pref = spy(
+ new WifiEntryPreference(mContext, mHotspotNetworkEntry, mMockIconInjector));
+
+ pref.refresh();
+
+ verify(pref).updateHotspotIcon(deviceType);
+ }
+
+ @Test
+ public void refresh_notHotspotNetworkEntry_shouldNotUpdateHotspotIcon() {
+ WifiEntryPreference pref = spy(
+ new WifiEntryPreference(mContext, mMockWifiEntry, mMockIconInjector));
+
+ pref.refresh();
+
+ verify(pref, never()).updateHotspotIcon(anyInt());
+ }
}