[Provider Model] Correct the connected Wi-Fi UI am: 151d93fdbc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15611714 Change-Id: I2e86f4149761cd2f0205bae380b3148f6824f0e8
This commit is contained in:
@@ -97,7 +97,8 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mInternetDialogController.getWifiEntryList().stream()
|
return mInternetDialogController.getWifiEntryList().stream()
|
||||||
.filter(wifiEntry -> !wifiEntry.isDefaultNetwork())
|
.filter(wifiEntry -> (!wifiEntry.isDefaultNetwork()
|
||||||
|
|| !wifiEntry.hasInternetAccess()))
|
||||||
.limit(getItemCount())
|
.limit(getItemCount())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -107,21 +108,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 default Wi-Fi.
|
* Return four Wi-Fi's entries if no internet Wi-Fi.
|
||||||
* Return three Wi-Fi's entries if one default Wi-Fi.
|
* Return three Wi-Fi's entries if one internet 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 default Wi-Fi.
|
* Return three Wi-Fi's entries if no internet Wi-Fi.
|
||||||
* Return two Wi-Fi's entries if one default Wi-Fi.
|
* Return two Wi-Fi's entries if one internet Wi-Fi.
|
||||||
*
|
*
|
||||||
* @return The total number of networks.
|
* @return The total number of networks.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
final boolean hasDefaultWifi = mInternetDialogController.getDefaultWifiEntry() != null;
|
final boolean hasInternetWifi = mInternetDialogController.getInternetWifiEntry() != null;
|
||||||
if (mInternetDialogController.isAirplaneModeEnabled()) {
|
if (mInternetDialogController.isAirplaneModeEnabled()) {
|
||||||
return hasDefaultWifi ? 3 : 4;
|
return hasInternetWifi ? 3 : 4;
|
||||||
} else {
|
} else {
|
||||||
return hasDefaultWifi ? 2 : 3;
|
return hasInternetWifi ? 2 : 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,10 +379,10 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mConnectedWifListLayout.setVisibility(View.VISIBLE);
|
mConnectedWifListLayout.setVisibility(View.VISIBLE);
|
||||||
mConnectedWifiTitleText.setText(getConnectedWifiTitle());
|
mConnectedWifiTitleText.setText(mInternetDialogController.getInternetWifiTitle());
|
||||||
mConnectedWifiSummaryText.setText(getConnectedWifiSummary());
|
mConnectedWifiSummaryText.setText(mInternetDialogController.getInternetWifiSummary());
|
||||||
mConnectedWifiIcon.setImageDrawable(
|
mConnectedWifiIcon.setImageDrawable(
|
||||||
mInternetDialogController.getConnectedWifiDrawable(mConnectedWifiEntry));
|
mInternetDialogController.getInternetWifiDrawable(mConnectedWifiEntry));
|
||||||
if (mInternetDialogController.isNightMode()) {
|
if (mInternetDialogController.isNightMode()) {
|
||||||
mConnectedWifiTitleText.setTextColor(
|
mConnectedWifiTitleText.setTextColor(
|
||||||
mContext.getColor(R.color.connected_network_primary_color));
|
mContext.getColor(R.color.connected_network_primary_color));
|
||||||
@@ -423,14 +423,6 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
return mInternetDialogController.getMobileNetworkSummary();
|
return mInternetDialogController.getMobileNetworkSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getConnectedWifiTitle() {
|
|
||||||
return mInternetDialogController.getDefaultWifiTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
String getConnectedWifiSummary() {
|
|
||||||
return mInternetDialogController.getDefaultWifiSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showProgressBar() {
|
protected void showProgressBar() {
|
||||||
if (mWifiManager == null || !mWifiManager.isWifiEnabled()
|
if (mWifiManager == null || !mWifiManager.isWifiEnabled()
|
||||||
|| mInternetDialogController.isDeviceLocked()) {
|
|| mInternetDialogController.isDeviceLocked()) {
|
||||||
|
|||||||
@@ -334,9 +334,9 @@ 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 getConnectedWifiDrawable(@NonNull WifiEntry wifiEntry) {
|
Drawable getInternetWifiDrawable(@NonNull WifiEntry wifiEntry) {
|
||||||
final Drawable drawable =
|
final Drawable drawable =
|
||||||
mWifiIconInjector.getIcon(false /* noInternet*/, wifiEntry.getLevel());
|
mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(), wifiEntry.getLevel());
|
||||||
if (drawable == null) {
|
if (drawable == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -549,24 +549,24 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDefaultWifiTitle() {
|
String getInternetWifiTitle() {
|
||||||
if (getDefaultWifiEntry() == null) {
|
if (getInternetWifiEntry() == null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "connected entry is null");
|
Log.d(TAG, "connected entry is null");
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getDefaultWifiEntry().getTitle();
|
return getInternetWifiEntry().getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDefaultWifiSummary() {
|
String getInternetWifiSummary() {
|
||||||
if (getDefaultWifiEntry() == null) {
|
if (getInternetWifiEntry() == null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "connected entry is null");
|
Log.d(TAG, "connected entry is null");
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getDefaultWifiEntry().getSummary(false);
|
return getInternetWifiEntry().getSummary(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchNetworkSetting() {
|
void launchNetworkSetting() {
|
||||||
@@ -594,11 +594,12 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
return mWifiEntry;
|
return mWifiEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiEntry getDefaultWifiEntry() {
|
WifiEntry getInternetWifiEntry() {
|
||||||
if (mConnectedEntry != null && mConnectedEntry.isDefaultNetwork()) {
|
if (mConnectedEntry == null || !mConnectedEntry.isDefaultNetwork()
|
||||||
return mConnectedEntry;
|
|| !mConnectedEntry.hasInternetAccess()) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return mConnectedEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiManager getWifiManager() {
|
WifiManager getWifiManager() {
|
||||||
@@ -801,7 +802,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
|
|||||||
mConnectedEntry = null;
|
mConnectedEntry = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCallback.onAccessPointsChanged(mWifiEntry, getDefaultWifiEntry());
|
mCallback.onAccessPointsChanged(mWifiEntry, getInternetWifiEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ 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";
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private WifiEntry mInternetWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiEntry mWifiEntry;
|
private WifiEntry mWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -45,41 +47,49 @@ public class InternetAdapterTest extends SysuiTestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||||
mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
|
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||||
|
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
|
when(mInternetWifiEntry.hasInternetAccess()).thenReturn(true);
|
||||||
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);
|
||||||
|
|
||||||
|
mInternetAdapter = new InternetAdapter(mInternetDialogController);
|
||||||
|
mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
|
||||||
|
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry);
|
||||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
||||||
mViewHolder.mWifiIconInjector = mWifiIconInjector;
|
mViewHolder.mWifiIconInjector = mWifiIconInjector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemCount_withApmOnWifiOnNoDefaultWifi_returnFour() {
|
public void getItemCount_withApmOnWifiOnNoInternetWifi_returnFour() {
|
||||||
|
// The preconditions WiFi ON is already in setUp()
|
||||||
|
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null);
|
||||||
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_withApmOnWifiOnHasDefaultWifi_returnThree() {
|
public void getItemCount_withApmOnWifiOnHasInternetWifi_returnThree() {
|
||||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||||
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_withApmOffWifiOnNoDefaultWifi_returnThree() {
|
public void getItemCount_withApmOffWifiOnNoInternetWifi_returnThree() {
|
||||||
|
// The preconditions WiFi ON is already in setUp()
|
||||||
|
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null);
|
||||||
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_withApmOffWifiOnHasDefaultWifi_returnTwo() {
|
public void getItemCount_withApmOffWifiOnHasInternetWifi_returnTwo() {
|
||||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||||
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);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import android.content.Intent;
|
|||||||
import android.graphics.drawable.Drawable;
|
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.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
@@ -85,8 +84,6 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
private WifiEntry mConnectedEntry;
|
private WifiEntry mConnectedEntry;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiInfo mWifiInfo;
|
|
||||||
@Mock
|
|
||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
@Mock
|
@Mock
|
||||||
private BroadcastDispatcher mBroadcastDispatcher;
|
private BroadcastDispatcher mBroadcastDispatcher;
|
||||||
@@ -100,9 +97,9 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
||||||
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
|
||||||
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||||
when(mConnectedEntry.isDefaultNetwork()).thenReturn(true);
|
when(mConnectedEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
|
when(mConnectedEntry.hasInternetAccess()).thenReturn(true);
|
||||||
|
|
||||||
mInternetDialogController = new MockInternetDialogController(mContext,
|
mInternetDialogController = new MockInternetDialogController(mContext,
|
||||||
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
||||||
@@ -222,53 +219,62 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiEntry_connectedEntryIsNull_returnNull() {
|
public void getInternetWifiEntry_connectedEntryIsNull_returnNull() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiEntry_connectedEntryIsNotDefault_returnNull() {
|
public void getInternetWifiEntry_connectedWifiIsNotDefaultNetwork_returnNull() {
|
||||||
when(mConnectedEntry.isDefaultNetwork()).thenReturn(false);
|
when(mConnectedEntry.isDefaultNetwork()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isNull();
|
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiEntry_connectedEntryIsDefault_returnConnectedEntry() {
|
public void getInternetWifiEntry_connectedWifiHasNotInternetAccess_returnNull() {
|
||||||
// The default conditions have been set in setUp().
|
when(mConnectedEntry.hasInternetAccess()).thenReturn(false);
|
||||||
// - The connected Wi-Fi entry with the default network condition.
|
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiEntry()).isEqualTo(mConnectedEntry);
|
assertThat(mInternetDialogController.getInternetWifiEntry()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiTitle_withNoDefaultEntry_returnEmpty() {
|
public void getInternetWifiEntry_connectedEntryIsInternetWifi_returnConnectedEntry() {
|
||||||
|
// The preconditions have been set in setUp().
|
||||||
|
// - The connected Wi-Fi entry have both default network and internet access conditions.
|
||||||
|
|
||||||
|
assertThat(mInternetDialogController.getInternetWifiEntry()).isEqualTo(mConnectedEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInternetWifiTitle_withNoConnectedWifiEntry_returnEmpty() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEmpty();
|
assertThat(mInternetDialogController.getInternetWifiTitle()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiTitle_withDefaultEntry_returnTitle() {
|
public void getInternetWifiTitle_withInternetWifi_returnTitle() {
|
||||||
|
// The preconditions have been set in setUp().
|
||||||
|
// - The connected Wi-Fi entry have both default network and internet access conditions.
|
||||||
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
when(mConnectedEntry.getTitle()).thenReturn(CONNECTED_TITLE);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiTitle()).isEqualTo(CONNECTED_TITLE);
|
assertThat(mInternetDialogController.getInternetWifiTitle()).isEqualTo(CONNECTED_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiSummary_withNoDefaultEntry_returnEmpty() {
|
public void getInternetWifiSummary_withNoConnectedWifiEntry_returnEmpty() {
|
||||||
mInternetDialogController.mConnectedEntry = null;
|
mInternetDialogController.mConnectedEntry = null;
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEmpty();
|
assertThat(mInternetDialogController.getInternetWifiSummary()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultWifiSummary_withDefaultEntry_returnSummary() {
|
public void getInternetWifiSummary_withInternetWifi_returnSummary() {
|
||||||
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getDefaultWifiSummary()).isEqualTo(CONNECTED_SUMMARY);
|
assertThat(mInternetDialogController.getInternetWifiSummary()).isEqualTo(CONNECTED_SUMMARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -293,11 +299,11 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getWifiConnectedDrawable_withConnectedEntry_returnIntentIconWithColorAccent() {
|
public void getWifiDrawable_withConnectedEntry_returnIntentIconWithCorrectColor() {
|
||||||
final Drawable drawable = mock(Drawable.class);
|
final Drawable drawable = mock(Drawable.class);
|
||||||
when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable);
|
when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable);
|
||||||
|
|
||||||
mInternetDialogController.getConnectedWifiDrawable(mConnectedEntry);
|
mInternetDialogController.getInternetWifiDrawable(mConnectedEntry);
|
||||||
|
|
||||||
verify(mWifiIconInjector).getIcon(eq(false), anyInt());
|
verify(mWifiIconInjector).getIcon(eq(false), anyInt());
|
||||||
verify(drawable).setTint(mContext.getColor(R.color.connected_network_primary_color));
|
verify(drawable).setTint(mContext.getColor(R.color.connected_network_primary_color));
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -11,12 +12,7 @@ import static org.mockito.Mockito.never;
|
|||||||
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.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -32,7 +28,6 @@ import androidx.test.filters.SmallTest;
|
|||||||
import com.android.internal.logging.UiEventLogger;
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.SysuiTestCase;
|
import com.android.systemui.SysuiTestCase;
|
||||||
import com.android.systemui.dagger.qualifiers.Main;
|
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@@ -53,33 +48,27 @@ import java.util.List;
|
|||||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||||
public class InternetDialogTest extends SysuiTestCase {
|
public class InternetDialogTest extends SysuiTestCase {
|
||||||
|
|
||||||
private static final int SUB_ID = 1;
|
|
||||||
private static final String MOBILE_NETWORK_TITLE = "Mobile Title";
|
private static final String MOBILE_NETWORK_TITLE = "Mobile Title";
|
||||||
private static final String MOBILE_NETWORK_SUMMARY = "Mobile Summary";
|
private static final String MOBILE_NETWORK_SUMMARY = "Mobile Summary";
|
||||||
private static final String WIFI_TITLE = "Connected Wi-Fi Title";
|
private static final String WIFI_TITLE = "Connected Wi-Fi Title";
|
||||||
private static final String WIFI_SUMMARY = "Connected Wi-Fi Summary";
|
private static final String WIFI_SUMMARY = "Connected Wi-Fi Summary";
|
||||||
|
|
||||||
@Mock
|
|
||||||
private InternetDialogFactory mInternetDialogFactory;
|
|
||||||
@Mock
|
|
||||||
private InternetDialogController mInternetDialogController;
|
|
||||||
@Mock
|
|
||||||
private UiEventLogger mUiEventLogger;
|
|
||||||
@Mock
|
@Mock
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private InternetAdapter mInternetAdapter;
|
private WifiManager mWifiManager;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mMockWifiManager;
|
private WifiEntry mInternetWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiEntry mWifiEntry;
|
private WifiEntry mWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiInfo mWifiInfo;
|
private InternetAdapter mInternetAdapter;
|
||||||
|
@Mock
|
||||||
|
private InternetDialogController mInternetDialogController;
|
||||||
|
|
||||||
private MockInternetDialog mInternetDialog;
|
private InternetDialog mInternetDialog;
|
||||||
private WifiReceiver mWifiReceiver;
|
|
||||||
private LinearLayout mWifiToggle;
|
private LinearLayout mWifiToggle;
|
||||||
private LinearLayout mConnectedWifi;
|
private LinearLayout mConnectedWifi;
|
||||||
private RecyclerView mWifiList;
|
private RecyclerView mWifiList;
|
||||||
@@ -88,24 +77,28 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mInternetDialog = new MockInternetDialog(mContext, mInternetDialogFactory,
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
||||||
mInternetDialogController, true, true, mUiEventLogger, mHandler);
|
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialog.show();
|
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
when(mMockWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
|
when(mInternetWifiEntry.hasInternetAccess()).thenReturn(true);
|
||||||
mInternetDialog.setMobileNetworkTitle(MOBILE_NETWORK_TITLE);
|
|
||||||
mInternetDialog.setMobileNetworkSummary(MOBILE_NETWORK_SUMMARY);
|
|
||||||
mInternetDialog.setConnectedWifiTitle(WIFI_TITLE);
|
|
||||||
mInternetDialog.setConnectedWifiSummary(WIFI_SUMMARY);
|
|
||||||
mWifiReceiver = new WifiReceiver();
|
|
||||||
IntentFilter mIntentFilter = new IntentFilter();
|
|
||||||
mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
|
||||||
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
mContext.registerReceiver(mWifiReceiver, mIntentFilter);
|
|
||||||
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.getMobileNetworkTitle()).thenReturn(MOBILE_NETWORK_TITLE);
|
||||||
|
when(mInternetDialogController.getMobileNetworkSummary())
|
||||||
|
.thenReturn(MOBILE_NETWORK_SUMMARY);
|
||||||
|
when(mInternetDialogController.getWifiManager()).thenReturn(mWifiManager);
|
||||||
|
when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry);
|
||||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
|
||||||
|
|
||||||
|
mInternetDialog = new InternetDialog(mContext, mock(InternetDialogFactory.class),
|
||||||
|
mInternetDialogController, true, true, mock(UiEventLogger.class), mHandler);
|
||||||
|
mInternetDialog.mAdapter = mInternetAdapter;
|
||||||
|
mInternetDialog.mConnectedWifiEntry = mInternetWifiEntry;
|
||||||
|
mInternetDialog.show();
|
||||||
|
|
||||||
mWifiToggle = mInternetDialog.mDialogView.requireViewById(R.id.turn_on_wifi_layout);
|
mWifiToggle = mInternetDialog.mDialogView.requireViewById(R.id.turn_on_wifi_layout);
|
||||||
mConnectedWifi = mInternetDialog.mDialogView.requireViewById(R.id.wifi_connected_layout);
|
mConnectedWifi = mInternetDialog.mDialogView.requireViewById(R.id.wifi_connected_layout);
|
||||||
mWifiList = mInternetDialog.mDialogView.requireViewById(R.id.wifi_list_layout);
|
mWifiList = mInternetDialog.mDialogView.requireViewById(R.id.wifi_list_layout);
|
||||||
@@ -148,13 +141,9 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOnAndHasConnectedWifi_showConnectedWifi() {
|
public void updateDialog_wifiOnAndHasInternetWifi_showConnectedWifi() {
|
||||||
|
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||||
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
||||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
|
||||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
|
||||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
|
||||||
mInternetDialog.mConnectedWifiEntry = mWifiEntry;
|
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
@@ -163,6 +152,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOnAndNoConnectedWifi_hideConnectedWifi() {
|
public void updateDialog_wifiOnAndNoConnectedWifi_hideConnectedWifi() {
|
||||||
|
mInternetDialog.mConnectedWifiEntry = null;
|
||||||
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
@@ -182,9 +172,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOnAndHasWifiList_showWifiListAndSeeAll() {
|
public void updateDialog_wifiOnAndHasWifiList_showWifiListAndSeeAll() {
|
||||||
List<WifiEntry> wifiEntries = new ArrayList<WifiEntry>();
|
// The preconditions WiFi ON and WiFi entries are already in setUp()
|
||||||
wifiEntries.add(mWifiEntry);
|
|
||||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries);
|
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
@@ -193,13 +181,9 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_deviceLockedAndHasConnectedWifi_showHighlightWifiToggle() {
|
public void updateDialog_deviceLockedAndHasInternetWifi_showHighlightWifiToggle() {
|
||||||
|
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
|
||||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
|
||||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
|
||||||
mInternetDialog.mConnectedWifiEntry = mWifiEntry;
|
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
@@ -208,13 +192,9 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_deviceLockedAndHasConnectedWifi_hideConnectedWifi() {
|
public void updateDialog_deviceLockedAndHasInternetWifi_hideConnectedWifi() {
|
||||||
|
// The preconditions WiFi ON and Internet WiFi are already in setUp()
|
||||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||||
when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
|
||||||
when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
|
||||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
|
||||||
when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
|
|
||||||
mInternetDialog.mConnectedWifiEntry = mWifiEntry;
|
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
@@ -223,10 +203,8 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_deviceLockedAndHasWifiList_hideWifiListAndSeeAll() {
|
public void updateDialog_deviceLockedAndHasWifiList_hideWifiListAndSeeAll() {
|
||||||
|
// The preconditions WiFi entries are already in setUp()
|
||||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||||
List<WifiEntry> wifiEntries = new ArrayList<WifiEntry>();
|
|
||||||
wifiEntries.add(mWifiEntry);
|
|
||||||
when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries);
|
|
||||||
|
|
||||||
mInternetDialog.updateDialog();
|
mInternetDialog.updateDialog();
|
||||||
|
|
||||||
@@ -244,7 +222,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
|
|
||||||
@@ -266,10 +244,10 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiManager.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);
|
||||||
when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
when(mWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
|
|
||||||
@@ -288,10 +266,10 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() {
|
public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mMockWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiManager.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);
|
||||||
when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
when(mWifiManager.getScanResults()).thenReturn(wifiScanResults);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
|
|
||||||
@@ -307,78 +285,4 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
assertThat(mInternetDialog.mIsProgressBarVisible).isTrue();
|
assertThat(mInternetDialog.mIsProgressBarVisible).isTrue();
|
||||||
assertThat(mInternetDialog.mIsSearchingHidden).isTrue();
|
assertThat(mInternetDialog.mIsSearchingHidden).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MockInternetDialog extends InternetDialog {
|
|
||||||
|
|
||||||
private String mMobileNetworkTitle;
|
|
||||||
private String mMobileNetworkSummary;
|
|
||||||
private String mConnectedWifiTitle;
|
|
||||||
private String mConnectedWifiSummary;
|
|
||||||
|
|
||||||
MockInternetDialog(Context context, InternetDialogFactory internetDialogFactory,
|
|
||||||
InternetDialogController internetDialogController, boolean canConfigMobileData,
|
|
||||||
boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) {
|
|
||||||
super(context, internetDialogFactory, internetDialogController, canConfigMobileData,
|
|
||||||
aboveStatusBar, uiEventLogger, handler);
|
|
||||||
mAdapter = mInternetAdapter;
|
|
||||||
mWifiManager = mMockWifiManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getMobileNetworkTitle() {
|
|
||||||
return mMobileNetworkTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getMobileNetworkSummary() {
|
|
||||||
return mMobileNetworkSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMobileNetworkTitle(String title) {
|
|
||||||
mMobileNetworkTitle = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMobileNetworkSummary(String summary) {
|
|
||||||
mMobileNetworkSummary = summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getConnectedWifiTitle() {
|
|
||||||
return mConnectedWifiTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getConnectedWifiSummary() {
|
|
||||||
return mConnectedWifiSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setConnectedWifiTitle(String title) {
|
|
||||||
mConnectedWifiTitle = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setConnectedWifiSummary(String summary) {
|
|
||||||
mConnectedWifiSummary = summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onWifiStateReceived(Context context, Intent intent) {
|
|
||||||
setMobileNetworkTitle(MOBILE_NETWORK_TITLE);
|
|
||||||
setMobileNetworkSummary(MOBILE_NETWORK_SUMMARY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class WifiReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
|
||||||
mInternetDialog.updateDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user