Merge "Show Instant Tether network icon" into udc-qpr-dev am: 8cdbeab57c

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24122143

Change-Id: If84ef910cfd4f0af6f34007c73c2cb50a91ea40e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Weng Su
2023-07-20 15:50:37 +00:00
committed by Automerger Merge Worker
2 changed files with 58 additions and 15 deletions

View File

@@ -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.RestrictedPreference;
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 class WifiEntryPreference extends RestrictedPreference implements
*/
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 @@ public class WifiEntryPreference extends RestrictedPreference implements
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 @@ public class WifiEntryPreference extends RestrictedPreference implements
}
}
@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;

View File

@@ -18,11 +18,15 @@ package com.android.settings.wifi;
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 androidx.preference.PreferenceViewHolder;
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 @@ public class WifiEntryPreferenceTest {
@Mock
private WifiEntry mMockWifiEntry;
@Mock
private HotspotNetworkEntry mHotspotNetworkEntry;
@Mock
private WifiUtils.InternetIconInjector mMockIconInjector;
@Mock
@@ -256,4 +263,26 @@ public class WifiEntryPreferenceTest {
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());
}
}