Merge "Show Instant Tether network icon" into udc-qpr-dev
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import static com.android.settingslib.wifi.WifiUtils.getHotspotIconResource;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -37,6 +39,7 @@ import com.android.settingslib.RestrictedPreference;
|
|||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.wifi.WifiUtils;
|
import com.android.settingslib.wifi.WifiUtils;
|
||||||
import com.android.wifitrackerlib.BaseWifiTracker;
|
import com.android.wifitrackerlib.BaseWifiTracker;
|
||||||
|
import com.android.wifitrackerlib.HotspotNetworkEntry;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,13 +148,17 @@ public class WifiEntryPreference extends RestrictedPreference implements
|
|||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
setTitle(mWifiEntry.getTitle());
|
setTitle(mWifiEntry.getTitle());
|
||||||
final int level = mWifiEntry.getLevel();
|
if (mWifiEntry instanceof HotspotNetworkEntry) {
|
||||||
final boolean showX = mWifiEntry.shouldShowXLevelIcon();
|
updateHotspotIcon(((HotspotNetworkEntry) mWifiEntry).getDeviceType());
|
||||||
|
} else {
|
||||||
|
int level = mWifiEntry.getLevel();
|
||||||
|
boolean showX = mWifiEntry.shouldShowXLevelIcon();
|
||||||
|
|
||||||
if (level != mLevel || showX != mShowX) {
|
if (level != mLevel || showX != mShowX) {
|
||||||
mLevel = level;
|
mLevel = level;
|
||||||
mShowX = showX;
|
mShowX = showX;
|
||||||
updateIcon(mShowX, mLevel);
|
updateIcon(mShowX, mLevel);
|
||||||
notifyChanged();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setSummary(mWifiEntry.getSummary(false /* concise */));
|
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;
|
return accent ? android.R.attr.colorAccent : android.R.attr.colorControlNormal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
private void setIconWithTint(Drawable drawable) {
|
||||||
void updateIcon(boolean showX, int level) {
|
|
||||||
if (level == -1) {
|
|
||||||
setIcon(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Drawable drawable = mIconInjector.getIcon(showX, level);
|
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
// Must use Drawable#setTintList() instead of Drawable#setTint() to show the grey
|
// Must use Drawable#setTintList() instead of Drawable#setTint() to show the grey
|
||||||
// icon when the preference is disabled.
|
// 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
|
@Nullable
|
||||||
private StateListDrawable getFrictionStateListDrawable() {
|
private StateListDrawable getFrictionStateListDrawable() {
|
||||||
TypedArray frictionSld;
|
TypedArray frictionSld;
|
||||||
|
@@ -18,11 +18,15 @@ package com.android.settings.wifi;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.wifi.sharedconnectivity.app.NetworkProviderInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -31,6 +35,7 @@ import androidx.preference.PreferenceViewHolder;
|
|||||||
|
|
||||||
import com.android.settingslib.R;
|
import com.android.settingslib.R;
|
||||||
import com.android.settingslib.wifi.WifiUtils;
|
import com.android.settingslib.wifi.WifiUtils;
|
||||||
|
import com.android.wifitrackerlib.HotspotNetworkEntry;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -52,6 +57,8 @@ public class WifiEntryPreferenceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private WifiEntry mMockWifiEntry;
|
private WifiEntry mMockWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
|
private HotspotNetworkEntry mHotspotNetworkEntry;
|
||||||
|
@Mock
|
||||||
private WifiUtils.InternetIconInjector mMockIconInjector;
|
private WifiUtils.InternetIconInjector mMockIconInjector;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -256,4 +263,26 @@ public class WifiEntryPreferenceTest {
|
|||||||
public void getSecondTargetResId_shouldNotReturnZero() {
|
public void getSecondTargetResId_shouldNotReturnZero() {
|
||||||
assertThat(mPref.getSecondTargetResId()).isNotEqualTo(0);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user