diff options
13 files changed, 461 insertions, 365 deletions
diff --git a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml index 5b58fe8c0b58..b841419c1c75 100644 --- a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml +++ b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml @@ -30,7 +30,7 @@ style="@style/Widget.SliceView.Panel" android:gravity="center_vertical|center_horizontal" android:layout_marginTop="24dp" - android:layout_marginBottom="16dp" + android:layout_marginBottom="@dimen/internet_dialog_network_layout_margin" android:orientation="vertical"> <TextView @@ -57,7 +57,7 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" + android:layout_marginBottom="@dimen/internet_dialog_network_layout_margin" android:orientation="vertical"> <View @@ -101,8 +101,8 @@ android:background="?android:attr/selectableItemBackground" android:layout_gravity="center_vertical|start" android:orientation="horizontal" - android:layout_marginEnd="@dimen/settingslib_switchbar_margin" - android:layout_marginStart="@dimen/settingslib_switchbar_margin" + android:layout_marginEnd="@dimen/internet_dialog_network_layout_margin" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" android:paddingStart="22dp" android:paddingEnd="22dp"> @@ -130,24 +130,24 @@ <TextView android:id="@+id/mobile_title" android:textDirection="locale" - android:layout_marginStart="16dp" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" + android:layout_marginEnd="7dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|start" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorPrimary" android:textSize="16sp" android:fontFamily="google-sans"/> <TextView android:id="@+id/mobile_summary" android:textDirection="locale" - android:layout_marginStart="16dp" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" + android:layout_marginEnd="34dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|start" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorTertiary" android:textSize="14sp" android:fontFamily="google-sans"/> @@ -179,8 +179,8 @@ android:background="?android:attr/selectableItemBackground" android:gravity="center" android:orientation="horizontal" - android:layout_marginEnd="@dimen/settingslib_switchbar_margin" - android:layout_marginStart="@dimen/settingslib_switchbar_margin" + android:layout_marginEnd="@dimen/internet_dialog_network_layout_margin" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" android:paddingStart="22dp" android:paddingEnd="22dp"> @@ -191,6 +191,7 @@ android:layout_width="wrap_content" android:layout_height="match_parent"> <TextView + android:id="@+id/wifi_toggle_title" android:text="@string/turn_on_wifi" android:textDirection="locale" android:layout_width="wrap_content" @@ -229,10 +230,10 @@ android:visibility="gone" android:background="?android:attr/selectableItemBackground" android:orientation="horizontal" - android:layout_marginEnd="@dimen/settingslib_switchbar_margin" - android:layout_marginStart="@dimen/settingslib_switchbar_margin" - android:paddingStart="22dp" - android:paddingEnd="22dp"> + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" + android:layout_marginEnd="@dimen/internet_dialog_network_layout_margin" + android:paddingStart="20dp" + android:paddingEnd="24dp"> <FrameLayout android:layout_width="24dp" @@ -247,12 +248,13 @@ </FrameLayout> <LinearLayout - android:layout_weight="3" android:id="@+id/wifi_connected_list" android:orientation="vertical" android:clickable="false" android:layout_width="wrap_content" android:layout_height="72dp" + android:layout_marginEnd="30dp" + android:layout_weight="1" android:gravity="start|center_vertical"> <TextView android:id="@+id/wifi_connected_title" @@ -260,9 +262,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|start" - android:layout_marginStart="16dp" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorPrimary" android:textSize="14sp" android:fontFamily="google-sans"/> @@ -272,9 +273,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|start" - android:layout_marginStart="16dp" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorTertiary" android:textSize="14sp" android:fontFamily="google-sans"/> @@ -283,14 +283,14 @@ <FrameLayout android:layout_width="24dp" android:layout_height="match_parent" - android:layout_marginEnd="5dp" android:clickable="false" + android:layout_gravity="end|center_vertical" android:gravity="center"> <ImageView android:id="@+id/wifi_settings_icon" android:src="@drawable/ic_settings_24dp" android:layout_width="24dp" - android:layout_gravity="center" + android:layout_gravity="end|center_vertical" android:layout_height="wrap_content"/> </FrameLayout> @@ -323,7 +323,7 @@ android:layout_height="24dp" android:clickable="false" android:layout_gravity="center_vertical|start" - android:layout_marginStart="16dp"> + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin"> <ImageView android:id="@+id/arrow_forward" android:src="@drawable/ic_arrow_forward" @@ -337,7 +337,7 @@ android:clickable="false" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginStart="16dp"> + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin"> <TextView android:text="@string/see_all_networks" android:textDirection="locale" diff --git a/packages/SystemUI/res/layout/internet_list_item.xml b/packages/SystemUI/res/layout/internet_list_item.xml index 19b1ef90bdfa..b52933da818d 100644 --- a/packages/SystemUI/res/layout/internet_list_item.xml +++ b/packages/SystemUI/res/layout/internet_list_item.xml @@ -31,15 +31,14 @@ android:focusable="true" android:background="?android:attr/selectableItemBackground" android:orientation="horizontal" - android:paddingStart="22dp" - android:paddingEnd="22dp"> - + android:paddingStart="20dp" + android:paddingEnd="40dp"> <FrameLayout android:layout_width="24dp" android:layout_height="24dp" android:clickable="false" android:layout_gravity="center_vertical|start" - android:layout_marginStart="16dp"> + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin"> <ImageView android:id="@+id/wifi_icon" android:layout_width="wrap_content" @@ -48,52 +47,47 @@ </FrameLayout> <LinearLayout - android:layout_weight="3" android:id="@+id/wifi_network_layout" android:orientation="vertical" android:clickable="false" android:layout_width="wrap_content" - android:layout_height="72dp"> + android:layout_height="72dp" + android:layout_weight="1" + android:gravity="start|center_vertical" + android:layout_marginStart="@dimen/internet_dialog_network_layout_margin"> <TextView android:id="@+id/wifi_title" android:textDirection="locale" - android:layout_weight="1" android:layout_width="wrap_content" - android:layout_height="0dp" - android:layout_gravity="center_vertical|start" + android:layout_height="20dp" android:gravity="start|center_vertical" - android:layout_marginStart="16dp" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorPrimary" android:textSize="14sp" - android:fontFamily="google-sans"/> + android:fontFamily="google-sans" + android:layout_marginEnd="18dp"/> <TextView android:id="@+id/wifi_summary" android:textDirection="locale" - android:layout_weight="1" android:layout_width="wrap_content" - android:layout_height="0dp" - android:layout_gravity="center_vertical|start" + android:layout_height="20dp" android:gravity="start|center_vertical" - android:layout_marginStart="16dp" android:ellipsize="end" - android:maxLines="1" android:textColor="?android:attr/textColorSecondary" android:textSize="14sp" - android:fontFamily="google-sans"/> + android:fontFamily="google-sans" + android:layout_marginEnd="18dp"/> </LinearLayout> <FrameLayout android:layout_width="24dp" android:layout_height="match_parent" - android:layout_marginEnd="@dimen/settingslib_switchbar_padding_right" android:clickable="false" - android:gravity="center"> + android:layout_gravity="end|center_vertical"> <ImageView android:id="@+id/wifi_locked_icon" + android:layout_gravity="end|center_vertical" android:layout_width="wrap_content" - android:layout_gravity="center" android:layout_height="wrap_content"/> </FrameLayout> diff --git a/packages/SystemUI/res/values-sw600dp/dimens.xml b/packages/SystemUI/res/values-sw600dp/dimens.xml index da80b85b38bf..0a34dfd71c7e 100644 --- a/packages/SystemUI/res/values-sw600dp/dimens.xml +++ b/packages/SystemUI/res/values-sw600dp/dimens.xml @@ -95,4 +95,7 @@ <dimen name="controls_top_margin">24dp</dimen> <dimen name="global_actions_grid_item_layout_height">80dp</dimen> + + <!-- Internet panel related dimensions --> + <dimen name="internet_dialog_list_max_width">624dp</dimen> </resources> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 25545480e069..ac7ad5d195a4 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1594,15 +1594,16 @@ <!-- Internet panel related dimensions --> <dimen name="internet_dialog_list_margin">12dp</dimen> <dimen name="internet_dialog_list_max_height">646dp</dimen> - <dimen name="internet_dialog_list_max_width">412dp</dimen> + <dimen name="internet_dialog_list_max_width">@dimen/match_parent</dimen> <!-- Signal icon in internet dialog --> <dimen name="signal_strength_icon_size">24dp</dimen> <!-- Internet dialog related dimensions --> <dimen name="internet_dialog_corner_radius">24dp</dimen> - - <!-- Size of internet dialog --> + <!-- End margin of network layout --> + <dimen name="internet_dialog_network_layout_margin">16dp</dimen> + <!-- Size of switch bar in internet dialog --> <dimen name="settingslib_switchbar_margin">16dp</dimen> <!-- Minimum width of switch --> <dimen name="settingslib_min_switch_width">52dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java index d0a4b62b8a1b..cc9e7485dcff 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/InternetTile.java @@ -122,8 +122,9 @@ public class InternetTile extends QSTileImpl<SignalState> { @Override protected void handleClick(@Nullable View view) { - boolean canConfigMobileData = mAccessPointController.canConfigMobileData(); - mHandler.post(() -> mInternetDialogFactory.create(true, canConfigMobileData)); + mHandler.post(() -> mInternetDialogFactory.create(true, + mAccessPointController.canConfigMobileData(), + mAccessPointController.canConfigWifi())); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java index 91c81bc506c2..4e897d9a8667 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java @@ -24,7 +24,6 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.text.Html; import android.text.TextUtils; -import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -34,6 +33,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import com.android.settingslib.Utils; @@ -43,7 +43,6 @@ import com.android.wifitrackerlib.WifiEntry; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; /** * Adapter for showing Wi-Fi networks. @@ -54,9 +53,10 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern private static final String ACTION_WIFI_DIALOG = "com.android.settings.WIFI_DIALOG"; private static final String EXTRA_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key"; private static final String EXTRA_CONNECT_FOR_CALLER = "connect_for_caller"; - private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private final InternetDialogController mInternetDialogController; + private List<WifiEntry> mWifiEntries; + private int mWifiEntriesCount; protected View mHolderView; protected Context mContext; @@ -76,54 +76,31 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern @Override public void onBindViewHolder(@NonNull InternetViewHolder viewHolder, int position) { - List<WifiEntry> wifiList = getWifiEntryList(); - if (wifiList != null && wifiList.size() != 0) { - int count = getItemCount(); - if (wifiList.size() > count) { - wifiList = getWifiEntryList().subList(0, count - 1); - } - - if (position < wifiList.size()) { - viewHolder.onBind(wifiList.get(position)); - } - } else if (DEBUG) { - Log.d(TAG, "onBindViewHolder, Wi-Fi entry list = null"); + if (mWifiEntries == null || position >= mWifiEntriesCount) { + return; } + viewHolder.onBind(mWifiEntries.get(position)); } - private List<WifiEntry> getWifiEntryList() { - if (mInternetDialogController.getWifiEntryList() == null) { - return null; - } - - return mInternetDialogController.getWifiEntryList().stream() - .filter(wifiEntry -> (!wifiEntry.isDefaultNetwork() - || !wifiEntry.hasInternetAccess())) - .limit(getItemCount()) - .collect(Collectors.toList()); + /** + * Updates the Wi-Fi networks. + * + * @param wifiEntries the updated Wi-Fi entries. + * @param wifiEntriesCount the total number of Wi-Fi entries. + */ + public void setWifiEntries(@Nullable List<WifiEntry> wifiEntries, int wifiEntriesCount) { + mWifiEntries = wifiEntries; + mWifiEntriesCount = wifiEntriesCount; } /** - * The total number of networks (mobile network and entries of Wi-Fi) should be four in - * {@link InternetDialog}. - * - * Airplane mode is ON (mobile network is gone): - * Return four Wi-Fi's entries if no internet Wi-Fi. - * Return three Wi-Fi's entries if one internet Wi-Fi. - * Airplane mode is OFF (mobile network is visible): - * Return three Wi-Fi's entries if no internet Wi-Fi. - * Return two Wi-Fi's entries if one internet Wi-Fi. + * Gets the total number of Wi-Fi networks. * - * @return The total number of networks. + * @return The total number of Wi-Fi entries. */ @Override public int getItemCount() { - final boolean hasInternetWifi = mInternetDialogController.getInternetWifiEntry() != null; - if (mInternetDialogController.isAirplaneModeEnabled()) { - return hasInternetWifi ? 3 : 4; - } else { - return hasInternetWifi ? 2 : 3; - } + return mWifiEntriesCount; } /** @@ -198,18 +175,18 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern mWifiNetworkLayout.setVisibility(View.VISIBLE); mWifiTitleText.setText(title); if (TextUtils.isEmpty(summary)) { - mWifiTitleText.setGravity(Gravity.CENTER); mWifiSummaryText.setVisibility(View.GONE); return; } else { - mWifiTitleText.setGravity(Gravity.BOTTOM); - mWifiSummaryText.setGravity(Gravity.TOP); mWifiSummaryText.setVisibility(View.VISIBLE); } mWifiSummaryText.setText(summary); } Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable { + if (wifiEntry.getLevel() == WifiEntry.WIFI_LEVEL_UNREACHABLE) { + return null; + } final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(), wifiEntry.getLevel()); if (drawable == null) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java index e1e0ba7a8d03..4d0cbd15a788 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java @@ -21,13 +21,11 @@ import static com.android.systemui.Prefs.Key.QS_HAS_TURNED_OFF_MOBILE_DATA; import android.app.AlertDialog; import android.content.Context; -import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Network; import android.net.NetworkCapabilities; -import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Handler; @@ -51,11 +49,12 @@ import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; -import android.widget.Space; import android.widget.Switch; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.annotation.WorkerThread; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -92,7 +91,7 @@ public class InternetDialog extends SystemUIDialog implements @VisibleForTesting protected View mDialogView; @VisibleForTesting - protected WifiEntry mConnectedWifiEntry; + protected boolean mCanConfigWifi; private InternetDialogFactory mInternetDialogFactory; private SubscriptionManager mSubscriptionManager; @@ -105,12 +104,14 @@ public class InternetDialog extends SystemUIDialog implements private TextView mInternetDialogSubTitle; private View mDivider; private ProgressBar mProgressBar; + private LinearLayout mInternetDialogLayout; private LinearLayout mInternetListLayout; private LinearLayout mConnectedWifListLayout; private LinearLayout mConnectedWifList; private LinearLayout mMobileNetworkLayout; private LinearLayout mMobileNetworkList; private LinearLayout mTurnWifiOnLayout; + private TextView mWifiToggleTitleText; private LinearLayout mSeeAllLayout; private RecyclerView mWifiRecyclerView; private ImageView mConnectedWifiIcon; @@ -125,10 +126,14 @@ public class InternetDialog extends SystemUIDialog implements private Button mDoneButton; private Drawable mBackgroundOn; private int mListMaxHeight; - private int mListMaxWidth; + private int mLayoutWidth; private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; private boolean mCanConfigMobileData; + // Wi-Fi entries + protected WifiEntry mConnectedWifiEntry; + protected int mWifiEntriesCount; + // Wi-Fi scanning progress bar protected boolean mIsProgressBarVisible; protected boolean mIsSearchingHidden; @@ -142,16 +147,17 @@ public class InternetDialog extends SystemUIDialog implements private final ViewTreeObserver.OnGlobalLayoutListener mInternetListLayoutListener = () -> { // Set max height for list - if (mInternetListLayout.getHeight() > mListMaxHeight) { - ViewGroup.LayoutParams params = mInternetListLayout.getLayoutParams(); + if (mInternetDialogLayout.getHeight() > mListMaxHeight) { + ViewGroup.LayoutParams params = mInternetDialogLayout.getLayoutParams(); params.height = mListMaxHeight; - mInternetListLayout.setLayoutParams(params); + mInternetDialogLayout.setLayoutParams(params); } }; public InternetDialog(Context context, InternetDialogFactory internetDialogFactory, InternetDialogController internetDialogController, boolean canConfigMobileData, - boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) { + boolean canConfigWifi, boolean aboveStatusBar, UiEventLogger uiEventLogger, + @Main Handler handler) { super(context, R.style.Theme_SystemUI_Dialog_Internet); if (DEBUG) { Log.d(TAG, "Init InternetDialog"); @@ -165,6 +171,7 @@ public class InternetDialog extends SystemUIDialog implements mTelephonyManager = mInternetDialogController.getTelephonyManager(); mWifiManager = mInternetDialogController.getWifiManager(); mCanConfigMobileData = canConfigMobileData; + mCanConfigWifi = canConfigWifi; mLayoutManager = new LinearLayoutManager(mContext) { @Override @@ -174,7 +181,7 @@ public class InternetDialog extends SystemUIDialog implements }; mListMaxHeight = context.getResources().getDimensionPixelSize( R.dimen.internet_dialog_list_max_height); - mListMaxWidth = context.getResources().getDimensionPixelSize( + mLayoutWidth = context.getResources().getDimensionPixelSize( R.dimen.internet_dialog_list_max_width); mUiEventLogger = uiEventLogger; mAdapter = new InternetAdapter(mInternetDialogController); @@ -202,11 +209,14 @@ public class InternetDialog extends SystemUIDialog implements layoutParams.setFitInsetsIgnoringVisibility(true); window.setAttributes(layoutParams); window.setContentView(mDialogView); - window.setLayout(mListMaxWidth, ViewGroup.LayoutParams.WRAP_CONTENT); + //Only fix the width for large screen or tablet. + window.setLayout(mContext.getResources().getDimensionPixelSize( + R.dimen.internet_dialog_list_max_width), ViewGroup.LayoutParams.WRAP_CONTENT); window.setWindowAnimations(R.style.Animation_InternetDialog); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.addFlags(FLAG_LAYOUT_NO_LIMITS); + mInternetDialogLayout = mDialogView.requireViewById(R.id.internet_connectivity_dialog); mInternetDialogTitle = mDialogView.requireViewById(R.id.internet_dialog_title); mInternetDialogSubTitle = mDialogView.requireViewById(R.id.internet_dialog_subtitle); mDivider = mDialogView.requireViewById(R.id.divider); @@ -215,6 +225,7 @@ public class InternetDialog extends SystemUIDialog implements mMobileNetworkLayout = mDialogView.requireViewById(R.id.mobile_network_layout); mMobileNetworkList = mDialogView.requireViewById(R.id.mobile_network_list); mTurnWifiOnLayout = mDialogView.requireViewById(R.id.turn_on_wifi_layout); + mWifiToggleTitleText = mDialogView.requireViewById(R.id.wifi_toggle_title); mConnectedWifListLayout = mDialogView.requireViewById(R.id.wifi_connected_layout); mConnectedWifList = mDialogView.requireViewById(R.id.wifi_connected_list); mConnectedWifiIcon = mDialogView.requireViewById(R.id.wifi_connected_icon); @@ -230,7 +241,7 @@ public class InternetDialog extends SystemUIDialog implements mMobileDataToggle = mDialogView.requireViewById(R.id.mobile_toggle); mWiFiToggle = mDialogView.requireViewById(R.id.wifi_toggle); mBackgroundOn = mContext.getDrawable(R.drawable.settingslib_switch_bar_bg_on); - mInternetListLayout.getViewTreeObserver().addOnGlobalLayoutListener( + mInternetDialogLayout.getViewTreeObserver().addOnGlobalLayoutListener( mInternetListLayoutListener); mInternetDialogTitle.setText(getDialogTitleText()); mInternetDialogTitle.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); @@ -247,7 +258,19 @@ public class InternetDialog extends SystemUIDialog implements if (DEBUG) { Log.d(TAG, "onStart"); } - mInternetDialogController.onStart(this); + mInternetDialogController.onStart(this, mCanConfigWifi); + if (!mCanConfigWifi) { + hideWifiViews(); + } + } + + @VisibleForTesting + void hideWifiViews() { + setProgressBarVisible(false); + mTurnWifiOnLayout.setVisibility(View.GONE); + mConnectedWifListLayout.setVisibility(View.GONE); + mWifiRecyclerView.setVisibility(View.GONE); + mSeeAllLayout.setVisibility(View.GONE); } @Override @@ -286,23 +309,22 @@ public class InternetDialog extends SystemUIDialog implements } else { mInternetDialogSubTitle.setText(getSubtitleText()); } - showProgressBar(); setMobileDataLayout(mInternetDialogController.activeNetworkIsCellular()); + if (!mCanConfigWifi) { + return; + } + + showProgressBar(); final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked(); final boolean isWifiEnabled = mWifiManager.isWifiEnabled(); updateWifiToggle(isWifiEnabled, isDeviceLocked); updateConnectedWifi(isWifiEnabled, isDeviceLocked); - List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList(); - final int wifiListVisibility = - (isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0) - ? View.GONE : View.VISIBLE; - mWifiRecyclerView.setVisibility(wifiListVisibility); - if (wifiListVisibility == View.VISIBLE) { - mAdapter.notifyDataSetChanged(); - } - mSeeAllLayout.setVisibility(wifiListVisibility); + final int visibility = (isDeviceLocked || !isWifiEnabled || mWifiEntriesCount <= 0) + ? View.GONE : View.VISIBLE; + mWifiRecyclerView.setVisibility(visibility); + mSeeAllLayout.setVisibility(visibility); } private void setOnClickListener() { @@ -368,6 +390,12 @@ public class InternetDialog extends SystemUIDialog implements private void updateWifiToggle(boolean isWifiEnabled, boolean isDeviceLocked) { mWiFiToggle.setChecked(isWifiEnabled); + if (isDeviceLocked && mInternetDialogController.isNightMode()) { + int titleColor = mConnectedWifiEntry != null ? mContext.getColor( + R.color.connected_network_primary_color) : Utils.getColorAttrDefaultColor( + mContext, android.R.attr.textColorPrimary); + mWifiToggleTitleText.setTextColor(titleColor); + } mTurnWifiOnLayout.setBackground( (isDeviceLocked && mConnectedWifiEntry != null) ? mBackgroundOn : null); } @@ -379,8 +407,8 @@ public class InternetDialog extends SystemUIDialog implements return; } mConnectedWifListLayout.setVisibility(View.VISIBLE); - mConnectedWifiTitleText.setText(mInternetDialogController.getInternetWifiTitle()); - mConnectedWifiSummaryText.setText(mInternetDialogController.getInternetWifiSummary()); + mConnectedWifiTitleText.setText(mConnectedWifiEntry.getTitle()); + mConnectedWifiSummaryText.setText(mConnectedWifiEntry.getSummary(false)); mConnectedWifiIcon.setImageDrawable( mInternetDialogController.getInternetWifiDrawable(mConnectedWifiEntry)); if (mInternetDialogController.isNightMode()) { @@ -430,8 +458,7 @@ public class InternetDialog extends SystemUIDialog implements return; } setProgressBarVisible(true); - List<ScanResult> wifiScanResults = mWifiManager.getScanResults(); - if (wifiScanResults != null && wifiScanResults.size() > 0) { + if (mConnectedWifiEntry != null || mWifiEntriesCount > 0) { mHandler.postDelayed(mHideProgressBarRunnable, PROGRESS_DELAY_MS); } else if (!mIsSearchingHidden) { mHandler.postDelayed(mHideSearchingRunnable, PROGRESS_DELAY_MS); @@ -516,8 +543,8 @@ public class InternetDialog extends SystemUIDialog implements } @Override + @WorkerThread public void onDataConnectionStateChanged(int state, int networkType) { - mAdapter.notifyDataSetChanged(); mHandler.post(() -> updateDialog()); } @@ -532,10 +559,16 @@ public class InternetDialog extends SystemUIDialog implements } @Override - public void onAccessPointsChanged(List<WifiEntry> wifiEntryList, WifiEntry connectedEntry) { + @WorkerThread + public void onAccessPointsChanged(@Nullable List<WifiEntry> wifiEntries, + @Nullable WifiEntry connectedEntry) { mConnectedWifiEntry = connectedEntry; - mAdapter.notifyDataSetChanged(); - mHandler.post(() -> updateDialog()); + mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size(); + mAdapter.setWifiEntries(wifiEntries, mWifiEntriesCount); + mHandler.post(() -> { + mAdapter.notifyDataSetChanged(); + updateDialog(); + }); } @Override @@ -548,24 +581,6 @@ public class InternetDialog extends SystemUIDialog implements } } - @Override - public void onWifiStateReceived(Context context, Intent intent) { - if (intent == null) { - return; - } - - String action = intent.getAction(); - if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { - mInternetDialogController.scanWifiAccessPoints(); - showProgressBar(); - return; - } - - if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { - mHandler.post(() -> updateDialog()); - } - } - public enum InternetDialogEvent implements UiEventLogger.UiEventEnum { @UiEvent(doc = "The Internet dialog became visible on the screen.") INTERNET_DIALOG_SHOW(843); diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java index ed32730c58b1..dfe78de81f7f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java @@ -32,7 +32,6 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkRequest; -import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Handler; import android.provider.Settings; @@ -53,6 +52,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.annotation.WorkerThread; import com.android.internal.logging.UiEventLogger; import com.android.keyguard.KeyguardUpdateMonitor; @@ -108,6 +108,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, R.string.all_network_unavailable; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + static final int MAX_WIFI_ENTRY_COUNT = 4; + private WifiManager mWifiManager; private Context mContext; private SubscriptionManager mSubscriptionManager; @@ -122,7 +124,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, private AccessPointController mAccessPointController; private IntentFilter mConnectionStateFilter; private InternetDialogCallback mCallback; - private List<WifiEntry> mWifiEntry; + private WifiEntry mConnectedEntry; + private int mWifiEntriesCount; private UiEventLogger mUiEventLogger; private BroadcastDispatcher mBroadcastDispatcher; private KeyguardUpdateMonitor mKeyguardUpdateMonitor; @@ -132,16 +135,15 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @VisibleForTesting protected ActivityStarter mActivityStarter; @VisibleForTesting - protected WifiEntry mConnectedEntry; - @VisibleForTesting protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting protected InternetTelephonyCallback mInternetTelephonyCallback; @VisibleForTesting protected WifiUtils.InternetIconInjector mWifiIconInjector; - @VisibleForTesting - KeyguardStateController mKeyguardStateController; + protected boolean mCanConfigWifi; + @VisibleForTesting + protected KeyguardStateController mKeyguardStateController; private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback = new KeyguardUpdateMonitorCallback() { @@ -183,8 +185,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mKeyguardUpdateMonitor = keyguardUpdateMonitor; mKeyguardStateController = keyguardStateController; mConnectionStateFilter = new IntentFilter(); - mConnectionStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - mConnectionStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); mConnectionStateFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); mUiEventLogger = uiEventLogger; mActivityStarter = starter; @@ -193,7 +193,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mWifiIconInjector = new WifiUtils.InternetIconInjector(mContext); } - void onStart(@NonNull InternetDialogCallback callback) { + void onStart(@NonNull InternetDialogCallback callback, boolean canConfigWifi) { if (DEBUG) { Log.d(TAG, "onStart"); } @@ -217,6 +217,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mConnectivityManager.registerNetworkCallback(new NetworkRequest.Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build(), new DataConnectivityListener(), mHandler); + mCanConfigWifi = canConfigWifi; scanWifiAccessPoints(); } @@ -270,7 +271,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return null; } - if (!mWifiManager.isWifiEnabled()) { + if (mCanConfigWifi && !mWifiManager.isWifiEnabled()) { // When the airplane mode is off and Wi-Fi is disabled. // Sub-Title: Wi-Fi is off if (DEBUG) { @@ -288,12 +289,11 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mContext.getText(SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS); } - final List<ScanResult> wifiList = mWifiManager.getScanResults(); - if (wifiList != null && wifiList.size() != 0) { - return mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT); + if (mConnectedEntry != null || mWifiEntriesCount > 0) { + return mCanConfigWifi ? mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT) : null; } - if (isProgressBarVisible) { + if (mCanConfigWifi && isProgressBarVisible) { // When the Wi-Fi scan result callback is received // Sub-Title: Searching for networks... return mContext.getText(SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS); @@ -317,7 +317,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mContext.getText(SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE); } - if (!isMobileDataEnabled()) { + if (mCanConfigWifi && !isMobileDataEnabled()) { if (DEBUG) { Log.d(TAG, "Mobile data off"); } @@ -331,7 +331,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return mContext.getText(SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE); } - return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE); + if (mCanConfigWifi) { + return mContext.getText(SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE); + } + return null; } Drawable getInternetWifiDrawable(@NonNull WifiEntry wifiEntry) { @@ -549,26 +552,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, return summary; } - String getInternetWifiTitle() { - if (getInternetWifiEntry() == null) { - if (DEBUG) { - Log.d(TAG, "connected entry is null"); - } - return ""; - } - return getInternetWifiEntry().getTitle(); - } - - String getInternetWifiSummary() { - if (getInternetWifiEntry() == null) { - if (DEBUG) { - Log.d(TAG, "connected entry is null"); - } - return ""; - } - return getInternetWifiEntry().getSummary(false); - } - void launchNetworkSetting() { mCallback.dismissDialog(); mActivityStarter.postStartActivityDismissingKeyguard(getSettingsIntent(), 0); @@ -590,18 +573,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } - List<WifiEntry> getWifiEntryList() { - return mWifiEntry; - } - - WifiEntry getInternetWifiEntry() { - if (mConnectedEntry == null || !mConnectedEntry.isDefaultNetwork() - || !mConnectedEntry.hasInternetAccess()) { - return null; - } - return mConnectedEntry; - } - WifiManager getWifiManager() { return mWifiManager; } @@ -779,20 +750,33 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } - void scanWifiAccessPoints() { - mAccessPointController.scanForAccessPoints(); + private void scanWifiAccessPoints() { + if (mCanConfigWifi) { + mAccessPointController.scanForAccessPoints(); + } } @Override + @WorkerThread public void onAccessPointsChanged(List<WifiEntry> accessPoints) { - if (accessPoints == null) { + if (!mCanConfigWifi) { + return; + } + + if (accessPoints == null || accessPoints.size() == 0) { + mConnectedEntry = null; + mWifiEntriesCount = 0; + if (mCallback != null) { + mCallback.onAccessPointsChanged(null /* wifiEntries */, null /* connectedEntry */); + } return; } boolean hasConnectedWifi = false; - mWifiEntry = accessPoints; - for (WifiEntry wifiEntry : accessPoints) { - if (wifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) { + final int accessPointSize = accessPoints.size(); + for (int i = 0; i < accessPointSize; i++) { + WifiEntry wifiEntry = accessPoints.get(i); + if (wifiEntry.isDefaultNetwork() && wifiEntry.hasInternetAccess()) { mConnectedEntry = wifiEntry; hasConnectedWifi = true; break; @@ -802,7 +786,23 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, mConnectedEntry = null; } - mCallback.onAccessPointsChanged(mWifiEntry, getInternetWifiEntry()); + int count = MAX_WIFI_ENTRY_COUNT; + if (hasCarrier()) { + count -= 1; + } + if (hasConnectedWifi) { + count -= 1; + } + final List<WifiEntry> wifiEntries = accessPoints.stream() + .filter(wifiEntry -> (!wifiEntry.isDefaultNetwork() + || !wifiEntry.hasInternetAccess())) + .limit(count) + .collect(Collectors.toList()); + mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size(); + + if (mCallback != null) { + mCallback.onAccessPointsChanged(wifiEntries, mConnectedEntry); + } } @Override @@ -855,8 +855,17 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, private class DataConnectivityListener extends ConnectivityManager.NetworkCallback { @Override + @WorkerThread public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) { + if (mCanConfigWifi) { + for (int transport : networkCapabilities.getTransportTypes()) { + if (transport == NetworkCapabilities.TRANSPORT_WIFI) { + scanWifiAccessPoints(); + break; + } + } + } final Network activeNetwork = mConnectivityManager.getActiveNetwork(); if (activeNetwork != null && activeNetwork.equals(network)) { // update UI @@ -869,11 +878,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) - || action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { - mCallback.onWifiStateReceived(context, intent); - } - if (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { if (DEBUG) { Log.d(TAG, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED"); @@ -929,8 +933,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, void dismissDialog(); - void onAccessPointsChanged(List<WifiEntry> wifiEntryList, WifiEntry connectedEntry); - - void onWifiStateReceived(Context context, Intent intent); + void onAccessPointsChanged(@Nullable List<WifiEntry> wifiEntries, + @Nullable WifiEntry connectedEntry); } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogFactory.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogFactory.kt index e82e89ef14c4..11c6980678b1 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogFactory.kt @@ -31,17 +31,17 @@ private val DEBUG = Log.isLoggable(TAG, Log.DEBUG) */ @SysUISingleton class InternetDialogFactory @Inject constructor( - @Main private val handler: Handler, - private val internetDialogController: InternetDialogController, - private val context: Context, - private val uiEventLogger: UiEventLogger + @Main private val handler: Handler, + private val internetDialogController: InternetDialogController, + private val context: Context, + private val uiEventLogger: UiEventLogger ) { companion object { var internetDialog: InternetDialog? = null } /** Creates a [InternetDialog]. */ - fun create(aboveStatusBar: Boolean, canConfigMobileData: Boolean) { + fun create(aboveStatusBar: Boolean, canConfigMobileData: Boolean, canConfigWifi: Boolean) { if (internetDialog != null) { if (DEBUG) { Log.d(TAG, "InternetDialog is showing, do not create it twice.") @@ -49,7 +49,7 @@ class InternetDialogFactory @Inject constructor( return } else { internetDialog = InternetDialog(context, this, internetDialogController, - canConfigMobileData, aboveStatusBar, uiEventLogger, handler) + canConfigMobileData, canConfigWifi, aboveStatusBar, uiEventLogger, handler) internetDialog?.show() } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java index 8bb545b394f9..af0d41331c28 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java @@ -801,8 +801,8 @@ public class NetworkControllerImpl extends BroadcastReceiver mReceiverHandler.post(this::handleConfigurationChanged); break; case Settings.Panel.ACTION_INTERNET_CONNECTIVITY: - boolean canConfigMobileData = mAccessPoints.canConfigMobileData(); - mMainHandler.post(() -> mInternetDialogFactory.create(true, canConfigMobileData)); + mMainHandler.post(() -> mInternetDialogFactory.create(true, + mAccessPoints.canConfigMobileData(), mAccessPoints.canConfigWifi())); break; default: int subId = intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java index 2b9082d7e303..fa5f70c5a2fc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java @@ -2,8 +2,11 @@ package com.android.systemui.qs.tiles.dialog; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -24,6 +27,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Arrays; +import java.util.List; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -35,6 +39,8 @@ public class InternetAdapterTest extends SysuiTestCase { @Mock private WifiEntry mInternetWifiEntry; @Mock + private List<WifiEntry> mWifiEntries; + @Mock private WifiEntry mWifiEntry; @Mock private InternetDialogController mInternetDialogController; @@ -56,43 +62,17 @@ public class InternetAdapterTest extends SysuiTestCase { mInternetAdapter = new InternetAdapter(mInternetDialogController); mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0); - when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry); - when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry)); + mInternetAdapter.setWifiEntries(Arrays.asList(mWifiEntry), 1 /* wifiEntriesCount */); mViewHolder.mWifiIconInjector = mWifiIconInjector; } @Test - public void getItemCount_withApmOnWifiOnNoInternetWifi_returnFour() { - // The preconditions WiFi ON is already in setUp() - when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null); - when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); - - assertThat(mInternetAdapter.getItemCount()).isEqualTo(4); - } - - @Test - public void getItemCount_withApmOnWifiOnHasInternetWifi_returnThree() { - // The preconditions WiFi ON and Internet WiFi are already in setUp() - when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); + public void getItemCount_returnWifiEntriesCount() { + for (int i = 0; i < InternetDialogController.MAX_WIFI_ENTRY_COUNT; i++) { + mInternetAdapter.setWifiEntries(mWifiEntries, i /* wifiEntriesCount */); - assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); - } - - @Test - public void getItemCount_withApmOffWifiOnNoInternetWifi_returnThree() { - // The preconditions WiFi ON is already in setUp() - when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null); - when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); - - assertThat(mInternetAdapter.getItemCount()).isEqualTo(3); - } - - @Test - public void getItemCount_withApmOffWifiOnHasInternetWifi_returnTwo() { - // The preconditions WiFi ON and Internet WiFi are already in setUp() - when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); - - assertThat(mInternetAdapter.getItemCount()).isEqualTo(2); + assertThat(mInternetAdapter.getItemCount()).isEqualTo(i); + } } @Test @@ -118,7 +98,17 @@ public class InternetAdapterTest extends SysuiTestCase { } @Test - public void onBindViewHolder_bindDefaultWifiNetwork_getIconWithInternet() { + public void onBindViewHolder_wifiLevelUnreachable_shouldNotGetWifiIcon() { + reset(mWifiIconInjector); + when(mWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_UNREACHABLE); + + mInternetAdapter.onBindViewHolder(mViewHolder, 0); + + verify(mWifiIconInjector, never()).getIcon(anyBoolean(), anyInt()); + } + + @Test + public void onBindViewHolder_shouldNotShowXLevelIcon_getIconWithInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(false); mInternetAdapter.onBindViewHolder(mViewHolder, 0); @@ -127,7 +117,7 @@ public class InternetAdapterTest extends SysuiTestCase { } @Test - public void onBindViewHolder_bindNoDefaultWifiNetwork_getIconWithNoInternet() { + public void onBindViewHolder_shouldShowXLevelIcon_getIconWithNoInternet() { when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true); mInternetAdapter.onBindViewHolder(mViewHolder, 0); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java index 830fe5af69b8..cacc4095d141 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java @@ -10,6 +10,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -17,7 +18,6 @@ import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; -import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Handler; import android.telephony.ServiceState; @@ -84,14 +84,26 @@ public class InternetDialogControllerTest extends SysuiTestCase { @Mock private WifiEntry mConnectedEntry; @Mock + private WifiEntry mWifiEntry1; + @Mock + private WifiEntry mWifiEntry2; + @Mock + private WifiEntry mWifiEntry3; + @Mock + private WifiEntry mWifiEntry4; + @Mock private ServiceState mServiceState; @Mock private BroadcastDispatcher mBroadcastDispatcher; @Mock private WifiUtils.InternetIconInjector mWifiIconInjector; + @Mock + InternetDialogController.InternetDialogCallback mInternetDialogCallback; private MockInternetDialogController mInternetDialogController; private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); + private List<WifiEntry> mAccessPoints = new ArrayList<>(); + private List<WifiEntry> mWifiEntries = new ArrayList<>(); @Before public void setUp() { @@ -100,6 +112,13 @@ public class InternetDialogControllerTest extends SysuiTestCase { when(mKeyguardStateController.isUnlocked()).thenReturn(true); when(mConnectedEntry.isDefaultNetwork()).thenReturn(true); when(mConnectedEntry.hasInternetAccess()).thenReturn(true); + when(mWifiEntry1.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED); + when(mWifiEntry2.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED); + when(mWifiEntry3.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED); + when(mWifiEntry4.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_DISCONNECTED); + mAccessPoints.add(mConnectedEntry); + mAccessPoints.add(mWifiEntry1); + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID}); mInternetDialogController = new MockInternetDialogController(mContext, mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController, @@ -108,10 +127,9 @@ public class InternetDialogControllerTest extends SysuiTestCase { mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController); mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor, mInternetDialogController.mOnSubscriptionsChangedListener); - mInternetDialogController.onStart( - mock(InternetDialogController.InternetDialogCallback.class)); + mInternetDialogController.onStart(mInternetDialogCallback, true); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); mInternetDialogController.mActivityStarter = mActivityStarter; - mInternetDialogController.mConnectedEntry = mConnectedEntry; mInternetDialogController.mWifiIconInjector = mWifiIconInjector; } @@ -143,32 +161,46 @@ public class InternetDialogControllerTest extends SysuiTestCase { mInternetDialogController.setAirplaneModeEnabled(false); when(mWifiManager.isWifiEnabled()).thenReturn(false); - assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false), - getResourcesString("wifi_is_off"))); + assertThat(mInternetDialogController.getSubtitleText(false)) + .isEqualTo(getResourcesString("wifi_is_off")); + + // if the Wi-Fi disallow config, then don't return Wi-Fi related string. + mInternetDialogController.mCanConfigWifi = false; + + assertThat(mInternetDialogController.getSubtitleText(false)) + .isNotEqualTo(getResourcesString("wifi_is_off")); } @Test public void getSubtitleText_withNoWifiEntry_returnSearchWifi() { mInternetDialogController.setAirplaneModeEnabled(false); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = mock(ArrayList.class); - doReturn(0).when(wifiScanResults).size(); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); + + assertThat(mInternetDialogController.getSubtitleText(true)) + .isEqualTo(getResourcesString("wifi_empty_list_wifi_on")); - assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(true), - getResourcesString("wifi_empty_list_wifi_on"))); + // if the Wi-Fi disallow config, then don't return Wi-Fi related string. + mInternetDialogController.mCanConfigWifi = false; + + assertThat(mInternetDialogController.getSubtitleText(true)) + .isNotEqualTo(getResourcesString("wifi_empty_list_wifi_on")); } @Test public void getSubtitleText_withWifiEntry_returnTapToConnect() { + // The preconditions WiFi Entries is already in setUp() mInternetDialogController.setAirplaneModeEnabled(false); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = mock(ArrayList.class); - doReturn(1).when(wifiScanResults).size(); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); - assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false), - getResourcesString("tap_a_network_to_connect"))); + assertThat(mInternetDialogController.getSubtitleText(false)) + .isEqualTo(getResourcesString("tap_a_network_to_connect")); + + // if the Wi-Fi disallow config, then don't return Wi-Fi related string. + mInternetDialogController.mCanConfigWifi = false; + + assertThat(mInternetDialogController.getSubtitleText(false)) + .isNotEqualTo(getResourcesString("tap_a_network_to_connect")); } @Test @@ -185,11 +217,7 @@ public class InternetDialogControllerTest extends SysuiTestCase { public void getSubtitleText_withNoService_returnNoNetworksAvailable() { mInternetDialogController.setAirplaneModeEnabled(false); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = new ArrayList<>(); - doReturn(wifiScanResults).when(mWifiManager).getScanResults(); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); - when(mSubscriptionManager.getActiveSubscriptionIdList()) - .thenReturn(new int[] {SUB_ID}); + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getState(); doReturn(mServiceState).when(mTelephonyManager).getServiceState(); @@ -203,143 +231,223 @@ public class InternetDialogControllerTest extends SysuiTestCase { public void getSubtitleText_withMobileDataDisabled_returnNoOtherAvailable() { mInternetDialogController.setAirplaneModeEnabled(false); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = new ArrayList<>(); - doReturn(wifiScanResults).when(mWifiManager).getScanResults(); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); - when(mSubscriptionManager.getActiveSubscriptionIdList()) - .thenReturn(new int[] {SUB_ID}); + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState(); doReturn(mServiceState).when(mTelephonyManager).getServiceState(); when(mTelephonyManager.isDataEnabled()).thenReturn(false); - assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false), - getResourcesString("non_carrier_network_unavailable"))); + assertThat(mInternetDialogController.getSubtitleText(false)) + .isEqualTo(getResourcesString("non_carrier_network_unavailable")); + + // if the Wi-Fi disallow config, then don't return Wi-Fi related string. + mInternetDialogController.mCanConfigWifi = false; + + assertThat(mInternetDialogController.getSubtitleText(false)) + .isNotEqualTo(getResourcesString("non_carrier_network_unavailable")); } @Test - public void getInternetWifiEntry_connectedEntryIsNull_returnNull() { - mInternetDialogController.mConnectedEntry = null; + public void getWifiDetailsSettingsIntent_withNoConnectedEntry_returnNull() { + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); - assertThat(mInternetDialogController.getInternetWifiEntry()).isNull(); + assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull(); } @Test - public void getInternetWifiEntry_connectedWifiIsNotDefaultNetwork_returnNull() { - when(mConnectedEntry.isDefaultNetwork()).thenReturn(false); + public void getWifiDetailsSettingsIntent_withNoConnectedEntryKey_returnNull() { + when(mConnectedEntry.getKey()).thenReturn(null); - assertThat(mInternetDialogController.getInternetWifiEntry()).isNull(); + assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull(); } @Test - public void getInternetWifiEntry_connectedWifiHasNotInternetAccess_returnNull() { - when(mConnectedEntry.hasInternetAccess()).thenReturn(false); + public void getWifiDetailsSettingsIntent_withConnectedEntryKey_returnIntent() { + when(mConnectedEntry.getKey()).thenReturn("test_key"); - assertThat(mInternetDialogController.getInternetWifiEntry()).isNull(); + assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull(); } @Test - 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. + public void getWifiDrawable_withConnectedEntry_returnIntentIconWithCorrectColor() { + final Drawable drawable = mock(Drawable.class); + when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable); - assertThat(mInternetDialogController.getInternetWifiEntry()).isEqualTo(mConnectedEntry); + mInternetDialogController.getInternetWifiDrawable(mConnectedEntry); + + verify(mWifiIconInjector).getIcon(eq(false), anyInt()); + verify(drawable).setTint(mContext.getColor(R.color.connected_network_primary_color)); } @Test - public void getInternetWifiTitle_withNoConnectedWifiEntry_returnEmpty() { - mInternetDialogController.mConnectedEntry = null; + public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() { + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); + + mInternetDialogController.launchWifiNetworkDetailsSetting(); - assertThat(mInternetDialogController.getInternetWifiTitle()).isEmpty(); + verify(mActivityStarter, never()) + .postStartActivityDismissingKeyguard(any(Intent.class), anyInt()); } @Test - 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); + public void launchWifiNetworkDetailsSetting_withConnectedEntryKey_startActivity() { + when(mConnectedEntry.getKey()).thenReturn("test_key"); - assertThat(mInternetDialogController.getInternetWifiTitle()).isEqualTo(CONNECTED_TITLE); + mInternetDialogController.launchWifiNetworkDetailsSetting(); + + verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt()); } @Test - public void getInternetWifiSummary_withNoConnectedWifiEntry_returnEmpty() { - mInternetDialogController.mConnectedEntry = null; + public void isDeviceLocked_keyguardIsUnlocked_returnFalse() { + when(mKeyguardStateController.isUnlocked()).thenReturn(true); - assertThat(mInternetDialogController.getInternetWifiSummary()).isEmpty(); + assertThat(mInternetDialogController.isDeviceLocked()).isFalse(); } @Test - public void getInternetWifiSummary_withInternetWifi_returnSummary() { - when(mConnectedEntry.getSummary(false)).thenReturn(CONNECTED_SUMMARY); + public void isDeviceLocked_keyguardIsLocked_returnTrue() { + when(mKeyguardStateController.isUnlocked()).thenReturn(false); - assertThat(mInternetDialogController.getInternetWifiSummary()).isEqualTo(CONNECTED_SUMMARY); + assertThat(mInternetDialogController.isDeviceLocked()).isTrue(); } @Test - public void getWifiDetailsSettingsIntent_withNoConnectedEntry_returnNull() { - mInternetDialogController.mConnectedEntry = null; + public void onAccessPointsChanged_canNotConfigWifi_doNothing() { + reset(mInternetDialogCallback); + mInternetDialogController.mCanConfigWifi = false; - assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull(); + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); + + verify(mInternetDialogCallback, never()).onAccessPointsChanged(any(), any()); } @Test - public void getWifiDetailsSettingsIntent_withNoConnectedEntryKey_returnNull() { - when(mConnectedEntry.getKey()).thenReturn(null); + public void onAccessPointsChanged_nullAccessPoints_callbackBothNull() { + reset(mInternetDialogCallback); - assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNull(); + mInternetDialogController.onAccessPointsChanged(null /* accessPoints */); + + verify(mInternetDialogCallback) + .onAccessPointsChanged(null /* wifiEntries */, null /* connectedEntry */); } @Test - public void getWifiDetailsSettingsIntent_withConnectedEntryKey_returnIntent() { - when(mConnectedEntry.getKey()).thenReturn("test_key"); + public void onAccessPointsChanged_oneConnectedEntry_callbackConnectedEntryOnly() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mConnectedEntry); - assertThat(mInternetDialogController.getWifiDetailsSettingsIntent()).isNotNull(); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); + + mWifiEntries.clear(); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); } @Test - public void getWifiDrawable_withConnectedEntry_returnIntentIconWithCorrectColor() { - final Drawable drawable = mock(Drawable.class); - when(mWifiIconInjector.getIcon(anyBoolean(), anyInt())).thenReturn(drawable); + public void onAccessPointsChanged_noConnectedEntryAndOneOther_callbackWifiEntriesOnly() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mWifiEntry1); - mInternetDialogController.getInternetWifiDrawable(mConnectedEntry); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); - verify(mWifiIconInjector).getIcon(eq(false), anyInt()); - verify(drawable).setTint(mContext.getColor(R.color.connected_network_primary_color)); + mWifiEntries.clear(); + mWifiEntries.add(mWifiEntry1); + verify(mInternetDialogCallback) + .onAccessPointsChanged(mWifiEntries, null /* connectedEntry */); } @Test - public void launchWifiNetworkDetailsSetting_withNoConnectedEntry_doNothing() { - mInternetDialogController.mConnectedEntry = null; + public void onAccessPointsChanged_oneConnectedEntryAndOneOther_callbackCorrectly() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mConnectedEntry); + mAccessPoints.add(mWifiEntry1); - mInternetDialogController.launchWifiNetworkDetailsSetting(); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); - verify(mActivityStarter, never()) - .postStartActivityDismissingKeyguard(any(Intent.class), anyInt()); + mWifiEntries.clear(); + mWifiEntries.add(mWifiEntry1); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); } @Test - public void launchWifiNetworkDetailsSetting_withConnectedEntryKey_startActivity() { - when(mConnectedEntry.getKey()).thenReturn("test_key"); + public void onAccessPointsChanged_oneConnectedEntryAndTwoOthers_callbackCorrectly() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mConnectedEntry); + mAccessPoints.add(mWifiEntry1); + mAccessPoints.add(mWifiEntry2); - mInternetDialogController.launchWifiNetworkDetailsSetting(); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); - verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt()); + mWifiEntries.clear(); + mWifiEntries.add(mWifiEntry1); + mWifiEntries.add(mWifiEntry2); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); } @Test - public void isDeviceLocked_keyguardIsUnlocked_returnFalse() { - when(mKeyguardStateController.isUnlocked()).thenReturn(true); + public void onAccessPointsChanged_oneConnectedEntryAndThreeOthers_callbackCutMore() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mConnectedEntry); + mAccessPoints.add(mWifiEntry1); + mAccessPoints.add(mWifiEntry2); + mAccessPoints.add(mWifiEntry3); + + mInternetDialogController.onAccessPointsChanged(mAccessPoints); + + mWifiEntries.clear(); + mWifiEntries.add(mWifiEntry1); + mWifiEntries.add(mWifiEntry2); + mWifiEntries.add(mWifiEntry3); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); + + // Turn off airplane mode to has carrier network, then Wi-Fi entries will cut last one. + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(false); - assertThat(mInternetDialogController.isDeviceLocked()).isFalse(); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); + + mWifiEntries.remove(mWifiEntry3); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); } @Test - public void isDeviceLocked_keyguardIsLocked_returnTrue() { - when(mKeyguardStateController.isUnlocked()).thenReturn(false); + public void onAccessPointsChanged_oneConnectedEntryAndFourOthers_callbackCutMore() { + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(true); + mAccessPoints.clear(); + mAccessPoints.add(mConnectedEntry); + mAccessPoints.add(mWifiEntry1); + mAccessPoints.add(mWifiEntry2); + mAccessPoints.add(mWifiEntry3); + mAccessPoints.add(mWifiEntry4); + + mInternetDialogController.onAccessPointsChanged(mAccessPoints); + + mWifiEntries.clear(); + mWifiEntries.add(mWifiEntry1); + mWifiEntries.add(mWifiEntry2); + mWifiEntries.add(mWifiEntry3); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); + + // Turn off airplane mode to has carrier network, then Wi-Fi entries will cut last one. + reset(mInternetDialogCallback); + mInternetDialogController.setAirplaneModeEnabled(false); - assertThat(mInternetDialogController.isDeviceLocked()).isTrue(); + mInternetDialogController.onAccessPointsChanged(mAccessPoints); + + mWifiEntries.remove(mWifiEntry3); + verify(mInternetDialogCallback).onAccessPointsChanged(mWifiEntries, mConnectedEntry); } private String getResourcesString(String name) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java index 5a018f409a0b..fa9c0538e9bd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java @@ -12,7 +12,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; import android.os.Handler; import android.telephony.TelephonyManager; @@ -20,7 +19,6 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; import android.widget.LinearLayout; -import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import androidx.test.filters.SmallTest; @@ -39,8 +37,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; @SmallTest @@ -62,13 +58,16 @@ public class InternetDialogTest extends SysuiTestCase { @Mock private WifiEntry mInternetWifiEntry; @Mock - private WifiEntry mWifiEntry; + private List<WifiEntry> mWifiEntries; @Mock private InternetAdapter mInternetAdapter; @Mock private InternetDialogController mInternetDialogController; private InternetDialog mInternetDialog; + private View mDialogView; + private View mSubTitle; + private LinearLayout mMobileDataToggle; private LinearLayout mWifiToggle; private LinearLayout mConnectedWifi; private RecyclerView mWifiList; @@ -83,26 +82,26 @@ public class InternetDialogTest extends SysuiTestCase { 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.getSummary(false)).thenReturn(WIFI_SUMMARY); + when(mWifiEntries.size()).thenReturn(1); 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)); mInternetDialog = new InternetDialog(mContext, mock(InternetDialogFactory.class), - mInternetDialogController, true, true, mock(UiEventLogger.class), mHandler); + mInternetDialogController, true, true, true, mock(UiEventLogger.class), mHandler); mInternetDialog.mAdapter = mInternetAdapter; - mInternetDialog.mConnectedWifiEntry = mInternetWifiEntry; + mInternetDialog.onAccessPointsChanged(mWifiEntries, mInternetWifiEntry); mInternetDialog.show(); - mWifiToggle = mInternetDialog.mDialogView.requireViewById(R.id.turn_on_wifi_layout); - mConnectedWifi = mInternetDialog.mDialogView.requireViewById(R.id.wifi_connected_layout); - mWifiList = mInternetDialog.mDialogView.requireViewById(R.id.wifi_list_layout); - mSeeAll = mInternetDialog.mDialogView.requireViewById(R.id.see_all_layout); + mDialogView = mInternetDialog.mDialogView; + mSubTitle = mDialogView.requireViewById(R.id.internet_dialog_subtitle); + mMobileDataToggle = mDialogView.requireViewById(R.id.mobile_network_layout); + mWifiToggle = mDialogView.requireViewById(R.id.turn_on_wifi_layout); + mConnectedWifi = mDialogView.requireViewById(R.id.wifi_connected_layout); + mWifiList = mDialogView.requireViewById(R.id.wifi_list_layout); + mSeeAll = mDialogView.requireViewById(R.id.see_all_layout); } @After @@ -111,33 +110,41 @@ public class InternetDialogTest extends SysuiTestCase { } @Test + public void hideWifiViews_WifiViewsGone() { + mInternetDialog.hideWifiViews(); + + assertThat(mInternetDialog.mIsProgressBarVisible).isFalse(); + assertThat(mWifiToggle.getVisibility()).isEqualTo(View.GONE); + assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE); + assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE); + assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE); + } + + @Test public void updateDialog_withApmOn_internetDialogSubTitleGone() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); + mInternetDialog.updateDialog(); - final TextView view = mInternetDialog.mDialogView.requireViewById( - R.id.internet_dialog_subtitle); - assertThat(view.getVisibility()).isEqualTo(View.GONE); + assertThat(mSubTitle.getVisibility()).isEqualTo(View.GONE); } @Test public void updateDialog_withApmOff_internetDialogSubTitleVisible() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(false); + mInternetDialog.updateDialog(); - final TextView view = mInternetDialog.mDialogView.requireViewById( - R.id.internet_dialog_subtitle); - assertThat(view.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mSubTitle.getVisibility()).isEqualTo(View.VISIBLE); } @Test public void updateDialog_withApmOn_mobileDataLayoutGone() { when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true); + mInternetDialog.updateDialog(); - final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById( - R.id.mobile_network_layout); - assertThat(linearLayout.getVisibility()).isEqualTo(View.GONE); + assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE); } @Test @@ -152,7 +159,8 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void updateDialog_wifiOnAndNoConnectedWifi_hideConnectedWifi() { - mInternetDialog.mConnectedWifiEntry = null; + // The precondition WiFi ON is already in setUp() + mInternetDialog.onAccessPointsChanged(mWifiEntries, null /* connectedEntry*/); doReturn(false).when(mInternetDialogController).activeNetworkIsCellular(); mInternetDialog.updateDialog(); @@ -162,7 +170,8 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void updateDialog_wifiOnAndNoWifiList_hideWifiListAndSeeAll() { - when(mInternetDialogController.getWifiEntryList()).thenReturn(null); + // The precondition WiFi ON is already in setUp() + mInternetDialog.onAccessPointsChanged(null /* wifiEntries */, mInternetWifiEntry); mInternetDialog.updateDialog(); @@ -245,9 +254,6 @@ public class InternetDialogTest extends SysuiTestCase { public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() { Mockito.reset(mHandler); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = mock(ArrayList.class); - when(wifiScanResults.size()).thenReturn(1); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); mInternetDialog.showProgressBar(); @@ -264,12 +270,10 @@ public class InternetDialogTest extends SysuiTestCase { } @Test - public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() { + public void showProgressBar_wifiEnabledWithoutWifiEntries_showProgressBarThenHideSearch() { Mockito.reset(mHandler); when(mWifiManager.isWifiEnabled()).thenReturn(true); - List<ScanResult> wifiScanResults = mock(ArrayList.class); - when(wifiScanResults.size()).thenReturn(0); - when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); + mInternetDialog.onAccessPointsChanged(null /* wifiEntries */, null /* connectedEntry*/); mInternetDialog.showProgressBar(); |