Revert "[Provider Model] Add WiFi toggle in internet panel"
This reverts commit 04a4060225
.
Reason for revert: Need to split the functions for cherry picking to different branches
Bug: 189912933
Change-Id: I8c30a87c83e23b3df88ce2689d500626e1dd28d2
This commit is contained in:
@@ -20,7 +20,6 @@ package com.android.settings.network;
|
||||
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
import android.app.PendingIntent;
|
||||
@@ -65,6 +64,7 @@ import java.util.stream.Collectors;
|
||||
public class ProviderModelSlice extends WifiSlice {
|
||||
|
||||
private static final String TAG = "ProviderModelSlice";
|
||||
protected static final String ACTION_TITLE_CONNECT_TO_CARRIER = "Connect_To_Carrier";
|
||||
|
||||
private final ProviderModelSliceHelper mHelper;
|
||||
|
||||
@@ -89,32 +89,49 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
// The provider model slice step:
|
||||
// First section: Add the Ethernet item.
|
||||
// Second section: Add the carrier item.
|
||||
// Third section: Add the Wi-Fi toggle item.
|
||||
// Fourth section: Add the connected Wi-Fi item.
|
||||
// Fifth section: Add the Wi-Fi items which are not connected.
|
||||
// Sixth section: Add the See All item.
|
||||
// First section: Add a Wi-Fi item which state is connected.
|
||||
// Second section: Add a carrier item.
|
||||
// Third section: Add the Wi-Fi items which are not connected.
|
||||
// Fourth section: If device has connection problem, this row show the message for user.
|
||||
@InternetUpdater.InternetType int internetType = getInternetType();
|
||||
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
|
||||
if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()
|
||||
&& internetType != InternetUpdater.INTERNET_ETHERNET) {
|
||||
log("Airplane mode is enabled.");
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
int maxListSize = 0;
|
||||
List<WifiSliceItem> wifiList = null;
|
||||
final NetworkProviderWorker worker = getWorker();
|
||||
if (worker != null) {
|
||||
// get Wi-Fi list.
|
||||
wifiList = worker.getResults();
|
||||
maxListSize = worker.getApRowCount();
|
||||
} else {
|
||||
log("network provider worker is null.");
|
||||
}
|
||||
|
||||
// First section: Add the Ethernet item.
|
||||
if (getInternetType() == InternetUpdater.INTERNET_ETHERNET) {
|
||||
final boolean hasCarrier = mHelper.hasCarrier();
|
||||
log("hasCarrier: " + hasCarrier);
|
||||
|
||||
// First section: Add a Ethernet or Wi-Fi item which state is connected.
|
||||
boolean isConnectedWifiAddedTop = false;
|
||||
final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
|
||||
if (internetType == InternetUpdater.INTERNET_ETHERNET) {
|
||||
log("get Ethernet item which is connected");
|
||||
listBuilder.addRow(createEthernetRow());
|
||||
maxListSize--;
|
||||
} else {
|
||||
if (connectedWifiItem != null && internetType == InternetUpdater.INTERNET_WIFI) {
|
||||
log("get Wi-Fi item which is connected to internet");
|
||||
listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
|
||||
isConnectedWifiAddedTop = true;
|
||||
maxListSize--;
|
||||
}
|
||||
}
|
||||
|
||||
// Second section: Add the carrier item.
|
||||
if (!mHelper.isAirplaneModeEnabled()) {
|
||||
final boolean hasCarrier = mHelper.hasCarrier();
|
||||
log("hasCarrier: " + hasCarrier);
|
||||
// Second section: Add a carrier item.
|
||||
if (hasCarrier) {
|
||||
mHelper.updateTelephony();
|
||||
listBuilder.addRow(
|
||||
@@ -122,44 +139,28 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
worker != null ? worker.getNetworkTypeDescription() : ""));
|
||||
maxListSize--;
|
||||
}
|
||||
}
|
||||
|
||||
// Third section: Add the Wi-Fi toggle item.
|
||||
final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
|
||||
listBuilder.addRow(createWifiToggleRow(mContext, isWifiEnabled));
|
||||
maxListSize--;
|
||||
if (!isWifiEnabled) {
|
||||
log("Wi-Fi is disabled");
|
||||
return listBuilder.build();
|
||||
}
|
||||
List<WifiSliceItem> wifiList = (worker != null) ? worker.getResults() : null;
|
||||
if (wifiList == null || wifiList.size() <= 0) {
|
||||
log("Wi-Fi list is empty");
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
// Fourth section: Add the connected Wi-Fi item.
|
||||
final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
|
||||
if (connectedWifiItem != null) {
|
||||
// Third section: Add the connected Wi-Fi item to Wi-Fi list if the Ethernet is connected.
|
||||
if (connectedWifiItem != null && !isConnectedWifiAddedTop) {
|
||||
log("get Wi-Fi item which is connected");
|
||||
listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
|
||||
maxListSize--;
|
||||
}
|
||||
|
||||
// Fifth section: Add the Wi-Fi items which are not connected.
|
||||
// Fourth section: Add the Wi-Fi items which are not connected.
|
||||
if (wifiList != null && wifiList.size() > 0) {
|
||||
log("get Wi-Fi items which are not connected. Wi-Fi items : " + wifiList.size());
|
||||
|
||||
final List<WifiSliceItem> disconnectedWifiList = wifiList.stream()
|
||||
.filter(item -> item.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED)
|
||||
.filter(wifiSliceItem -> wifiSliceItem.getConnectedState()
|
||||
!= WifiEntry.CONNECTED_STATE_CONNECTED)
|
||||
.limit(maxListSize - 1)
|
||||
.collect(Collectors.toList());
|
||||
for (WifiSliceItem item : disconnectedWifiList) {
|
||||
listBuilder.addRow(getWifiSliceItemRow(item));
|
||||
}
|
||||
|
||||
// Sixth section: Add the See All item.
|
||||
log("add See-All");
|
||||
listBuilder.addRow(getSeeAllRow());
|
||||
|
||||
}
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
@@ -268,26 +269,6 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
.setSubtitle(mContext.getText(R.string.to_switch_networks_disconnect_ethernet));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link ListBuilder.RowBuilder} of the Wi-Fi toggle.
|
||||
*/
|
||||
protected ListBuilder.RowBuilder createWifiToggleRow(Context context, boolean isWifiEnabled) {
|
||||
final Intent intent = new Intent(WIFI_SLICE_URI.toString())
|
||||
.setData(WIFI_SLICE_URI)
|
||||
.setClass(context, SliceBroadcastReceiver.class)
|
||||
.putExtra(EXTRA_TOGGLE_STATE, !isWifiEnabled)
|
||||
// The FLAG_RECEIVER_FOREGROUND flag is necessary to avoid the intent delay of
|
||||
// the first sending after the device restarts
|
||||
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
final SliceAction toggleSliceAction = SliceAction.createToggle(pendingIntent,
|
||||
null /* actionTitle */, isWifiEnabled);
|
||||
return new ListBuilder.RowBuilder()
|
||||
.setTitle(context.getString(R.string.wifi_settings))
|
||||
.setPrimaryAction(toggleSliceAction);
|
||||
}
|
||||
|
||||
protected ListBuilder.RowBuilder getSeeAllRow() {
|
||||
final CharSequence title = mContext.getText(R.string.previous_connected_see_all);
|
||||
final IconCompat icon = getSeeAllIcon();
|
||||
@@ -313,6 +294,31 @@ public class ProviderModelSlice extends WifiSlice {
|
||||
return SliceAction.createDeeplink(intent, icon, ListBuilder.ICON_IMAGE, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListBuilder.RowBuilder getWifiSliceItemRow(WifiSliceItem wifiSliceItem) {
|
||||
final CharSequence title = wifiSliceItem.getTitle();
|
||||
final IconCompat levelIcon = getWifiSliceItemLevelIcon(wifiSliceItem);
|
||||
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
||||
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setSubtitle(wifiSliceItem.getSummary())
|
||||
.setContentDescription(wifiSliceItem.getContentDescription());
|
||||
|
||||
final IconCompat endIcon;
|
||||
if (wifiSliceItem.hasInternetAccess()) {
|
||||
rowBuilder.setPrimaryAction(SliceAction.create(getBroadcastIntent(mContext),
|
||||
levelIcon, ListBuilder.ICON_IMAGE, ACTION_TITLE_CONNECT_TO_CARRIER));
|
||||
endIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_close);
|
||||
} else {
|
||||
rowBuilder.setPrimaryAction(getWifiEntryAction(wifiSliceItem, levelIcon, title));
|
||||
endIcon = getEndIcon(wifiSliceItem);
|
||||
}
|
||||
if (endIcon != null) {
|
||||
rowBuilder.addEndItem(endIcon, ListBuilder.ICON_IMAGE);
|
||||
}
|
||||
return rowBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IconCompat getWifiSliceItemLevelIcon(WifiSliceItem wifiSliceItem) {
|
||||
if (wifiSliceItem.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED
|
||||
|
@@ -54,7 +54,7 @@ public class NetworkProviderWorker extends WifiScanWorker implements
|
||||
DataConnectivityListener.Client, InternetUpdater.InternetChangeListener,
|
||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
||||
private static final String TAG = "NetworkProviderWorker";
|
||||
private static final int PROVIDER_MODEL_DEFAULT_EXPANDED_ROW_COUNT = 6;
|
||||
private static final int PROVIDER_MODEL_DEFAULT_EXPANDED_ROW_COUNT = 5;
|
||||
private DataContentObserver mMobileDataObserver;
|
||||
private SignalStrengthListener mSignalStrengthListener;
|
||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||
|
@@ -38,6 +38,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
@@ -83,13 +84,12 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
}
|
||||
|
||||
if (TextUtils.equals(intent.getAction(), WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
|
||||
updateProgressBar();
|
||||
showProgressBar();
|
||||
updatePanelTitle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.equals(intent.getAction(), WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
updateProgressBar();
|
||||
updatePanelTitle();
|
||||
}
|
||||
}
|
||||
@@ -110,40 +110,13 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
private int mDefaultDataSubid = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
// Wi-Fi scanning progress bar
|
||||
protected HandlerInjector mHandlerInjector;
|
||||
protected boolean mIsProgressBarVisible;
|
||||
protected boolean mIsScanningSubTitleShownOnce;
|
||||
protected Runnable mHideProgressBarRunnable = () -> {
|
||||
protected final Runnable mHideProgressBarRunnable = () -> {
|
||||
setProgressBarVisible(false);
|
||||
};
|
||||
protected Runnable mHideScanningSubTitleRunnable = () -> {
|
||||
mIsScanningSubTitleShownOnce = true;
|
||||
updatePanelTitle();
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for testing compatibility.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static class HandlerInjector {
|
||||
protected final Handler mHandler;
|
||||
|
||||
HandlerInjector(Context context) {
|
||||
mHandler = context.getMainThreadHandler();
|
||||
}
|
||||
|
||||
public void postDelay(Runnable runnable) {
|
||||
mHandler.postDelayed(runnable, 2000 /* delay millis */);
|
||||
}
|
||||
|
||||
public void removeCallbacks(Runnable runnable) {
|
||||
mHandler.removeCallbacks(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private InternetConnectivityPanel(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
mHandlerInjector = new HandlerInjector(context);
|
||||
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
|
||||
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
|
||||
|
||||
@@ -177,7 +150,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mTelephonyManager.registerTelephonyCallback(
|
||||
new HandlerExecutor(new Handler(Looper.getMainLooper())), mTelephonyCallback);
|
||||
mContext.registerReceiver(mWifiStateReceiver, mWifiStateFilter);
|
||||
updateProgressBar();
|
||||
showProgressBar();
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -192,8 +165,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mConnectivityListener.stop();
|
||||
mTelephonyManager.unregisterTelephonyCallback(mTelephonyCallback);
|
||||
mContext.unregisterReceiver(mWifiStateReceiver);
|
||||
mHandlerInjector.removeCallbacks(mHideProgressBarRunnable);
|
||||
mHandlerInjector.removeCallbacks(mHideScanningSubTitleRunnable);
|
||||
mContext.getMainThreadHandler().removeCallbacks(mHideProgressBarRunnable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,6 +209,23 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomizedButtonUsed() {
|
||||
return mIsProviderModelEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCustomizedButtonTitle() {
|
||||
return mContext.getText(
|
||||
mInternetUpdater.isWifiEnabled() ? R.string.turn_off_wifi : R.string.turn_on_wifi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickCustomizedButton(FragmentActivity panelActivity) {
|
||||
// Don't finish the panel activity
|
||||
mWifiManager.setWifiEnabled(!mInternetUpdater.isWifiEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProgressBarVisible() {
|
||||
return mIsProgressBarVisible;
|
||||
@@ -257,7 +246,6 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
*/
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
||||
log("onAirplaneModeChanged: isAirplaneModeOn:" + isAirplaneModeOn);
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -266,7 +254,6 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
*/
|
||||
@Override
|
||||
public void onWifiEnabledChanged(boolean enabled) {
|
||||
log("onWifiEnabledChanged: enabled:" + enabled);
|
||||
updatePanelTitle();
|
||||
}
|
||||
|
||||
@@ -318,6 +305,13 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
return;
|
||||
}
|
||||
|
||||
if (mIsProgressBarVisible) {
|
||||
// When the Wi-Fi scan result callback is received
|
||||
// Sub-Title: Searching for networks...
|
||||
mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mInternetUpdater.isAirplaneModeOn()) {
|
||||
return;
|
||||
}
|
||||
@@ -325,18 +319,11 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
final List<ScanResult> wifiList = mWifiManager.getScanResults();
|
||||
if (wifiList != null && wifiList.size() != 0) {
|
||||
// When the Wi-Fi scan result is not empty
|
||||
// Sub-Title: Tap a network to connect
|
||||
// Sub-Title: Select the network you want to use for data
|
||||
mSubtitle = SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mIsScanningSubTitleShownOnce && mIsProgressBarVisible) {
|
||||
// When the Wi-Fi scan result callback is received
|
||||
// Sub-Title: Searching for networks...
|
||||
mSubtitle = SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS;
|
||||
return;
|
||||
}
|
||||
|
||||
// Sub-Title:
|
||||
// show non_carrier_network_unavailable
|
||||
// - while Wi-Fi on + no Wi-Fi item
|
||||
@@ -366,7 +353,7 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE;
|
||||
}
|
||||
|
||||
protected void updateProgressBar() {
|
||||
protected void showProgressBar() {
|
||||
if (mWifiManager == null || !mInternetUpdater.isWifiEnabled()) {
|
||||
setProgressBarVisible(false);
|
||||
return;
|
||||
@@ -375,9 +362,8 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
|
||||
setProgressBarVisible(true);
|
||||
List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
|
||||
if (wifiScanResults != null && wifiScanResults.size() > 0) {
|
||||
mHandlerInjector.postDelay(mHideProgressBarRunnable);
|
||||
} else if (!mIsScanningSubTitleShownOnce) {
|
||||
mHandlerInjector.postDelay(mHideScanningSubTitleRunnable);
|
||||
mContext.getMainThreadHandler().postDelayed(mHideProgressBarRunnable,
|
||||
2000 /* delay millis */);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static com.android.settings.network.ProviderModelSlice.ACTION_TITLE_CONNECT_TO_CARRIER;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -40,8 +42,6 @@ import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceItem;
|
||||
import androidx.slice.SliceMetadata;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
@@ -100,6 +100,8 @@ public class ProviderModelSliceTest {
|
||||
ListBuilder.RowBuilder mMockCarrierRowBuild;
|
||||
@Mock
|
||||
WifiPickerTracker mWifiPickerTracker;
|
||||
@Mock
|
||||
WifiSliceItem mWifiSliceItem;
|
||||
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@@ -120,7 +122,7 @@ public class ProviderModelSliceTest {
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
@@ -180,24 +182,7 @@ public class ProviderModelSliceTest {
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_airplaneModeIsOn_oneWifiToggle() {
|
||||
mWifiList.clear();
|
||||
mMockNetworkProviderWorker.updateSelfResults(null);
|
||||
mockHelperCondition(true, false, false, null);
|
||||
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
verify(mListBuilder, times(1)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
final SliceItem sliceTitle =
|
||||
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
|
||||
assertThat(sliceTitle.getText()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "wifi_settings"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_haveTwoWifiAndOneCarrier_getFiveRow() {
|
||||
public void getSlice_haveTwoWifiAndOneCarrier_getCarrierAndTwoWiFiAndSeeAll() {
|
||||
mWifiList.clear();
|
||||
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
|
||||
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
|
||||
@@ -212,13 +197,13 @@ public class ProviderModelSliceTest {
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
|
||||
verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_haveOneConnectedWifiAndTwoDisconnectedWifiAndNoCarrier_getFiveRow() {
|
||||
public void getSlice_haveOneConnectedWifiAndTwoDisconnectedWifiAndNoCarrier_getFourRow() {
|
||||
mWifiList.clear();
|
||||
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
|
||||
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
|
||||
@@ -235,13 +220,13 @@ public class ProviderModelSliceTest {
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_haveTwoDisconnectedWifiAndNoCarrier_getFourRow() {
|
||||
public void getSlice_haveTwoDisconnectedWifiAndNoCarrier_getThreeRow() {
|
||||
mWifiList.clear();
|
||||
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
|
||||
WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi1_key", true);
|
||||
@@ -255,13 +240,13 @@ public class ProviderModelSliceTest {
|
||||
final Slice slice = mMockProviderModelSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
verify(mListBuilder, times(4)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
verify(mListBuilder, times(3)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_haveEthernetAndCarrierAndTwoDisconnectedWifi_getSixRow() {
|
||||
public void getSlice_haveEthernetAndCarrierAndTwoDisconnectedWifi_getFiveRow() {
|
||||
mWifiList.clear();
|
||||
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
|
||||
WifiEntry.CONNECTED_STATE_DISCONNECTED, "wifi1_key", true);
|
||||
@@ -279,13 +264,13 @@ public class ProviderModelSliceTest {
|
||||
assertThat(slice).isNotNull();
|
||||
assertThat(mMockProviderModelSlice.hasCreateEthernetRow()).isTrue();
|
||||
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
|
||||
verify(mListBuilder, times(6)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getSixRow() {
|
||||
public void getSlice_haveEthernetAndCarrierAndConnectedWifiAndDisconnectedWifi_getFiveRow() {
|
||||
mWifiList.clear();
|
||||
mockWifiItemCondition(mMockWifiSliceItem1, "wifi1", "wifi1",
|
||||
WifiEntry.CONNECTED_STATE_CONNECTED, "wifi1_key", true);
|
||||
@@ -303,7 +288,7 @@ public class ProviderModelSliceTest {
|
||||
assertThat(slice).isNotNull();
|
||||
assertThat(mMockProviderModelSlice.hasCreateEthernetRow()).isTrue();
|
||||
verify(mListBuilder, times(1)).addRow(mMockCarrierRowBuild);
|
||||
verify(mListBuilder, times(6)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
verify(mListBuilder, times(5)).addRow(any(ListBuilder.RowBuilder.class));
|
||||
assertThat(mMockProviderModelSlice.hasSeeAllRow()).isTrue();
|
||||
}
|
||||
|
||||
@@ -395,11 +380,6 @@ public class ProviderModelSliceTest {
|
||||
return super.getSeeAllRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListBuilder.RowBuilder getWifiSliceItemRow(WifiSliceItem wifiSliceItem) {
|
||||
return super.getWifiSliceItemRow(wifiSliceItem);
|
||||
}
|
||||
|
||||
public boolean hasCreateEthernetRow() {
|
||||
return mHasCreateEthernetRow;
|
||||
}
|
||||
@@ -440,4 +420,29 @@ public class ProviderModelSliceTest {
|
||||
|
||||
verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSliceItemRow_wifiNoInternetAccess_actionConnectToWifiSsid() {
|
||||
when(mWifiSliceItem.getKey()).thenReturn("wifi_key");
|
||||
when(mWifiSliceItem.getTitle()).thenReturn("wifi_ssid");
|
||||
when(mWifiSliceItem.hasInternetAccess()).thenReturn(false);
|
||||
|
||||
ListBuilder.RowBuilder rowBuilder =
|
||||
mMockProviderModelSlice.getWifiSliceItemRow(mWifiSliceItem);
|
||||
|
||||
assertThat(rowBuilder.getPrimaryAction().getTitle())
|
||||
.isEqualTo("wifi_ssid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiSliceItemRow_wifiHasInternetAccess_actionConnectToCarrier() {
|
||||
when(mWifiSliceItem.getTitle()).thenReturn("wifi_ssid");
|
||||
when(mWifiSliceItem.hasInternetAccess()).thenReturn(true);
|
||||
|
||||
ListBuilder.RowBuilder rowBuilder =
|
||||
mMockProviderModelSlice.getWifiSliceItemRow(mWifiSliceItem);
|
||||
|
||||
assertThat(rowBuilder.getPrimaryAction().getTitle())
|
||||
.isEqualTo(ACTION_TITLE_CONNECT_TO_CARRIER);
|
||||
}
|
||||
}
|
||||
|
@@ -18,9 +18,12 @@ package com.android.settings.panel;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -29,7 +32,9 @@ import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
@@ -77,6 +82,8 @@ public class InternetConnectivityPanelTest {
|
||||
@Rule
|
||||
public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@Mock
|
||||
Handler mMainThreadHandler;
|
||||
@Mock
|
||||
PanelContentCallback mPanelContentCallback;
|
||||
@Mock
|
||||
InternetUpdater mInternetUpdater;
|
||||
@@ -84,34 +91,17 @@ public class InternetConnectivityPanelTest {
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private ProviderModelSliceHelper mProviderModelSliceHelper;
|
||||
@Mock
|
||||
private FragmentActivity mPanelActivity;
|
||||
|
||||
private Context mContext;
|
||||
private FakeHandlerInjector mFakeHandlerInjector;
|
||||
private InternetConnectivityPanel mPanel;
|
||||
|
||||
private class FakeHandlerInjector extends InternetConnectivityPanel.HandlerInjector {
|
||||
|
||||
private Runnable mRunnable;
|
||||
|
||||
FakeHandlerInjector(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDelay(Runnable runnable) {
|
||||
mRunnable = runnable;
|
||||
}
|
||||
|
||||
public Runnable getRunnable() {
|
||||
return mRunnable;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mFakeHandlerInjector = new FakeHandlerInjector(mContext);
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getMainThreadHandler()).thenReturn(mMainThreadHandler);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
mPanel = InternetConnectivityPanel.create(mContext);
|
||||
@@ -119,7 +109,6 @@ public class InternetConnectivityPanelTest {
|
||||
mPanel.mIsProviderModelEnabled = true;
|
||||
mPanel.mInternetUpdater = mInternetUpdater;
|
||||
mPanel.mProviderModelSliceHelper = mProviderModelSliceHelper;
|
||||
mPanel.mHandlerInjector = mFakeHandlerInjector;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,6 +203,20 @@ public class InternetConnectivityPanelTest {
|
||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCustomizedButtonTitle_wifiOff_turnOnWifi() {
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_ON_WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCustomizedButtonTitle_wifiOn_turnOffWifi() {
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_OFF_WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlices_providerModelDisabled_containsNecessarySlices() {
|
||||
mPanel.mIsProviderModelEnabled = false;
|
||||
@@ -237,6 +240,31 @@ public class InternetConnectivityPanelTest {
|
||||
assertThat(mPanel.getSeeMoreIntent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCustomizedButton_wifiOn_setWifiOff() {
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCustomizedButton_wifiOff_setWifiOn() {
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCustomizedButton_shouldNotFinishActivity() {
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mPanelActivity, never()).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePanelTitle_onHeaderChanged() {
|
||||
clearInvocations(mPanelContentCallback);
|
||||
@@ -267,41 +295,36 @@ public class InternetConnectivityPanelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateProgressBar_wifiDisabled_hideProgress() {
|
||||
public void showProgressBar_wifiDisabled_hideProgress() {
|
||||
mPanel.mIsProgressBarVisible = true;
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.updateProgressBar();
|
||||
mPanel.showProgressBar();
|
||||
|
||||
assertThat(mPanel.isProgressBarVisible()).isFalse();
|
||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateProgressBar_noWifiScanResults_showProgressForever() {
|
||||
mPanel.mIsScanningSubTitleShownOnce = false;
|
||||
public void showProgressBar_noWifiScanResults_showProgressForever() {
|
||||
mPanel.mIsProgressBarVisible = false;
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
List<ScanResult> noWifiScanResults = new ArrayList<>();
|
||||
doReturn(noWifiScanResults).when(mWifiManager).getScanResults();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.updateProgressBar();
|
||||
mPanel.showProgressBar();
|
||||
|
||||
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
||||
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||
verify(mPanelContentCallback).onHeaderChanged();
|
||||
|
||||
assertThat(mFakeHandlerInjector.getRunnable())
|
||||
.isEqualTo(mPanel.mHideScanningSubTitleRunnable);
|
||||
mFakeHandlerInjector.getRunnable().run();
|
||||
assertThat(mPanel.mIsScanningSubTitleShownOnce).isTrue();
|
||||
assertThat(mPanel.mIsProgressBarVisible).isTrue();
|
||||
verify(mMainThreadHandler, never())
|
||||
.postDelayed(any() /* mHideProgressBarRunnable */, anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateProgressBar_hasWifiScanResults_showProgressDelayedHide() {
|
||||
public void showProgressBar_hasWifiScanResults_showProgressDelayedHide() {
|
||||
mPanel.mIsProgressBarVisible = false;
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
List<ScanResult> hasWifiScanResults = mock(ArrayList.class);
|
||||
@@ -309,15 +332,11 @@ public class InternetConnectivityPanelTest {
|
||||
doReturn(hasWifiScanResults).when(mWifiManager).getScanResults();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.updateProgressBar();
|
||||
mPanel.showProgressBar();
|
||||
|
||||
assertThat(mPanel.isProgressBarVisible()).isTrue();
|
||||
verify(mPanelContentCallback).onProgressBarVisibleChanged();
|
||||
|
||||
assertThat(mFakeHandlerInjector.getRunnable())
|
||||
.isEqualTo(mPanel.mHideProgressBarRunnable);
|
||||
mFakeHandlerInjector.getRunnable().run();
|
||||
assertThat(mPanel.mIsProgressBarVisible).isFalse();
|
||||
verify(mMainThreadHandler).postDelayed(any() /* mHideProgressBarRunnable */, anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user