Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22306c37 authored by Weng Su's avatar Weng Su Committed by Zoey Chen
Browse files

[RESTRICT AUTOMERGE] [Provider Model] Fix WiFi SSID disappear issue

- When WiFi is connected, there will be no internet access for a short
time. Need to detect the ConnectivityManager network to assign WiFi to
the default network, and make sure that the Wi-Fi connection is ready
for internet access.

- Refine the main thread functions to avoid calling unnecessary
functions

Bug: 195893061
Test: manual test
atest -c InternetAdapterTest \
         InternetDialogControllerTest \
         InternetDialogTest

Change-Id: I505c9b044f8b139fb6c5d4df415c5ad56ce7b301
(cherry picked from commit 65aa2ec5)
parent 7c0b74fd
Loading
Loading
Loading
Loading
+21 −41
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
@@ -34,6 +33,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;


import com.android.settingslib.Utils;
import com.android.settingslib.Utils;
@@ -43,7 +43,6 @@ import com.android.wifitrackerlib.WifiEntry;


import java.util.List;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;


/**
/**
 * Adapter for showing Wi-Fi networks.
 * 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 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_CHOSEN_WIFI_ENTRY_KEY = "key_chosen_wifientry_key";
    private static final String EXTRA_CONNECT_FOR_CALLER = "connect_for_caller";
    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 final InternetDialogController mInternetDialogController;
    private List<WifiEntry> mWifiEntries;
    private int mWifiEntriesCount;


    protected View mHolderView;
    protected View mHolderView;
    protected Context mContext;
    protected Context mContext;
@@ -76,54 +76,31 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern


    @Override
    @Override
    public void onBindViewHolder(@NonNull InternetViewHolder viewHolder, int position) {
    public void onBindViewHolder(@NonNull InternetViewHolder viewHolder, int position) {
        List<WifiEntry> wifiList = getWifiEntryList();
        if (mWifiEntries == null || position >= mWifiEntriesCount) {
        if (wifiList != null && wifiList.size() != 0) {
            return;
            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");
        }
        }
        }

        viewHolder.onBind(mWifiEntries.get(position));
    private List<WifiEntry> getWifiEntryList() {
        if (mInternetDialogController.getWifiEntryList() == null) {
            return null;
    }
    }


        return mInternetDialogController.getWifiEntryList().stream()
    /**
                .filter(wifiEntry -> (!wifiEntry.isDefaultNetwork()
     * Updates the Wi-Fi networks.
                        || !wifiEntry.hasInternetAccess()))
     *
                .limit(getItemCount())
     * @param wifiEntries the updated Wi-Fi entries.
                .collect(Collectors.toList());
     * @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
     * Gets the total number of Wi-Fi networks.
     * {@link InternetDialog}.
     *
     *
     * Airplane mode is ON (mobile network is gone):
     * @return The total number of Wi-Fi entries.
     *   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.
     */
     */
    @Override
    @Override
    public int getItemCount() {
    public int getItemCount() {
        final boolean hasInternetWifi = mInternetDialogController.getInternetWifiEntry() != null;
        return mWifiEntriesCount;
        if (mInternetDialogController.isAirplaneModeEnabled()) {
            return hasInternetWifi ? 3 : 4;
        } else {
            return hasInternetWifi ? 2 : 3;
        }
    }
    }


    /**
    /**
@@ -210,6 +187,9 @@ public class InternetAdapter extends RecyclerView.Adapter<InternetAdapter.Intern
        }
        }


        Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable {
        Drawable getWifiDrawable(@NonNull WifiEntry wifiEntry) throws Throwable {
            if (wifiEntry.getLevel() == WifiEntry.WIFI_LEVEL_UNREACHABLE) {
                return null;
            }
            final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(),
            final Drawable drawable = mWifiIconInjector.getIcon(wifiEntry.shouldShowXLevelIcon(),
                    wifiEntry.getLevel());
                    wifiEntry.getLevel());
            if (drawable == null) {
            if (drawable == null) {
+21 −37
Original line number Original line Diff line number Diff line
@@ -21,13 +21,11 @@ import static com.android.systemui.Prefs.Key.QS_HAS_TURNED_OFF_MOBILE_DATA;


import android.app.AlertDialog;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.net.Network;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
@@ -54,7 +52,9 @@ import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TextView;


import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;


@@ -91,8 +91,6 @@ public class InternetDialog extends SystemUIDialog implements
    @VisibleForTesting
    @VisibleForTesting
    protected View mDialogView;
    protected View mDialogView;
    @VisibleForTesting
    @VisibleForTesting
    protected WifiEntry mConnectedWifiEntry;
    @VisibleForTesting
    protected boolean mCanConfigWifi;
    protected boolean mCanConfigWifi;


    private InternetDialogFactory mInternetDialogFactory;
    private InternetDialogFactory mInternetDialogFactory;
@@ -131,6 +129,10 @@ public class InternetDialog extends SystemUIDialog implements
    private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private boolean mCanConfigMobileData;
    private boolean mCanConfigMobileData;


    // Wi-Fi entries
    protected WifiEntry mConnectedWifiEntry;
    protected int mWifiEntriesCount;

    // Wi-Fi scanning progress bar
    // Wi-Fi scanning progress bar
    protected boolean mIsProgressBarVisible;
    protected boolean mIsProgressBarVisible;
    protected boolean mIsSearchingHidden;
    protected boolean mIsSearchingHidden;
@@ -315,15 +317,10 @@ public class InternetDialog extends SystemUIDialog implements
        updateWifiToggle(isWifiEnabled, isDeviceLocked);
        updateWifiToggle(isWifiEnabled, isDeviceLocked);
        updateConnectedWifi(isWifiEnabled, isDeviceLocked);
        updateConnectedWifi(isWifiEnabled, isDeviceLocked);


        List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList();
        final int visibility = (isDeviceLocked || !isWifiEnabled || mWifiEntriesCount <= 0)
        final int wifiListVisibility =
                (isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0)
                ? View.GONE : View.VISIBLE;
                ? View.GONE : View.VISIBLE;
        mWifiRecyclerView.setVisibility(wifiListVisibility);
        mWifiRecyclerView.setVisibility(visibility);
        if (wifiListVisibility == View.VISIBLE) {
        mSeeAllLayout.setVisibility(visibility);
            mAdapter.notifyDataSetChanged();
        }
        mSeeAllLayout.setVisibility(wifiListVisibility);
    }
    }


    private void setOnClickListener() {
    private void setOnClickListener() {
@@ -457,8 +454,7 @@ public class InternetDialog extends SystemUIDialog implements
            return;
            return;
        }
        }
        setProgressBarVisible(true);
        setProgressBarVisible(true);
        List<ScanResult> wifiScanResults = mWifiManager.getScanResults();
        if (mConnectedWifiEntry != null || mWifiEntriesCount > 0) {
        if (wifiScanResults != null && wifiScanResults.size() > 0) {
            mHandler.postDelayed(mHideProgressBarRunnable, PROGRESS_DELAY_MS);
            mHandler.postDelayed(mHideProgressBarRunnable, PROGRESS_DELAY_MS);
        } else if (!mIsSearchingHidden) {
        } else if (!mIsSearchingHidden) {
            mHandler.postDelayed(mHideSearchingRunnable, PROGRESS_DELAY_MS);
            mHandler.postDelayed(mHideSearchingRunnable, PROGRESS_DELAY_MS);
@@ -543,8 +539,8 @@ public class InternetDialog extends SystemUIDialog implements
    }
    }


    @Override
    @Override
    @WorkerThread
    public void onDataConnectionStateChanged(int state, int networkType) {
    public void onDataConnectionStateChanged(int state, int networkType) {
        mAdapter.notifyDataSetChanged();
        mHandler.post(() -> updateDialog());
        mHandler.post(() -> updateDialog());
    }
    }


@@ -559,10 +555,16 @@ public class InternetDialog extends SystemUIDialog implements
    }
    }


    @Override
    @Override
    public void onAccessPointsChanged(List<WifiEntry> wifiEntryList, WifiEntry connectedEntry) {
    @WorkerThread
    public void onAccessPointsChanged(@Nullable List<WifiEntry> wifiEntries,
            @Nullable WifiEntry connectedEntry) {
        mConnectedWifiEntry = connectedEntry;
        mConnectedWifiEntry = connectedEntry;
        mWifiEntriesCount = wifiEntries == null ? 0 : wifiEntries.size();
        mAdapter.setWifiEntries(wifiEntries, mWifiEntriesCount);
        mHandler.post(() -> {
            mAdapter.notifyDataSetChanged();
            mAdapter.notifyDataSetChanged();
        mHandler.post(() -> updateDialog());
            updateDialog();
        });
    }
    }


    @Override
    @Override
@@ -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 {
    public enum InternetDialogEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "The Internet dialog became visible on the screen.")
        @UiEvent(doc = "The Internet dialog became visible on the screen.")
        INTERNET_DIALOG_SHOW(843);
        INTERNET_DIALOG_SHOW(843);
+51 −36
Original line number Original line Diff line number Diff line
@@ -32,7 +32,6 @@ import android.net.ConnectivityManager;
import android.net.Network;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.NetworkRequest;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Handler;
import android.provider.Settings;
import android.provider.Settings;
@@ -53,6 +52,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;


import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitor;
@@ -108,6 +108,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
            R.string.all_network_unavailable;
            R.string.all_network_unavailable;
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);


    static final int MAX_WIFI_ENTRY_COUNT = 4;

    private WifiManager mWifiManager;
    private WifiManager mWifiManager;
    private Context mContext;
    private Context mContext;
    private SubscriptionManager mSubscriptionManager;
    private SubscriptionManager mSubscriptionManager;
@@ -122,7 +124,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
    private AccessPointController mAccessPointController;
    private AccessPointController mAccessPointController;
    private IntentFilter mConnectionStateFilter;
    private IntentFilter mConnectionStateFilter;
    private InternetDialogCallback mCallback;
    private InternetDialogCallback mCallback;
    private List<WifiEntry> mWifiEntry;
    private WifiEntry mConnectedEntry;
    private int mWifiEntriesCount;
    private UiEventLogger mUiEventLogger;
    private UiEventLogger mUiEventLogger;
    private BroadcastDispatcher mBroadcastDispatcher;
    private BroadcastDispatcher mBroadcastDispatcher;
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@@ -132,8 +135,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
    @VisibleForTesting
    @VisibleForTesting
    protected ActivityStarter mActivityStarter;
    protected ActivityStarter mActivityStarter;
    @VisibleForTesting
    @VisibleForTesting
    protected WifiEntry mConnectedEntry;
    @VisibleForTesting
    protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
    protected SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
    @VisibleForTesting
    @VisibleForTesting
    protected InternetTelephonyCallback mInternetTelephonyCallback;
    protected InternetTelephonyCallback mInternetTelephonyCallback;
@@ -141,9 +142,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
    protected WifiUtils.InternetIconInjector mWifiIconInjector;
    protected WifiUtils.InternetIconInjector mWifiIconInjector;
    @VisibleForTesting
    @VisibleForTesting
    protected boolean mCanConfigWifi;
    protected boolean mCanConfigWifi;

    @VisibleForTesting
    @VisibleForTesting
    KeyguardStateController mKeyguardStateController;
    protected KeyguardStateController mKeyguardStateController;


    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
            new KeyguardUpdateMonitorCallback() {
@@ -185,8 +185,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardStateController = keyguardStateController;
        mKeyguardStateController = keyguardStateController;
        mConnectionStateFilter = new IntentFilter();
        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);
        mConnectionStateFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
        mUiEventLogger = uiEventLogger;
        mUiEventLogger = uiEventLogger;
        mActivityStarter = starter;
        mActivityStarter = starter;
@@ -291,8 +289,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
            return mContext.getText(SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS);
            return mContext.getText(SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS);
        }
        }


        final List<ScanResult> wifiList = mWifiManager.getScanResults();
        if (mConnectedEntry != null || mWifiEntriesCount > 0) {
        if (wifiList != null && wifiList.size() != 0) {
            return mCanConfigWifi ? mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT) : null;
            return mCanConfigWifi ? mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT) : null;
        }
        }


@@ -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() {
    WifiManager getWifiManager() {
        return mWifiManager;
        return mWifiManager;
    }
    }
@@ -765,22 +750,33 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
        }
        }
    }
    }


    void scanWifiAccessPoints() {
    private void scanWifiAccessPoints() {
        if (mCanConfigWifi) {
        if (mCanConfigWifi) {
            mAccessPointController.scanForAccessPoints();
            mAccessPointController.scanForAccessPoints();
        }
        }
    }
    }


    @Override
    @Override
    @WorkerThread
    public void onAccessPointsChanged(List<WifiEntry> accessPoints) {
    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;
            return;
        }
        }


        boolean hasConnectedWifi = false;
        boolean hasConnectedWifi = false;
        mWifiEntry = accessPoints;
        final int accessPointSize = accessPoints.size();
        for (WifiEntry wifiEntry : accessPoints) {
        for (int i = 0; i < accessPointSize; i++) {
            if (wifiEntry.getConnectedState() == WifiEntry.CONNECTED_STATE_CONNECTED) {
            WifiEntry wifiEntry = accessPoints.get(i);
            if (wifiEntry.isDefaultNetwork() && wifiEntry.hasInternetAccess()) {
                mConnectedEntry = wifiEntry;
                mConnectedEntry = wifiEntry;
                hasConnectedWifi = true;
                hasConnectedWifi = true;
                break;
                break;
@@ -790,7 +786,23 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
            mConnectedEntry = null;
            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
    @Override
@@ -843,8 +855,17 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,


    private class DataConnectivityListener extends ConnectivityManager.NetworkCallback {
    private class DataConnectivityListener extends ConnectivityManager.NetworkCallback {
        @Override
        @Override
        @WorkerThread
        public void onCapabilitiesChanged(@NonNull Network network,
        public void onCapabilitiesChanged(@NonNull Network network,
                @NonNull NetworkCapabilities networkCapabilities) {
                @NonNull NetworkCapabilities networkCapabilities) {
            if (mCanConfigWifi) {
                for (int transport : networkCapabilities.getTransportTypes()) {
                    if (transport == NetworkCapabilities.TRANSPORT_WIFI) {
                        scanWifiAccessPoints();
                        break;
                    }
                }
            }
            final Network activeNetwork = mConnectivityManager.getActiveNetwork();
            final Network activeNetwork = mConnectivityManager.getActiveNetwork();
            if (activeNetwork != null && activeNetwork.equals(network)) {
            if (activeNetwork != null && activeNetwork.equals(network)) {
                // update UI
                // update UI
@@ -857,11 +878,6 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            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 (action.equals(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) {
                if (DEBUG) {
                if (DEBUG) {
                    Log.d(TAG, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED");
                    Log.d(TAG, "ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED");
@@ -917,8 +933,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,


        void dismissDialog();
        void dismissDialog();


        void onAccessPointsChanged(List<WifiEntry> wifiEntryList, WifiEntry connectedEntry);
        void onAccessPointsChanged(@Nullable List<WifiEntry> wifiEntries,

                @Nullable WifiEntry connectedEntry);
        void onWifiStateReceived(Context context, Intent intent);
    }
    }
}
}
+24 −34
Original line number Original line Diff line number Diff line
@@ -2,8 +2,11 @@ package com.android.systemui.qs.tiles.dialog;


import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
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.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


@@ -24,6 +27,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;


import java.util.Arrays;
import java.util.Arrays;
import java.util.List;


@SmallTest
@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWith(AndroidTestingRunner.class)
@@ -35,6 +39,8 @@ public class InternetAdapterTest extends SysuiTestCase {
    @Mock
    @Mock
    private WifiEntry mInternetWifiEntry;
    private WifiEntry mInternetWifiEntry;
    @Mock
    @Mock
    private List<WifiEntry> mWifiEntries;
    @Mock
    private WifiEntry mWifiEntry;
    private WifiEntry mWifiEntry;
    @Mock
    @Mock
    private InternetDialogController mInternetDialogController;
    private InternetDialogController mInternetDialogController;
@@ -56,43 +62,17 @@ public class InternetAdapterTest extends SysuiTestCase {


        mInternetAdapter = new InternetAdapter(mInternetDialogController);
        mInternetAdapter = new InternetAdapter(mInternetDialogController);
        mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
        mViewHolder = mInternetAdapter.onCreateViewHolder(new LinearLayout(mContext), 0);
        when(mInternetDialogController.getInternetWifiEntry()).thenReturn(mInternetWifiEntry);
        mInternetAdapter.setWifiEntries(Arrays.asList(mWifiEntry), 1 /* wifiEntriesCount */);
        when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
        mViewHolder.mWifiIconInjector = mWifiIconInjector;
        mViewHolder.mWifiIconInjector = mWifiIconInjector;
    }
    }


    @Test
    @Test
    public void getItemCount_withApmOnWifiOnNoInternetWifi_returnFour() {
    public void getItemCount_returnWifiEntriesCount() {
        // The preconditions WiFi ON is already in setUp()
        for (int i = 0; i < InternetDialogController.MAX_WIFI_ENTRY_COUNT; i++) {
        when(mInternetDialogController.getInternetWifiEntry()).thenReturn(null);
            mInternetAdapter.setWifiEntries(mWifiEntries, i /* wifiEntriesCount */);
        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);


        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
    @Test
@@ -118,7 +98,17 @@ public class InternetAdapterTest extends SysuiTestCase {
    }
    }


    @Test
    @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);
        when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(false);


        mInternetAdapter.onBindViewHolder(mViewHolder, 0);
        mInternetAdapter.onBindViewHolder(mViewHolder, 0);
@@ -127,7 +117,7 @@ public class InternetAdapterTest extends SysuiTestCase {
    }
    }


    @Test
    @Test
    public void onBindViewHolder_bindNoDefaultWifiNetwork_getIconWithNoInternet() {
    public void onBindViewHolder_shouldShowXLevelIcon_getIconWithNoInternet() {
        when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true);
        when(mWifiEntry.shouldShowXLevelIcon()).thenReturn(true);


        mInternetAdapter.onBindViewHolder(mViewHolder, 0);
        mInternetAdapter.onBindViewHolder(mViewHolder, 0);
+157 −51

File changed.

Preview size limit exceeded, changes collapsed.

Loading