[Provider Model] Show Wi-Fi icon with exclamation mark
- Show Wi-Fi icon with exclamation mark if the Wi-Fi has no the internet
access (e.g. Printer/GoPro cases).
- If the Wi-Fi network is the default network from ConnectivityManager,
then the Wi-Fi should be available for the internet access.
Bug: 192923176
Test: manual test
atest -c InternetAdapterTest \
InternetDialogControllerTest \
InternetDialogTest
Change-Id: I7239d56b1ad394950f61f51779f0dac611aeddea
Merged-In: I7239d56b1ad394950f61f51779f0dac611aeddea
(cherry picked from commit a51e9f50c6)
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog;
|
|||||||
import static com.android.wifitrackerlib.WifiEntry.SECURITY_NONE;
|
import static com.android.wifitrackerlib.WifiEntry.SECURITY_NONE;
|
||||||
import static com.android.wifitrackerlib.WifiEntry.SECURITY_OWE;
|
import static com.android.wifitrackerlib.WifiEntry.SECURITY_OWE;
|
||||||
|
|
||||||
import android.annotation.ColorInt;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -35,10 +34,10 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
|
import com.android.settingslib.wifi.WifiUtils;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
|
|
||||||
@@ -98,8 +97,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mInternetDialogController.getWifiEntryList().stream()
|
return mInternetDialogController.getWifiEntryList().stream()
|
||||||
.filter(wifiAp -> wifiAp.getConnectedState()
|
.filter(wifiEntry -> !wifiEntry.isDefaultNetwork())
|
||||||
!= WifiEntry.CONNECTED_STATE_CONNECTED)
|
|
||||||
.limit(getItemCount())
|
.limit(getItemCount())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -109,21 +107,21 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
* {@link InternetDialog}.
|
* {@link InternetDialog}.
|
||||||
*
|
*
|
||||||
* Airplane mode is ON (mobile network is gone):
|
* Airplane mode is ON (mobile network is gone):
|
||||||
* Return four Wi-Fi's entries if no connected Wi-Fi.
|
* Return four Wi-Fi's entries if no default Wi-Fi.
|
||||||
* Return three Wi-Fi's entries if one connected Wi-Fi.
|
* Return three Wi-Fi's entries if one default Wi-Fi.
|
||||||
* Airplane mode is OFF (mobile network is visible):
|
* Airplane mode is OFF (mobile network is visible):
|
||||||
* Return three Wi-Fi's entries if no connected Wi-Fi.
|
* Return three Wi-Fi's entries if no default Wi-Fi.
|
||||||
* Return two Wi-Fi's entries if one connected Wi-Fi.
|
* Return two Wi-Fi's entries if one default Wi-Fi.
|
||||||
*
|
*
|
||||||
* @return The total number of networks.
|
* @return The total number of networks.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
boolean hasConnectedWifi = mInternetDialogController.getConnectedWifiEntry() != null;
|
final boolean hasDefaultWifi = mInternetDialogController.getDefaultWifiEntry() != null;
|
||||||
if (mInternetDialogController.isAirplaneModeEnabled()) {
|
if (mInternetDialogController.isAirplaneModeEnabled()) {
|
||||||
return hasConnectedWifi ? 3 : 4;
|
return hasDefaultWifi ? 3 : 4;
|
||||||
} else {
|
} else {
|
||||||
return hasConnectedWifi ? 2 : 3;
|
return hasDefaultWifi ? 2 : 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +140,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
final Context mContext;
|
final Context mContext;
|
||||||
final InternetDialogController mInternetDialogController;
|
final InternetDialogController mInternetDialogController;
|
||||||
|
|
||||||
|
protected WifiUtils.InternetIconInjector mWifiIconInjector;
|
||||||
|
|
||||||
InternetViewHolder(View view, InternetDialogController internetDialogController) {
|
InternetViewHolder(View view, InternetDialogController internetDialogController) {
|
||||||
super(view);
|
super(view);
|
||||||
mContext = view.getContext();
|
mContext = view.getContext();
|
||||||
@@ -153,6 +153,7 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
mWifiTitleText = view.requireViewById(R.id.wifi_title);
|
mWifiTitleText = view.requireViewById(R.id.wifi_title);
|
||||||
mWifiSummaryText = view.requireViewById(R.id.wifi_summary);
|
mWifiSummaryText = view.requireViewById(R.id.wifi_summary);
|
||||||
mWifiLockedIcon = view.requireViewById(R.id.wifi_locked_icon);
|
mWifiLockedIcon = view.requireViewById(R.id.wifi_locked_icon);
|
||||||
|
mWifiIconInjector = mInternetDialogController.getWifiIconInjector();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBind(WifiEntry wifiEntry) {
|
void onBind(WifiEntry wifiEntry) {
|
||||||
@@ -207,19 +208,17 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
mWifiSummaryText.setText(summary);
|
mWifiSummaryText.setText(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable getWifiDrawable(WifiEntry wifiEntry) throws Throwable {
|
Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable {
|
||||||
Drawable drawable = mContext.getDrawable(
|
final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(),
|
||||||
com.android.internal.R.drawable.ic_wifi_signal_0);
|
wifiEntry.getLevel());
|
||||||
|
if (drawable == null) {
|
||||||
AtomicReference<Drawable> shared = new AtomicReference<>();
|
return null;
|
||||||
final @ColorInt int tint = Utils.getColorAttrDefaultColor(mContext,
|
}
|
||||||
android.R.attr.colorControlNormal);
|
drawable.setTint(
|
||||||
Drawable signalDrawable = mContext.getDrawable(
|
Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal));
|
||||||
Utils.getWifiIconResource(wifiEntry.getLevel()));
|
final AtomicReference<Drawable> shared = new AtomicReference<>();
|
||||||
signalDrawable.setTint(tint);
|
shared.set(drawable);
|
||||||
shared.set(signalDrawable);
|
return shared.get();
|
||||||
drawable = shared.get();
|
|
||||||
return drawable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
protected WifiManager mWifiManager;
|
protected WifiManager mWifiManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected View mDialogView;
|
protected View mDialogView;
|
||||||
|
@VisibleForTesting
|
||||||
|
protected WifiEntry mConnectedWifiEntry;
|
||||||
|
|
||||||
private InternetDialogFactory mInternetDialogFactory;
|
private InternetDialogFactory mInternetDialogFactory;
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@@ -123,7 +125,6 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
private Switch mWiFiToggle;
|
private Switch mWiFiToggle;
|
||||||
private Button mDoneButton;
|
private Button mDoneButton;
|
||||||
private Drawable mBackgroundOn;
|
private Drawable mBackgroundOn;
|
||||||
private WifiEntry mConnectedWifiEntry;
|
|
||||||
private int mListMaxHeight;
|
private int mListMaxHeight;
|
||||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
private boolean mCanConfigMobileData;
|
private boolean mCanConfigMobileData;
|
||||||
@@ -355,8 +356,7 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setConnectedWifiLayout() {
|
private void setConnectedWifiLayout() {
|
||||||
if (!mWifiManager.isWifiEnabled()
|
if (!mWifiManager.isWifiEnabled() || mConnectedWifiEntry == null) {
|
||||||
|| mInternetDialogController.getConnectedWifiEntry() == null) {
|
|
||||||
mConnectedWifListLayout.setBackground(null);
|
mConnectedWifListLayout.setBackground(null);
|
||||||
mConnectedWifListLayout.setVisibility(View.GONE);
|
mConnectedWifListLayout.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
@@ -364,7 +364,8 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
mConnectedWifListLayout.setVisibility(View.VISIBLE);
|
mConnectedWifListLayout.setVisibility(View.VISIBLE);
|
||||||
mConnectedWifiTitleText.setText(getConnectedWifiTitle());
|
mConnectedWifiTitleText.setText(getConnectedWifiTitle());
|
||||||
mConnectedWifiSummaryText.setText(getConnectedWifiSummary());
|
mConnectedWifiSummaryText.setText(getConnectedWifiSummary());
|
||||||
mConnectedWifiIcon.setImageDrawable(getConnectedWifiDrawable());
|
mConnectedWifiIcon.setImageDrawable(
|
||||||
|
mInternetDialogController.getConnectedWifiDrawable(mConnectedWifiEntry));
|
||||||
mConnectedWifiTitleText.setTextColor(
|
mConnectedWifiTitleText.setTextColor(
|
||||||
mContext.getColor(R.color.connected_network_primary_color));
|
mContext.getColor(R.color.connected_network_primary_color));
|
||||||
mConnectedWifiSummaryText.setTextColor(
|
mConnectedWifiSummaryText.setTextColor(
|
||||||
@@ -391,15 +392,6 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
mIsProgressBarVisible && !mIsSearchingHidden);
|
mIsProgressBarVisible && !mIsSearchingHidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getConnectedWifiDrawable() {
|
|
||||||
try {
|
|
||||||
return mInternetDialogController.getWifiConnectedDrawable(mConnectedWifiEntry);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Drawable getSignalStrengthDrawable() {
|
private Drawable getSignalStrengthDrawable() {
|
||||||
return mInternetDialogController.getSignalStrengthDrawable();
|
return mInternetDialogController.getSignalStrengthDrawable();
|
||||||
}
|
}
|
||||||
@@ -413,11 +405,11 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getConnectedWifiTitle() {
|
String getConnectedWifiTitle() {
|
||||||
return mInternetDialogController.getConnectedWifiTitle();
|
return mInternetDialogController.getDefaultWifiTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getConnectedWifiSummary() {
|
String getConnectedWifiSummary() {
|
||||||
return mInternetDialogController.getConnectedWifiSummary();
|
return mInternetDialogController.getDefaultWifiSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showProgressBar() {
|
protected void showProgressBar() {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.systemui.qs.tiles.dialog;
|
|||||||
import static com.android.settingslib.mobile.MobileMappings.getIconKey;
|
import static com.android.settingslib.mobile.MobileMappings.getIconKey;
|
||||||
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
|
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
|
||||||
|
|
||||||
import android.annotation.ColorInt;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -134,6 +133,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
|
protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected InternetTelephonyCallback mInternetTelephonyCallback;
|
protected InternetTelephonyCallback mInternetTelephonyCallback;
|
||||||
|
@VisibleForTesting
|
||||||
|
protected WifiUtils.InternetIconInjector mWifiIconInjector;
|
||||||
|
|
||||||
private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
|
private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
|
||||||
new KeyguardUpdateMonitorCallback() {
|
new KeyguardUpdateMonitorCallback() {
|
||||||
@@ -181,6 +182,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
mActivityStarter = starter;
|
mActivityStarter = starter;
|
||||||
mAccessPointController = accessPointController;
|
mAccessPointController = accessPointController;
|
||||||
mConfig = MobileMappings.Config.readConfig(mContext);
|
mConfig = MobileMappings.Config.readConfig(mContext);
|
||||||
|
mWifiIconInjector = new WifiUtils.InternetIconInjector(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStart(@NonNull InternetDialogCallback callback) {
|
void onStart(@NonNull InternetDialogCallback callback) {
|
||||||
@@ -315,14 +317,14 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE);
|
return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable getWifiConnectedDrawable(WifiEntry wifiEntry) throws Throwable {
|
Drawable getConnectedWifiDrawable(@NonNull WifiEntry wifiEntry) {
|
||||||
final @ColorInt int tint;
|
final Drawable drawable =
|
||||||
tint = Utils.getColorAttrDefaultColor(mContext,
|
mWifiIconInjector.getIcon(false /* noInternet*/, wifiEntry.getLevel());
|
||||||
com.android.internal.R.attr.colorControlNormal);
|
if (drawable == null) {
|
||||||
final Drawable drawable = mContext.getDrawable(
|
return null;
|
||||||
com.android.settingslib.Utils.getWifiIconResource(wifiEntry.getLevel()));
|
}
|
||||||
drawable.setTint(tint);
|
drawable.setTint(Utils.getColorAttrDefaultColor(mContext,
|
||||||
|
com.android.internal.R.attr.colorControlNormal));
|
||||||
return drawable;
|
return drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,24 +527,24 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getConnectedWifiTitle() {
|
String getDefaultWifiTitle() {
|
||||||
if (getConnectedWifiEntry() == null) {
|
if (getDefaultWifiEntry() == null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "connected entry is null");
|
Log.d(TAG, "connected entry is null");
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getConnectedWifiEntry().getTitle();
|
return getDefaultWifiEntry().getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getConnectedWifiSummary() {
|
String getDefaultWifiSummary() {
|
||||||
if (getConnectedWifiEntry() == null) {
|
if (getDefaultWifiEntry() == null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "connected entry is null");
|
Log.d(TAG, "connected entry is null");
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getConnectedWifiEntry().getSummary(false);
|
return getDefaultWifiEntry().getSummary(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchNetworkSetting() {
|
void launchNetworkSetting() {
|
||||||
@@ -570,8 +572,11 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
return mWifiEntry;
|
return mWifiEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiEntry getConnectedWifiEntry() {
|
WifiEntry getDefaultWifiEntry() {
|
||||||
return mConnectedEntry;
|
if (mConnectedEntry != null && mConnectedEntry.isDefaultNetwork()) {
|
||||||
|
return mConnectedEntry;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiManager getWifiManager() {
|
WifiManager getWifiManager() {
|
||||||
@@ -770,7 +775,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
mConnectedEntry = null;
|
mConnectedEntry = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCallback.onAccessPointsChanged(mWifiEntry, mConnectedEntry);
|
mCallback.onAccessPointsChanged(mWifiEntry, getDefaultWifiEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -873,6 +878,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WifiUtils.InternetIconInjector getWifiIconInjector() {
|
||||||
|
return mWifiIconInjector;
|
||||||
|
}
|
||||||
|
|
||||||
interface InternetDialogCallback {
|
interface InternetDialogCallback {
|
||||||
|
|
||||||
void onRefreshCarrierInfo();
|
void onRefreshCarrierInfo();
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package com.android.systemui.qs.tiles.dialog;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
@@ -11,6 +13,7 @@ import android.widget.LinearLayout;
|
|||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
|
import com.android.settingslib.wifi.WifiUtils;
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
|
|
||||||
@@ -28,51 +31,55 @@ public class InternetAdapterTest extends SysuiTestCase {
|
|||||||
|
|
||||||
private static final String WIFI_TITLE = "Wi-Fi Title";
|
private static final String WIFI_TITLE = "Wi-Fi Title";
|
||||||
private static final String WIFI_SUMMARY = "Wi-Fi Summary";
|
private static final String WIFI_SUMMARY = "Wi-Fi Summary";
|
||||||
private InternetDialogController mInternetDialogController = mock(
|
|
||||||
InternetDialogController.class);
|
@Mock
|
||||||
|
private WifiEntry mWifiEntry;
|
||||||
|
@Mock
|
||||||
|
private InternetDialogController mInternetDialogController;
|
||||||
|
@Mock
|
||||||
|
private WifiUtils.InternetIconInjector mWifiIconInjector;
|
||||||
|
|
||||||
private InternetAdapter mInternetAdapter;
|
private InternetAdapter mInternetAdapter;
|
||||||
private InternetAdapter.InternetViewHolder mViewHolder;
|
private InternetAdapter.InternetViewHolder mViewHolder;
|
||||||
@Mock
|
|
||||||
private WifiEntry mWifiEntry = mock(WifiEntry.class);
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
||||||
mViewHolder = (InternetAdapter.InternetViewHolder) mInternetAdapter
|
mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
|
||||||
.onCreateViewHolder(new LinearLayout(mContext), 0);
|
|
||||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
||||||
|
mViewHolder.mWifiIconInjector = mWifiIconInjector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_withApmOnWifiOnNoConnectedWifi_returnFour() {
|
public void getItemCount_withApmOnWifiOnNoDefaultWifi_returnFour() {
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(4);
|
assertThat(mInternetAdapter.getItemCount()).isEqualTo(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_withApmOnWifiOnHasConnectedWifi_returnThree() {
|
public void getItemCount_withApmOnWifiOnHasDefaultWifi_returnThree() {
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry);
|
when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry);
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_withApmOffWifiOnNoConnectedWifi_returnThree() {
|
public void getItemCount_withApmOffWifiOnNoDefaultWifi_returnThree() {
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
assertThat(mInternetAdapter.getItemCount()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_withApmOffWifiOnHasConnectedWifi_returnTwo() {
|
public void getItemCount_withApmOffWifiOnHasDefaultWifi_returnTwo() {
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry);
|
when(mInternetDialogController.getDefaultWifiEntry()).thenReturn(mWifiEntry);
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mInternetAdapter.getItemCount()).isEqualTo(2);
|
assertThat(mInternetAdapter.getItemCount()).isEqualTo(2);
|
||||||
@@ -99,4 +106,22 @@ public class InternetAdapterTest extends SysuiTestCase {
|
|||||||
assertThat(mViewHolder.mWifiIcon.getVisibility()).isEqualTo(View.VISIBLE);
|
assertThat(mViewHolder.mWifiIcon.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
assertThat(mViewHolder.mWifiLockedIcon.getVisibility()).isEqualTo(View.VISIBLE);
|
assertThat(mViewHolder.mWifiLockedIcon.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_bindDefaultWifiNetwork_getIconWithInternet() {
|
||||||
|
when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(false);
|
||||||
|
|
||||||
|
mInternetAdapter.onBindViewHolder(mViewHolder, 0);
|
||||||
|
|
||||||
|
verify(mWifiIconInjector).getIcon(eq(false) /* noInternet */, anyInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_bindNoDefaultWifiNetwork_getIconWithNoInternet() {
|
||||||
|
when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true);
|
||||||
|
|
||||||
|
mInternetAdapter.onBindViewHolder(mViewHolder, 0);
|
||||||
|
|
||||||
|
verify(mWifiIconInjector).getIcon(eq(true) /* noInternet */, anyInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
@@ -13,6 +15,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
@@ -30,6 +33,8 @@ import androidx.test.filters.SmallTest;
|
|||||||
|
|
||||||
import com.android.internal.logging.UiEventLogger;
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
|
import com.android.settingslib.wifi.WifiUtils;
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||||
import com.android.systemui.dagger.qualifiers.Main;
|
import com.android.systemui.dagger.qualifiers.Main;
|
||||||
@@ -60,16 +65,12 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
private static final String CONNECTED_TITLE = "Connected Wi-Fi Title";
|
private static final String CONNECTED_TITLE = "Connected Wi-Fi Title";
|
||||||
private static final String CONNECTED_SUMMARY = "Connected Wi-Fi Summary";
|
private static final String CONNECTED_SUMMARY = "Connected Wi-Fi Summary";
|
||||||
|
|
||||||
private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class);
|
@Mock
|
||||||
private MockInternetDialogController mInternetDialogController;
|
private WifiManager mWifiManager;
|
||||||
private InternetDialogController.InternetDialogCallback mCallback =
|
@Mock
|
||||||
mock(InternetDialogController.InternetDialogCallback.class);
|
private TelephonyManager mTelephonyManager;
|
||||||
private ActivityStarter mStarter = mock(ActivityStarter.class);
|
@Mock
|
||||||
private WifiManager mWifiManager = mock(WifiManager.class);
|
private SubscriptionManager mSubscriptionManager;
|
||||||
private ConnectivityManager mConnectivityManager = mock(ConnectivityManager.class);
|
|
||||||
private TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
|
|
||||||
private SubscriptionManager mSubscriptionManager = mock(SubscriptionManager.class);
|
|
||||||
private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
|
|
||||||
@Mock
|
@Mock
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -88,21 +89,31 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
@Mock
|
@Mock
|
||||||
private BroadcastDispatcher mBroadcastDispatcher;
|
private BroadcastDispatcher mBroadcastDispatcher;
|
||||||
|
@Mock
|
||||||
|
private WifiUtils.InternetIconInjector mWifiIconInjector;
|
||||||
|
|
||||||
|
private MockInternetDialogController mInternetDialogController;
|
||||||
|
private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
||||||
mInternetDialogController = new MockInternetDialogController(mContext, mUiEventLogger,
|
when(mConnectedEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
mStarter, mAccessPointController, mSubscriptionManager, mTelephonyManager,
|
|
||||||
mWifiManager, mConnectivityManager, mHandler, mExecutor, mBroadcastDispatcher,
|
mInternetDialogController = new MockInternetDialogController(mContext,
|
||||||
|
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
||||||
|
mSubscriptionManager, mTelephonyManager, mWifiManager,
|
||||||
|
mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher,
|
||||||
mKeyguardUpdateMonitor, mGlobalSettings);
|
mKeyguardUpdateMonitor, mGlobalSettings);
|
||||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
||||||
mInternetDialogController.mOnSubscriptionsChangedListener);
|
mInternetDialogController.mOnSubscriptionsChangedListener);
|
||||||
mInternetDialogController.onStart(mCallback);
|
mInternetDialogController.onStart(
|
||||||
|
mock(InternetDialogController.InternetDialogCallback.class));
|
||||||
mInternetDialogController.mActivityStarter = mActivityStarter;
|
mInternetDialogController.mActivityStarter = mActivityStarter;
|
||||||
mInternetDialogController.mConnectedEntry = mConnectedEntry;
|
mInternetDialogController.mConnectedEntry = mConnectedEntry;
|
||||||
|
mInternetDialogController.mWifiIconInjector = mWifiIconInjector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -199,35 +210,53 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedWifiTitle_withNoConnectedEntry_returnNull() {
|
public void getDefaultWifiEntry_connectedEntryIsNull_returnNull() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
|
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
||||||
""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedWifiTitle_withConnectedEntry_returnTitle() {
|
public void getDefaultWifiEntry_connectedEntryIsNotDefault_returnNull() {
|
||||||
|
when(mConnectedEntry.isDefaultNetwork()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDefaultWifiEntry_connectedEntryIsDefault_returnConnectedEntry() {
|
||||||
|
// The default conditions have been set in setUp().
|
||||||
|
// - The connected Wi-Fi entry with the default network condition.
|
||||||
|
|
||||||
|
assertThat(mInternetDialogController.getDefaultWifiEntry()).isEqualTo(mConnectedEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDefaultWifiTitle_withNoDefaultEntry_returnEmpty() {
|
||||||
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
|
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDefaultWifiTitle_withDefaultEntry_returnTitle() {
|
||||||
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiTitle(),
|
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEqualTo(CONNECTED_TITLE);
|
||||||
CONNECTED_TITLE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedWifiSummary_withNoConnectedEntry_returnNull() {
|
public void getDefaultWifiSummary_withNoDefaultEntry_returnEmpty() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
|
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEmpty();
|
||||||
""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedWifiSummary_withConnectedEntry_returnSummary() {
|
public void getDefaultWifiSummary_withDefaultEntry_returnSummary() {
|
||||||
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mInternetDialogController.getConnectedWifiSummary(),
|
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEqualTo(CONNECTED_SUMMARY);
|
||||||
CONNECTED_SUMMARY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -251,6 +280,18 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull();
|
assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiConnectedDrawable_withConnectedEntry_returnIntentIconWithColorAccent() {
|
||||||
|
final Drawable drawable = mock(Drawable.class);
|
||||||
|
when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable);
|
||||||
|
|
||||||
|
mInternetDialogController.getConnectedWifiDrawable(mConnectedEntry);
|
||||||
|
|
||||||
|
verify(mWifiIconInjector).getIcon(eq(false), anyInt());
|
||||||
|
verify(drawable).setTint(Utils.getColorAttrDefaultColor(mContext,
|
||||||
|
com.android.internal.R.attr.colorControlNormal));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() {
|
public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -141,11 +142,13 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||||
when(mInternetDialogController.getConnectedWifiEntry()).thenReturn(mWifiEntry);
|
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
|
mInternetDialog.mConnectedWifiEntry = mWifiEntry;
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
|
final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
|
||||||
R.id.wifi_connected_layout);
|
R.id.wifi_connected_layout);
|
||||||
|
|
||||||
assertThat(linearLayout.getVisibility()).isEqualTo(View.VISIBLE);
|
assertThat(linearLayout.getVisibility()).isEqualTo(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +183,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
||||||
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
@@ -190,6 +194,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
||||||
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||||
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
||||||
when(wifiScanResults.size()).thenReturn(1);
|
when(wifiScanResults.size()).thenReturn(1);
|
||||||
@@ -211,6 +216,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() {
|
public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() {
|
||||||
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
||||||
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
List<ScanResult> wifiScanResults = mock(ArrayList.class);
|
||||||
when(wifiScanResults.size()).thenReturn(0);
|
when(wifiScanResults.size()).thenReturn(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user