Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +21 −41 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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. Loading @@ -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; Loading @@ -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; } private List<WifiEntry> getWifiEntryList() { if (mInternetDialogController.getWifiEntryList() == null) { return null; viewHolder.onBind(mWifiEntries.get(position)); } 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}. * Gets the total number of Wi-Fi networks. * * 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. * * @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; } /** Loading Loading @@ -210,6 +187,9 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } 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) { Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +21 −37 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -54,7 +52,9 @@ import android.widget.ProgressBar; 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; Loading Loading @@ -91,8 +91,6 @@ public class InternetDialog extends SystemUIDialog implements @VisibleForTesting protected View mDialogView; @VisibleForTesting protected WifiEntry mConnectedWifiEntry; @VisibleForTesting protected boolean mCanConfigWifi; private InternetDialogFactory mInternetDialogFactory; Loading Loading @@ -131,6 +129,10 @@ public class InternetDialog extends SystemUIDialog implements 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; Loading Loading @@ -315,15 +317,10 @@ public class InternetDialog extends SystemUIDialog implements updateWifiToggle(isWifiEnabled, isDeviceLocked); updateConnectedWifi(isWifiEnabled, isDeviceLocked); List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList(); final int wifiListVisibility = (isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0) final int visibility = (isDeviceLocked || !isWifiEnabled || mWifiEntriesCount <= 0) ? View.GONE : View.VISIBLE; mWifiRecyclerView.setVisibility(wifiListVisibility); if (wifiListVisibility == View.VISIBLE) { mAdapter.notifyDataSetChanged(); } mSeeAllLayout.setVisibility(wifiListVisibility); mWifiRecyclerView.setVisibility(visibility); mSeeAllLayout.setVisibility(visibility); } private void setOnClickListener() { Loading Loading @@ -457,8 +454,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); Loading Loading @@ -543,8 +539,8 @@ public class InternetDialog extends SystemUIDialog implements } @Override @WorkerThread public void onDataConnectionStateChanged(int state, int networkType) { mAdapter.notifyDataSetChanged(); mHandler.post(() -> updateDialog()); } Loading @@ -559,10 +555,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; mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size(); mAdapter.setWifiEntries(wifiEntries, mWifiEntriesCount); mHandler.post(() -> { mAdapter.notifyDataSetChanged(); mHandler.post(() -> updateDialog()); updateDialog(); }); } @Override Loading @@ -575,24 +577,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); Loading packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +51 −36 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -132,8 +135,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @VisibleForTesting protected ActivityStarter mActivityStarter; @VisibleForTesting protected WifiEntry mConnectedEntry; @VisibleForTesting protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting protected InternetTelephonyCallback mInternetTelephonyCallback; Loading @@ -141,9 +142,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, protected WifiUtils.InternetIconInjector mWifiIconInjector; @VisibleForTesting protected boolean mCanConfigWifi; @VisibleForTesting KeyguardStateController mKeyguardStateController; protected KeyguardStateController mKeyguardStateController; private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback = new KeyguardUpdateMonitorCallback() { Loading Loading @@ -185,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; Loading Loading @@ -291,8 +289,7 @@ 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) { if (mConnectedEntry != null || mWifiEntriesCount > 0) { return mCanConfigWifi ? mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT) : null; } Loading Loading @@ -576,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; } Loading Loading @@ -765,22 +750,33 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } void scanWifiAccessPoints() { private void scanWifiAccessPoints() { if (mCanConfigWifi) { mAccessPointController.scanForAccessPoints(); } } @Override @WorkerThread public void onAccessPointsChanged(List<WifiEntry> accessPoints) { if (accessPoints == null || !mCanConfigWifi) { 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; Loading @@ -790,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 Loading Loading @@ -843,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 Loading @@ -857,11 +878,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (mCanConfigWifi && (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"); Loading Loading @@ -917,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); } } packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java +24 −34 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -24,6 +27,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.List; @SmallTest @RunWith(AndroidTestingRunner.class) Loading @@ -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; Loading @@ -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); 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); 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); assertThat(mInternetAdapter.getItemCount()).isEqualTo(i); } @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); } @Test Loading @@ -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); Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +157 −51 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +21 −41 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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. Loading @@ -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; Loading @@ -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; } private List<WifiEntry> getWifiEntryList() { if (mInternetDialogController.getWifiEntryList() == null) { return null; viewHolder.onBind(mWifiEntries.get(position)); } 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}. * Gets the total number of Wi-Fi networks. * * 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. * * @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; } /** Loading Loading @@ -210,6 +187,9 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern } 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) { Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +21 −37 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -54,7 +52,9 @@ import android.widget.ProgressBar; 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; Loading Loading @@ -91,8 +91,6 @@ public class InternetDialog extends SystemUIDialog implements @VisibleForTesting protected View mDialogView; @VisibleForTesting protected WifiEntry mConnectedWifiEntry; @VisibleForTesting protected boolean mCanConfigWifi; private InternetDialogFactory mInternetDialogFactory; Loading Loading @@ -131,6 +129,10 @@ public class InternetDialog extends SystemUIDialog implements 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; Loading Loading @@ -315,15 +317,10 @@ public class InternetDialog extends SystemUIDialog implements updateWifiToggle(isWifiEnabled, isDeviceLocked); updateConnectedWifi(isWifiEnabled, isDeviceLocked); List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList(); final int wifiListVisibility = (isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0) final int visibility = (isDeviceLocked || !isWifiEnabled || mWifiEntriesCount <= 0) ? View.GONE : View.VISIBLE; mWifiRecyclerView.setVisibility(wifiListVisibility); if (wifiListVisibility == View.VISIBLE) { mAdapter.notifyDataSetChanged(); } mSeeAllLayout.setVisibility(wifiListVisibility); mWifiRecyclerView.setVisibility(visibility); mSeeAllLayout.setVisibility(visibility); } private void setOnClickListener() { Loading Loading @@ -457,8 +454,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); Loading Loading @@ -543,8 +539,8 @@ public class InternetDialog extends SystemUIDialog implements } @Override @WorkerThread public void onDataConnectionStateChanged(int state, int networkType) { mAdapter.notifyDataSetChanged(); mHandler.post(() -> updateDialog()); } Loading @@ -559,10 +555,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; mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size(); mAdapter.setWifiEntries(wifiEntries, mWifiEntriesCount); mHandler.post(() -> { mAdapter.notifyDataSetChanged(); mHandler.post(() -> updateDialog()); updateDialog(); }); } @Override Loading @@ -575,24 +577,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); Loading
packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +51 −36 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -132,8 +135,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @VisibleForTesting protected ActivityStarter mActivityStarter; @VisibleForTesting protected WifiEntry mConnectedEntry; @VisibleForTesting protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener; @VisibleForTesting protected InternetTelephonyCallback mInternetTelephonyCallback; Loading @@ -141,9 +142,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, protected WifiUtils.InternetIconInjector mWifiIconInjector; @VisibleForTesting protected boolean mCanConfigWifi; @VisibleForTesting KeyguardStateController mKeyguardStateController; protected KeyguardStateController mKeyguardStateController; private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback = new KeyguardUpdateMonitorCallback() { Loading Loading @@ -185,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; Loading Loading @@ -291,8 +289,7 @@ 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) { if (mConnectedEntry != null || mWifiEntriesCount > 0) { return mCanConfigWifi ? mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT) : null; } Loading Loading @@ -576,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; } Loading Loading @@ -765,22 +750,33 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, } } void scanWifiAccessPoints() { private void scanWifiAccessPoints() { if (mCanConfigWifi) { mAccessPointController.scanForAccessPoints(); } } @Override @WorkerThread public void onAccessPointsChanged(List<WifiEntry> accessPoints) { if (accessPoints == null || !mCanConfigWifi) { 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; Loading @@ -790,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 Loading Loading @@ -843,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 Loading @@ -857,11 +878,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback, @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (mCanConfigWifi && (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"); Loading Loading @@ -917,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); } }
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetAdapterTest.java +24 −34 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -24,6 +27,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.List; @SmallTest @RunWith(AndroidTestingRunner.class) Loading @@ -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; Loading @@ -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); 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); 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); assertThat(mInternetAdapter.getItemCount()).isEqualTo(i); } @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); } @Test Loading @@ -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); Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +157 −51 File changed.Preview size limit exceeded, changes collapsed. Show changes