Merge "Use Wi-Fi state cache in Internet Panel" into tm-dev am: ac3033fd40
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17821952 Change-Id: Iecc28017170a74bde67f8334661afd173474fc28 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -24,7 +24,6 @@ import android.content.res.TypedArray;
|
|||||||
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.WifiManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.telephony.ServiceState;
|
import android.telephony.ServiceState;
|
||||||
@@ -90,8 +89,6 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected InternetAdapter mAdapter;
|
protected InternetAdapter mAdapter;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected WifiManager mWifiManager;
|
|
||||||
@VisibleForTesting
|
|
||||||
protected View mDialogView;
|
protected View mDialogView;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected boolean mCanConfigWifi;
|
protected boolean mCanConfigWifi;
|
||||||
@@ -179,7 +176,6 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
mSubscriptionManager = mInternetDialogController.getSubscriptionManager();
|
mSubscriptionManager = mInternetDialogController.getSubscriptionManager();
|
||||||
mDefaultDataSubId = mInternetDialogController.getDefaultDataSubscriptionId();
|
mDefaultDataSubId = mInternetDialogController.getDefaultDataSubscriptionId();
|
||||||
mTelephonyManager = mInternetDialogController.getTelephonyManager();
|
mTelephonyManager = mInternetDialogController.getTelephonyManager();
|
||||||
mWifiManager = mInternetDialogController.getWifiManager();
|
|
||||||
mCanConfigMobileData = canConfigMobileData;
|
mCanConfigMobileData = canConfigMobileData;
|
||||||
mCanConfigWifi = canConfigWifi;
|
mCanConfigWifi = canConfigWifi;
|
||||||
mCanChangeWifiState = WifiEnterpriseRestrictionUtils.isChangeWifiStateAllowed(context);
|
mCanChangeWifiState = WifiEnterpriseRestrictionUtils.isChangeWifiStateAllowed(context);
|
||||||
@@ -332,7 +328,7 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
|
|
||||||
showProgressBar();
|
showProgressBar();
|
||||||
final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked();
|
final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked();
|
||||||
final boolean isWifiEnabled = mWifiManager != null && mWifiManager.isWifiEnabled();
|
final boolean isWifiEnabled = mInternetDialogController.isWifiEnabled();
|
||||||
final boolean isWifiScanEnabled = mInternetDialogController.isWifiScanEnabled();
|
final boolean isWifiScanEnabled = mInternetDialogController.isWifiScanEnabled();
|
||||||
updateWifiToggle(isWifiEnabled, isDeviceLocked);
|
updateWifiToggle(isWifiEnabled, isDeviceLocked);
|
||||||
updateConnectedWifi(isWifiEnabled, isDeviceLocked);
|
updateConnectedWifi(isWifiEnabled, isDeviceLocked);
|
||||||
@@ -362,9 +358,8 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
mSeeAllLayout.setOnClickListener(this::onClickSeeMoreButton);
|
mSeeAllLayout.setOnClickListener(this::onClickSeeMoreButton);
|
||||||
mWiFiToggle.setOnCheckedChangeListener(
|
mWiFiToggle.setOnCheckedChangeListener(
|
||||||
(buttonView, isChecked) -> {
|
(buttonView, isChecked) -> {
|
||||||
if (mWifiManager == null) return;
|
if (mInternetDialogController.isWifiEnabled() == isChecked) return;
|
||||||
buttonView.setChecked(isChecked);
|
mInternetDialogController.setWifiEnabled(isChecked);
|
||||||
mWifiManager.setWifiEnabled(isChecked);
|
|
||||||
});
|
});
|
||||||
mDoneButton.setOnClickListener(v -> dismiss());
|
mDoneButton.setOnClickListener(v -> dismiss());
|
||||||
mAirplaneModeButton.setOnClickListener(v -> {
|
mAirplaneModeButton.setOnClickListener(v -> {
|
||||||
@@ -388,7 +383,7 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
Log.d(TAG, "setMobileDataLayout, isCarrierNetworkActive = " + isCarrierNetworkActive);
|
Log.d(TAG, "setMobileDataLayout, isCarrierNetworkActive = " + isCarrierNetworkActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isWifiEnabled = mWifiManager != null && mWifiManager.isWifiEnabled();
|
boolean isWifiEnabled = mInternetDialogController.isWifiEnabled();
|
||||||
if (!mInternetDialogController.hasActiveSubId()
|
if (!mInternetDialogController.hasActiveSubId()
|
||||||
&& (!isWifiEnabled || !isCarrierNetworkActive)) {
|
&& (!isWifiEnabled || !isCarrierNetworkActive)) {
|
||||||
mMobileNetworkLayout.setVisibility(View.GONE);
|
mMobileNetworkLayout.setVisibility(View.GONE);
|
||||||
@@ -444,7 +439,9 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
private void updateWifiToggle(boolean isWifiEnabled, boolean isDeviceLocked) {
|
private void updateWifiToggle(boolean isWifiEnabled, boolean isDeviceLocked) {
|
||||||
mWiFiToggle.setChecked(isWifiEnabled);
|
if (mWiFiToggle.isChecked() != isWifiEnabled) {
|
||||||
|
mWiFiToggle.setChecked(isWifiEnabled);
|
||||||
|
}
|
||||||
if (isDeviceLocked) {
|
if (isDeviceLocked) {
|
||||||
mWifiToggleTitleText.setTextAppearance((mConnectedWifiEntry != null)
|
mWifiToggleTitleText.setTextAppearance((mConnectedWifiEntry != null)
|
||||||
? R.style.TextAppearance_InternetDialog_Active
|
? R.style.TextAppearance_InternetDialog_Active
|
||||||
@@ -572,7 +569,7 @@ public class InternetDialog extends SystemUIDialog implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void showProgressBar() {
|
protected void showProgressBar() {
|
||||||
if (mWifiManager == null || !mWifiManager.isWifiEnabled()
|
if (!mInternetDialogController.isWifiEnabled()
|
||||||
|| mInternetDialogController.isDeviceLocked()) {
|
|| mInternetDialogController.isDeviceLocked()) {
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;
|
|||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
|
import android.annotation.AnyThread;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -157,6 +158,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
|||||||
private LocationController mLocationController;
|
private LocationController mLocationController;
|
||||||
private DialogLaunchAnimator mDialogLaunchAnimator;
|
private DialogLaunchAnimator mDialogLaunchAnimator;
|
||||||
private boolean mHasWifiEntries;
|
private boolean mHasWifiEntries;
|
||||||
|
private WifiStateWorker mWifiStateWorker;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final float TOAST_PARAMS_HORIZONTAL_WEIGHT = 1.0f;
|
static final float TOAST_PARAMS_HORIZONTAL_WEIGHT = 1.0f;
|
||||||
@@ -210,7 +212,9 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
|||||||
@Background Handler workerHandler,
|
@Background Handler workerHandler,
|
||||||
CarrierConfigTracker carrierConfigTracker,
|
CarrierConfigTracker carrierConfigTracker,
|
||||||
LocationController locationController,
|
LocationController locationController,
|
||||||
DialogLaunchAnimator dialogLaunchAnimator) {
|
DialogLaunchAnimator dialogLaunchAnimator,
|
||||||
|
WifiStateWorker wifiStateWorker
|
||||||
|
) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Init InternetDialogController");
|
Log.d(TAG, "Init InternetDialogController");
|
||||||
}
|
}
|
||||||
@@ -241,6 +245,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
|||||||
mLocationController = locationController;
|
mLocationController = locationController;
|
||||||
mDialogLaunchAnimator = dialogLaunchAnimator;
|
mDialogLaunchAnimator = dialogLaunchAnimator;
|
||||||
mConnectedWifiInternetMonitor = new ConnectedWifiInternetMonitor();
|
mConnectedWifiInternetMonitor = new ConnectedWifiInternetMonitor();
|
||||||
|
mWifiStateWorker = wifiStateWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onStart(@NonNull InternetDialogCallback callback, boolean canConfigWifi) {
|
void onStart(@NonNull InternetDialogCallback callback, boolean canConfigWifi) {
|
||||||
@@ -323,7 +328,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
CharSequence getSubtitleText(boolean isProgressBarVisible) {
|
CharSequence getSubtitleText(boolean isProgressBarVisible) {
|
||||||
if (mCanConfigWifi && !mWifiManager.isWifiEnabled()) {
|
if (mCanConfigWifi && !isWifiEnabled()) {
|
||||||
// When Wi-Fi is disabled.
|
// When Wi-Fi is disabled.
|
||||||
// Sub-Title: Wi-Fi is off
|
// Sub-Title: Wi-Fi is off
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -648,6 +653,27 @@ public class InternetDialogController implements AccessPointController.AccessPoi
|
|||||||
startActivity(intent, view);
|
startActivity(intent, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable Wi-Fi.
|
||||||
|
*
|
||||||
|
* @param enabled {@code true} to enable, {@code false} to disable.
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
public void setWifiEnabled(boolean enabled) {
|
||||||
|
mWifiStateWorker.setWifiEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether Wi-Fi is enabled or disabled.
|
||||||
|
*
|
||||||
|
* @return {@code true} if Wi-Fi is enabled or enabling
|
||||||
|
* @see WifiManager#getWifiState()
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
public boolean isWifiEnabled() {
|
||||||
|
return mWifiStateWorker.isWifiEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
void connectCarrierNetwork() {
|
void connectCarrierNetwork() {
|
||||||
final MergedCarrierEntry mergedCarrierEntry =
|
final MergedCarrierEntry mergedCarrierEntry =
|
||||||
mAccessPointController.getMergedCarrierEntry();
|
mAccessPointController.getMergedCarrierEntry();
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.qs.tiles.dialog;
|
||||||
|
|
||||||
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_STATE;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_CHANGED_ACTION;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_DISABLING;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.AnyThread;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||||
|
import com.android.systemui.dagger.SysUISingleton;
|
||||||
|
import com.android.systemui.dagger.qualifiers.Background;
|
||||||
|
import com.android.systemui.util.concurrency.DelayableExecutor;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Worker for the Wi-Fi enabled state cache.
|
||||||
|
*/
|
||||||
|
@SysUISingleton
|
||||||
|
public class WifiStateWorker extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String TAG = "WifiStateWorker";
|
||||||
|
|
||||||
|
private DelayableExecutor mBackgroundExecutor;
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
private int mWifiState = WIFI_STATE_DISABLED;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public WifiStateWorker(
|
||||||
|
BroadcastDispatcher broadcastDispatcher,
|
||||||
|
@Background DelayableExecutor backgroundExecutor,
|
||||||
|
@Nullable WifiManager wifiManager) {
|
||||||
|
mWifiManager = wifiManager;
|
||||||
|
mBackgroundExecutor = backgroundExecutor;
|
||||||
|
|
||||||
|
broadcastDispatcher.registerReceiver(this, new IntentFilter(WIFI_STATE_CHANGED_ACTION));
|
||||||
|
mBackgroundExecutor.execute(() -> {
|
||||||
|
if (mWifiManager == null) return;
|
||||||
|
|
||||||
|
mWifiState = mWifiManager.getWifiState();
|
||||||
|
Log.i(TAG, "WifiManager.getWifiState():" + mWifiState);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable Wi-Fi.
|
||||||
|
*
|
||||||
|
* @param enabled {@code true} to enable, {@code false} to disable.
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
public void setWifiEnabled(boolean enabled) {
|
||||||
|
mBackgroundExecutor.execute(() -> {
|
||||||
|
if (mWifiManager == null) return;
|
||||||
|
|
||||||
|
mWifiState = (enabled) ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING;
|
||||||
|
if (!mWifiManager.setWifiEnabled(enabled)) {
|
||||||
|
Log.e(TAG, "Failed to WifiManager.setWifiEnabled(" + enabled + ");");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Wi-Fi enabled state.
|
||||||
|
*
|
||||||
|
* @return One of {@link WifiManager#WIFI_STATE_DISABLED},
|
||||||
|
* {@link WifiManager#WIFI_STATE_DISABLING}, {@link WifiManager#WIFI_STATE_ENABLED},
|
||||||
|
* {@link WifiManager#WIFI_STATE_ENABLING}
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
public int getWifiState() {
|
||||||
|
return mWifiState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether Wi-Fi is enabled or disabled.
|
||||||
|
*
|
||||||
|
* @return {@code true} if Wi-Fi is enabled or enabling
|
||||||
|
* @see WifiManager#getWifiState()
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
public boolean isWifiEnabled() {
|
||||||
|
return (mWifiState == WIFI_STATE_ENABLED || mWifiState == WIFI_STATE_ENABLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent == null) return;
|
||||||
|
|
||||||
|
if (WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
|
final int wifiState = intent.getIntExtra(EXTRA_WIFI_STATE, WIFI_STATE_DISABLED);
|
||||||
|
if (wifiState == WIFI_STATE_UNKNOWN) return;
|
||||||
|
|
||||||
|
mWifiState = wifiState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -138,6 +138,8 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
private DialogLaunchAnimator mDialogLaunchAnimator;
|
private DialogLaunchAnimator mDialogLaunchAnimator;
|
||||||
@Mock
|
@Mock
|
||||||
private View mDialogLaunchView;
|
private View mDialogLaunchView;
|
||||||
|
@Mock
|
||||||
|
private WifiStateWorker mWifiStateWorker;
|
||||||
|
|
||||||
private TestableResources mTestableResources;
|
private TestableResources mTestableResources;
|
||||||
private InternetDialogController mInternetDialogController;
|
private InternetDialogController mInternetDialogController;
|
||||||
@@ -166,6 +168,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
when(mSystemUIToast.getView()).thenReturn(mToastView);
|
when(mSystemUIToast.getView()).thenReturn(mToastView);
|
||||||
when(mSystemUIToast.getGravity()).thenReturn(GRAVITY_FLAGS);
|
when(mSystemUIToast.getGravity()).thenReturn(GRAVITY_FLAGS);
|
||||||
when(mSystemUIToast.getInAnimation()).thenReturn(mAnimator);
|
when(mSystemUIToast.getInAnimation()).thenReturn(mAnimator);
|
||||||
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mInternetDialogController = new InternetDialogController(mContext,
|
mInternetDialogController = new InternetDialogController(mContext,
|
||||||
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
|
||||||
@@ -173,7 +176,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher,
|
mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher,
|
||||||
mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController,
|
mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController,
|
||||||
mWindowManager, mToastFactory, mWorkerHandler, mCarrierConfigTracker,
|
mWindowManager, mToastFactory, mWorkerHandler, mCarrierConfigTracker,
|
||||||
mLocationController, mDialogLaunchAnimator);
|
mLocationController, mDialogLaunchAnimator, mWifiStateWorker);
|
||||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
|
||||||
mInternetDialogController.mOnSubscriptionsChangedListener);
|
mInternetDialogController.mOnSubscriptionsChangedListener);
|
||||||
mInternetDialogController.onStart(mInternetDialogCallback, true);
|
mInternetDialogController.onStart(mInternetDialogCallback, true);
|
||||||
@@ -239,7 +242,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withApmOnAndWifiOff_returnWifiIsOff() {
|
public void getSubtitleText_withApmOnAndWifiOff_returnWifiIsOff() {
|
||||||
fakeAirplaneModeEnabled(true);
|
fakeAirplaneModeEnabled(true);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getSubtitleText(false))
|
assertThat(mInternetDialogController.getSubtitleText(false))
|
||||||
.isEqualTo(getResourcesString("wifi_is_off"));
|
.isEqualTo(getResourcesString("wifi_is_off"));
|
||||||
@@ -254,7 +257,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withWifiOff_returnWifiIsOff() {
|
public void getSubtitleText_withWifiOff_returnWifiIsOff() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getSubtitleText(false))
|
assertThat(mInternetDialogController.getSubtitleText(false))
|
||||||
.isEqualTo(getResourcesString("wifi_is_off"));
|
.isEqualTo(getResourcesString("wifi_is_off"));
|
||||||
@@ -269,7 +272,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withNoWifiEntry_returnSearchWifi() {
|
public void getSubtitleText_withNoWifiEntry_returnSearchWifi() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getSubtitleText(true))
|
assertThat(mInternetDialogController.getSubtitleText(true))
|
||||||
@@ -286,7 +289,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
public void getSubtitleText_withWifiEntry_returnTapToConnect() {
|
public void getSubtitleText_withWifiEntry_returnTapToConnect() {
|
||||||
// The preconditions WiFi Entries is already in setUp()
|
// The preconditions WiFi Entries is already in setUp()
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mInternetDialogController.getSubtitleText(false))
|
assertThat(mInternetDialogController.getSubtitleText(false))
|
||||||
.isEqualTo(getResourcesString("tap_a_network_to_connect"));
|
.isEqualTo(getResourcesString("tap_a_network_to_connect"));
|
||||||
@@ -301,7 +304,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_deviceLockedWithWifiOn_returnUnlockToViewNetworks() {
|
public void getSubtitleText_deviceLockedWithWifiOn_returnUnlockToViewNetworks() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false),
|
assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false),
|
||||||
@@ -311,7 +314,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withNoService_returnNoNetworksAvailable() {
|
public void getSubtitleText_withNoService_returnNoNetworksAvailable() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
||||||
|
|
||||||
doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getState();
|
doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getState();
|
||||||
@@ -325,7 +328,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withMobileDataDisabled_returnNoOtherAvailable() {
|
public void getSubtitleText_withMobileDataDisabled_returnNoOtherAvailable() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
||||||
|
|
||||||
doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState();
|
doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState();
|
||||||
@@ -346,7 +349,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void getSubtitleText_withCarrierNetworkActiveOnly_returnNoOtherAvailable() {
|
public void getSubtitleText_withCarrierNetworkActiveOnly_returnNoOtherAvailable() {
|
||||||
fakeAirplaneModeEnabled(false);
|
fakeAirplaneModeEnabled(false);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mWifiStateWorker.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
mInternetDialogController.onAccessPointsChanged(null /* accessPoints */);
|
||||||
when(mMergedCarrierEntry.isDefaultNetwork()).thenReturn(true);
|
when(mMergedCarrierEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
@@ -64,8 +63,6 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mWifiManager;
|
|
||||||
@Mock
|
|
||||||
private WifiEntry mInternetWifiEntry;
|
private WifiEntry mInternetWifiEntry;
|
||||||
@Mock
|
@Mock
|
||||||
private List<WifiEntry> mWifiEntries;
|
private List<WifiEntry> mWifiEntries;
|
||||||
@@ -97,7 +94,6 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
|
||||||
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
when(mInternetWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
|
||||||
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
when(mInternetWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
|
||||||
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
when(mInternetWifiEntry.isDefaultNetwork()).thenReturn(true);
|
||||||
@@ -107,7 +103,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
when(mInternetDialogController.getMobileNetworkTitle()).thenReturn(MOBILE_NETWORK_TITLE);
|
when(mInternetDialogController.getMobileNetworkTitle()).thenReturn(MOBILE_NETWORK_TITLE);
|
||||||
when(mInternetDialogController.getMobileNetworkSummary())
|
when(mInternetDialogController.getMobileNetworkSummary())
|
||||||
.thenReturn(MOBILE_NETWORK_SUMMARY);
|
.thenReturn(MOBILE_NETWORK_SUMMARY);
|
||||||
when(mInternetDialogController.getWifiManager()).thenReturn(mWifiManager);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mMockitoSession = ExtendedMockito.mockitoSession()
|
mMockitoSession = ExtendedMockito.mockitoSession()
|
||||||
.spyStatic(WifiEnterpriseRestrictionUtils.class)
|
.spyStatic(WifiEnterpriseRestrictionUtils.class)
|
||||||
@@ -232,7 +228,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
// Carrier network should be gone if airplane mode ON and Wi-Fi is off.
|
// Carrier network should be gone if airplane mode ON and Wi-Fi is off.
|
||||||
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
|
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
mInternetDialog.updateDialog(true);
|
mInternetDialog.updateDialog(true);
|
||||||
|
|
||||||
@@ -241,7 +237,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
// Carrier network should be visible if airplane mode ON and Wi-Fi is ON.
|
// Carrier network should be visible if airplane mode ON and Wi-Fi is ON.
|
||||||
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
|
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
|
||||||
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
when(mInternetDialogController.isAirplaneModeEnabled()).thenReturn(true);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mInternetDialog.updateDialog(true);
|
mInternetDialog.updateDialog(true);
|
||||||
|
|
||||||
@@ -468,7 +464,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOffAndWifiScanOff_hideWifiScanNotify() {
|
public void updateDialog_wifiOffAndWifiScanOff_hideWifiScanNotify() {
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(false);
|
||||||
|
|
||||||
mInternetDialog.updateDialog(false);
|
mInternetDialog.updateDialog(false);
|
||||||
@@ -478,7 +474,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOffAndWifiScanOnAndDeviceLocked_hideWifiScanNotify() {
|
public void updateDialog_wifiOffAndWifiScanOnAndDeviceLocked_hideWifiScanNotify() {
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(true);
|
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(true);
|
||||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
|
||||||
|
|
||||||
@@ -489,7 +485,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateDialog_wifiOffAndWifiScanOnAndDeviceUnlocked_showWifiScanNotify() {
|
public void updateDialog_wifiOffAndWifiScanOnAndDeviceUnlocked_showWifiScanNotify() {
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(true);
|
when(mInternetDialogController.isWifiScanEnabled()).thenReturn(true);
|
||||||
when(mInternetDialogController.isDeviceLocked()).thenReturn(false);
|
when(mInternetDialogController.isDeviceLocked()).thenReturn(false);
|
||||||
|
|
||||||
@@ -501,6 +497,26 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
assertThat(wifiScanNotifyText.getMovementMethod()).isNotNull();
|
assertThat(wifiScanNotifyText.getMovementMethod()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateDialog_wifiIsDisabled_uncheckWifiSwitch() {
|
||||||
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
|
mWifiToggleSwitch.setChecked(true);
|
||||||
|
|
||||||
|
mInternetDialog.updateDialog(false);
|
||||||
|
|
||||||
|
assertThat(mWifiToggleSwitch.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateDialog_wifiIsEnabled_checkWifiSwitch() {
|
||||||
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(true);
|
||||||
|
mWifiToggleSwitch.setChecked(false);
|
||||||
|
|
||||||
|
mInternetDialog.updateDialog(false);
|
||||||
|
|
||||||
|
assertThat(mWifiToggleSwitch.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onClickSeeMoreButton_clickSeeAll_verifyLaunchNetworkSetting() {
|
public void onClickSeeMoreButton_clickSeeAll_verifyLaunchNetworkSetting() {
|
||||||
mSeeAll.performClick();
|
mSeeAll.performClick();
|
||||||
@@ -512,7 +528,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
public void showProgressBar_wifiDisabled_hideProgressBar() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(false);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
|
|
||||||
@@ -534,7 +550,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
mInternetDialog.showProgressBar();
|
mInternetDialog.showProgressBar();
|
||||||
|
|
||||||
@@ -553,7 +569,7 @@ public class InternetDialogTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void showProgressBar_wifiEnabledWithoutWifiEntries_showProgressBarThenHideSearch() {
|
public void showProgressBar_wifiEnabledWithoutWifiEntries_showProgressBarThenHideSearch() {
|
||||||
Mockito.reset(mHandler);
|
Mockito.reset(mHandler);
|
||||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
when(mInternetDialogController.isWifiEnabled()).thenReturn(true);
|
||||||
mInternetDialog.mConnectedWifiEntry = null;
|
mInternetDialog.mConnectedWifiEntry = null;
|
||||||
mInternetDialog.mWifiEntriesCount = 0;
|
mInternetDialog.mWifiEntriesCount = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.systemui.qs.tiles.dialog;
|
||||||
|
|
||||||
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_STATE;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_CHANGED_ACTION;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_DISABLING;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING;
|
||||||
|
import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN;
|
||||||
|
|
||||||
|
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.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.testing.AndroidTestingRunner;
|
||||||
|
|
||||||
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
|
import com.android.systemui.SysuiTestCase;
|
||||||
|
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||||
|
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||||
|
import com.android.systemui.util.time.FakeSystemClock;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
@RunWith(AndroidTestingRunner.class)
|
||||||
|
@SmallTest
|
||||||
|
public class WifiStateWorkerTest extends SysuiTestCase {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public MockitoRule mRule = MockitoJUnit.rule();
|
||||||
|
@Mock
|
||||||
|
private BroadcastDispatcher mBroadcastDispatcher;
|
||||||
|
@Mock
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
@Mock
|
||||||
|
private Intent mIntent;
|
||||||
|
|
||||||
|
private WifiStateWorker mWifiStateWorker;
|
||||||
|
private FakeExecutor mBackgroundExecutor = new FakeExecutor(new FakeSystemClock());
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
when(mWifiManager.setWifiEnabled(anyBoolean())).thenReturn(true);
|
||||||
|
when(mWifiManager.getWifiState()).thenReturn(WIFI_STATE_ENABLED);
|
||||||
|
when(mIntent.getAction()).thenReturn(WIFI_STATE_CHANGED_ACTION);
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLED);
|
||||||
|
|
||||||
|
mWifiStateWorker = new WifiStateWorker(mBroadcastDispatcher, mBackgroundExecutor,
|
||||||
|
mWifiManager);
|
||||||
|
mBackgroundExecutor.runAllReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void constructor_shouldGetWifiState() {
|
||||||
|
verify(mWifiManager).getWifiState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setWifiEnabled_wifiManagerIsNull_shouldNotSetWifiEnabled() {
|
||||||
|
mWifiStateWorker = new WifiStateWorker(mBroadcastDispatcher, mBackgroundExecutor,
|
||||||
|
null /* wifiManager */);
|
||||||
|
|
||||||
|
mWifiStateWorker.setWifiEnabled(true);
|
||||||
|
mBackgroundExecutor.runAllReady();
|
||||||
|
|
||||||
|
verify(mWifiManager, never()).setWifiEnabled(anyBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setWifiEnabled_enabledIsTrue_shouldSetWifiEnabled() {
|
||||||
|
mWifiStateWorker.setWifiEnabled(true);
|
||||||
|
mBackgroundExecutor.runAllReady();
|
||||||
|
|
||||||
|
verify(mWifiManager).setWifiEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setWifiEnabled_enabledIsFalse_shouldSetWifiDisabled() {
|
||||||
|
mWifiStateWorker.setWifiEnabled(false);
|
||||||
|
mBackgroundExecutor.runAllReady();
|
||||||
|
|
||||||
|
verify(mWifiManager).setWifiEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiState_receiveWifiStateDisabling_getWifiStateDisabling() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_DISABLING);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_DISABLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiState_receiveWifiStateDisabled_getWifiStateDisabled() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_DISABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiState_receiveWifiStateEnabling_getWifiStateEnabling() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLING);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_ENABLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiState_receiveWifiStateEnabled_getWifiStateEnabled() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWifiState_receiveWifiStateUnknown_ignoreTheIntent() {
|
||||||
|
// Update the Wi-Fi state to WIFI_STATE_DISABLED
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_DISABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_DISABLED);
|
||||||
|
|
||||||
|
// Receiver WIFI_STATE_UNKNOWN
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_UNKNOWN);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
// Ignore the intent and keep the Wi-Fi state to WIFI_STATE_DISABLED
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_DISABLED);
|
||||||
|
|
||||||
|
// Update the Wi-Fi state to WIFI_STATE_ENABLED
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_ENABLED);
|
||||||
|
|
||||||
|
// Receiver WIFI_STATE_UNKNOWN change
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_UNKNOWN);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
// Ignore the intent and keep the Wi-Fi state to WIFI_STATE_ENABLED
|
||||||
|
assertThat(mWifiStateWorker.getWifiState()).isEqualTo(WIFI_STATE_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiEnabled_receiveWifiStateDisabling_returnFalse() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_DISABLING);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.isWifiEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiEnabled_receiveWifiStateDisabled_returnFalse() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_DISABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.isWifiEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiEnabled_receiveWifiStateEnabling_returnTrue() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLING);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.isWifiEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isWifiEnabled_receiveWifiStateEnabled_returnTrue() {
|
||||||
|
when(mIntent.getIntExtra(eq(EXTRA_WIFI_STATE), anyInt())).thenReturn(WIFI_STATE_ENABLED);
|
||||||
|
mWifiStateWorker.onReceive(mContext, mIntent);
|
||||||
|
|
||||||
|
assertThat(mWifiStateWorker.isWifiEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user