summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNagendra Prasad Nagarle Basavaraju <nagendranb@google.com>2023-03-06 09:48:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-03-06 09:48:03 +0000
commitf8a66c5a6a07ac4b394cfc969621718edbf6d5ea (patch)
treeeb64ca3dc556141f445481602c4570e6eb68b057
parenta06afb0a3373a8a6430ae9e82be9cc526c647cbd (diff)
parent5fec6580da91b02c5ace7fa3d506ec25bda1a20a (diff)
downloadTelephony-f8a66c5a6a07ac4b394cfc969621718edbf6d5ea.tar.gz
[QNS]WifiQualityMonitor Issue am: 5fec6580da
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/Telephony/+/21747579 Change-Id: Ieb2be7dee7e4dfca7801cd18f8a06db34b025ce4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/QualityMonitor.java4
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/WifiQualityMonitor.java204
-rw-r--r--services/QualifiedNetworksService/tests/src/com/android/telephony/qns/WifiQualityMonitorTest.java158
3 files changed, 210 insertions, 156 deletions
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/QualityMonitor.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/QualityMonitor.java
index 5242b68..ffc2091 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/QualityMonitor.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/QualityMonitor.java
@@ -36,11 +36,7 @@ abstract class QualityMonitor {
protected static final int EVENT_WIFI_STATE_CHANGED = BASE + 3;
protected static final int EVENT_WIFI_NOTIFY_TIMER_EXPIRED = BASE + 4;
protected static final int EVENT_SUBSCRIPTION_ID_CHANGED = BASE + 5;
-
- protected static final int BACKHAUL_TIMER_DEFAULT = 3000;
-
private final String mTag;
-
protected Context mContext;
protected final HashMap<String, IThresholdListener> mThresholdCallbackMap = new HashMap<>();
protected final ConcurrentHashMap<String, List<Threshold>> mThresholdsList =
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/WifiQualityMonitor.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/WifiQualityMonitor.java
index bc8b8fd..bf758a9 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/WifiQualityMonitor.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/WifiQualityMonitor.java
@@ -16,14 +16,12 @@
package com.android.telephony.qns;
import static android.net.NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED;
+import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static com.android.telephony.qns.QnsConstants.THRESHOLD_EQUAL_OR_LARGER;
import android.annotation.NonNull;
-import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
@@ -54,16 +52,14 @@ public class WifiQualityMonitor extends QualityMonitor {
private final WifiManager mWifiManager;
private final ConnectivityManager mConnectivityManager;
private final WiFiThresholdCallback mWiFiThresholdCallback;
- private final WiFiStatusCallback mWiFiStatusCallback;
private final NetworkRequest.Builder mBuilder;
private int mWifiRssi;
- private final Handler mHandler;
+ @VisibleForTesting Handler mHandler;
private int mRegisteredThreshold = SIGNAL_STRENGTH_UNSPECIFIED;
- private boolean mIsWifiConnected = true;
+ private static final int BACKHAUL_TIMER_DEFAULT = 3000;
+ static final int INVALID_RSSI = -127;
private boolean mIsRegistered = false;
- private boolean mWifiStateIntentEnabled = false;
- private boolean mIsBackhaulRunning;
private class WiFiThresholdCallback extends ConnectivityManager.NetworkCallback {
/** Callback Received based on meeting Wifi RSSI Threshold Registered or Wifi Lost */
@@ -71,64 +67,62 @@ public class WifiQualityMonitor extends QualityMonitor {
public void onCapabilitiesChanged(
@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
super.onCapabilitiesChanged(network, networkCapabilities);
- mWifiRssi = networkCapabilities.getSignalStrength();
- Log.d(mTag, "onCapabilitiesChanged, wifi rssi = " + mWifiRssi);
- mHandler.sendEmptyMessage(EVENT_WIFI_RSSI_CHANGED);
+ Log.d(
+ mTag,
+ "onCapabilitiesChanged wlan network="
+ + network
+ + ", capabilities="
+ + networkCapabilities);
+ if (networkCapabilities != null) {
+ mWifiRssi = networkCapabilities.getSignalStrength();
+ Log.d(mTag, "onCapabilitiesChanged_rssi: " + mWifiRssi);
+ validateWqmStatus(mWifiRssi);
+ }
}
- }
- private class WiFiStatusCallback extends ConnectivityManager.NetworkCallback {
- /** Called when connected network is disconnected. */
+ /** Called when current threshold goes below the threshold set. */
@Override
public void onLost(@NonNull Network network) {
super.onLost(network);
- Log.d(mTag, "onLost: " + network);
- mIsWifiConnected = false;
- if (mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
- Log.d(mTag, "Stop all active backhaul timers");
- mHandler.removeMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED);
- mWaitingThresholds.clear();
- }
- mHandler.sendEmptyMessage(EVENT_WIFI_STATE_CHANGED);
+ mWifiRssi = getCurrentQuality(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI);
+ Log.d(mTag, "onLost_rssi=" + mWifiRssi);
+ validateWqmStatus(mWifiRssi);
}
+ }
- /** Called when the framework connects network & is ready for use. */
- @Override
- public void onAvailable(@NonNull Network network) {
- super.onAvailable(network);
- Log.d(mTag, "onAvailable: " + network);
- NetworkCapabilities networkCapabilities =
- mConnectivityManager.getNetworkCapabilities(network);
- if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
- if (!mIsWifiConnected) {
- mIsWifiConnected = true;
- mHandler.sendEmptyMessage(EVENT_WIFI_STATE_CHANGED);
- } else {
- Log.d(mTag, "mIsWifiConnected is already true");
- }
+ @VisibleForTesting
+ synchronized void validateWqmStatus(int wifiRssi) {
+ if (isWifiRssiValid(wifiRssi)) {
+ Log.d(mTag, "Registered Threshold @ Wqm Status check =" + mRegisteredThreshold);
+ if (!mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
+ mHandler.obtainMessage(EVENT_WIFI_RSSI_CHANGED, wifiRssi, 0).sendToTarget();
+ } else {
+ Log.d(mTag, "BackhaulCheck in Progress , skip validation");
}
+ } else {
+ Log.d(mTag, "Cancel backhaul if running for invalid SS received");
+ clearBackHaulTimer();
}
}
- final BroadcastReceiver mWifiStateIntentReceiver =
- new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- Log.d(mTag, "onReceive action = " + action);
- if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
- mWifiRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
- Log.d(mTag, "Threshold on RSSI change = " + mWifiRssi);
- if (mRegisteredThreshold != SIGNAL_STRENGTH_UNSPECIFIED
- && mWifiRssi < 0
- && mWifiRssi > SIGNAL_STRENGTH_UNSPECIFIED) {
- mHandler.sendEmptyMessage(EVENT_WIFI_RSSI_CHANGED);
- } else {
- Log.d(mTag, "Current Registered_Vs_RSSI= " + mRegisteredThreshold);
- }
- }
- }
- };
+ private boolean isWifiRssiValid(int wifiRssi) {
+ if (mRegisteredThreshold != SIGNAL_STRENGTH_UNSPECIFIED
+ && wifiRssi < 0
+ && wifiRssi > SIGNAL_STRENGTH_UNSPECIFIED
+ && wifiRssi != INVALID_RSSI) {
+ Log.d(mTag, "rssi under check is valid");
+ return true;
+ }
+ return false;
+ }
+
+ private void clearBackHaulTimer() {
+ if (mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
+ Log.d(mTag, "Stop all active backhaul timers");
+ mHandler.removeMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED);
+ mWaitingThresholds.clear();
+ }
+ }
/**
* Create WifiQualityMonitor object for accessing WifiManager, ConnectivityManager to monitor
@@ -141,6 +135,7 @@ public class WifiQualityMonitor extends QualityMonitor {
HandlerThread handlerThread = new HandlerThread(mTag);
handlerThread.start();
mHandler = new WiFiEventsHandler(handlerThread.getLooper());
+
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
mWifiManager = mContext.getSystemService(WifiManager.class);
if (mConnectivityManager == null) {
@@ -155,11 +150,7 @@ public class WifiQualityMonitor extends QualityMonitor {
new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
- .addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
-
- /* Network Callback for Threshold Register. */
- mWiFiStatusCallback = new WiFiStatusCallback();
- Log.d(mTag, "created WifiQualityMonitor");
+ .addTransportType(TRANSPORT_WIFI);
}
/** Returns current Wifi RSSI information */
@@ -217,8 +208,6 @@ public class WifiQualityMonitor extends QualityMonitor {
private void checkForThresholdRegistration() {
// Current check is on measurement type as RSSI
// Future to be enhanced for WiFi PER.
- mWifiRssi = getCurrentQuality(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI);
- Log.d(mTag, "Current Wifi Threshold = " + mWifiRssi);
int newThreshold = SIGNAL_STRENGTH_UNSPECIFIED;
for (Map.Entry<String, List<Threshold>> entry : mThresholdsList.entrySet()) {
for (Threshold t : entry.getValue()) {
@@ -249,55 +238,57 @@ public class WifiQualityMonitor extends QualityMonitor {
}
}
- private void validateForWifiBackhaul() {
- mIsBackhaulRunning = false;
+ private void validateForWifiBackhaul(int wifiRssi) {
+ if (mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
+ mHandler.removeMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED);
+ }
for (Map.Entry<String, List<Threshold>> entry : mThresholdsList.entrySet()) {
if (mWaitingThresholds.getOrDefault(entry.getKey(), false)) {
continue;
}
for (Threshold th : entry.getValue()) {
- if (th.isMatching(mWifiRssi)) {
+ if (th.isMatching(wifiRssi)) {
Log.d(mTag, "RSSI matched for threshold = " + th);
- handleMatchingThreshold(entry.getKey(), th);
+ handleMatchingThreshold(entry.getKey(), th, wifiRssi);
}
}
}
}
- private void handleMatchingThreshold(String key, Threshold th) {
+ private void handleMatchingThreshold(String key, Threshold th, int wifiRssi) {
int backhaul = th.getWaitTime();
if (backhaul < 0 && th.getMatchType() != QnsConstants.THRESHOLD_EQUAL_OR_SMALLER) {
backhaul = BACKHAUL_TIMER_DEFAULT;
}
if (backhaul > 0) {
mWaitingThresholds.put(key, true);
- if (!mIsBackhaulRunning) {
+ if (!mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
Log.d(mTag, "Starting backhaul timer = " + backhaul);
mHandler.sendEmptyMessageDelayed(EVENT_WIFI_NOTIFY_TIMER_EXPIRED, backhaul);
- mIsBackhaulRunning = true;
}
} else {
- checkAndNotifySignalStrength(key);
+ Log.d(mTag, "Notify for RSSI Threshold Registered w/o Backhaul = " + backhaul);
+ checkAndNotifySignalStrength(key, wifiRssi);
}
}
- private void validateThresholdsAfterBackHaul() {
+ private void validateThresholdsAfterBackHaul(int wifiRssi) {
mWaitingThresholds.clear();
for (Map.Entry<String, List<Threshold>> entry : mThresholdsList.entrySet()) {
- checkAndNotifySignalStrength(entry.getKey());
+ checkAndNotifySignalStrength(entry.getKey(), wifiRssi);
}
}
- private void checkAndNotifySignalStrength(String key) {
+ private void checkAndNotifySignalStrength(String key, int wifiRssi) {
List<Threshold> thresholdsList = mThresholdsList.get(key);
if (thresholdsList == null) return;
Log.d(mTag, "checkAndNotifySignalStrength for " + thresholdsList);
List<Threshold> matchedThresholds = new ArrayList<>();
Threshold threshold;
for (Threshold th : thresholdsList) {
- if (th.isMatching(mWifiRssi)) {
+ if (th.isMatching(wifiRssi)) {
threshold = th.copy();
- threshold.setThreshold(mWifiRssi);
+ threshold.setThreshold(wifiRssi);
matchedThresholds.add(threshold);
}
}
@@ -310,65 +301,33 @@ public class WifiQualityMonitor extends QualityMonitor {
if (!register) {
unregisterCallback();
if (mThresholdsList.isEmpty()) {
- registerWiFiReceiver(false);
- if (mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED)) {
- Log.d(mTag, "Stop all active backhaul timers");
- mHandler.removeMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED);
- mWaitingThresholds.clear();
- }
+ clearBackHaulTimer();
+ mWaitingThresholds.clear();
}
} else {
Log.d(mTag, "Listening to threshold = " + mRegisteredThreshold);
mBuilder.setSignalStrength(mRegisteredThreshold);
registerCallback();
- registerWiFiReceiver(true);
}
}
private void unregisterCallback() {
if (mIsRegistered) {
- Log.d(mTag, "Unregister CallBack");
- mConnectivityManager.unregisterNetworkCallback(mWiFiThresholdCallback);
- mConnectivityManager.unregisterNetworkCallback(mWiFiStatusCallback);
+ Log.d(mTag, "Unregister callbacks");
mIsRegistered = false;
+ mConnectivityManager.unregisterNetworkCallback(mWiFiThresholdCallback);
}
}
private void registerCallback() {
unregisterCallback();
if (!mIsRegistered) {
- Log.d(mTag, "Register CallBacks");
+ Log.d(mTag, "Register callbacks");
mConnectivityManager.registerNetworkCallback(mBuilder.build(), mWiFiThresholdCallback);
- mConnectivityManager.registerNetworkCallback(
- new NetworkRequest.Builder()
- .clearCapabilities()
- .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
- .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
- .build(),
- mWiFiStatusCallback);
mIsRegistered = true;
}
}
- private synchronized void registerWiFiReceiver(boolean register) {
- if (register) {
- if (!mWifiStateIntentEnabled) {
- // Register for RSSI Changed Action intent.
- Log.d(mTag, "registerReceiver for RSSI_CHANGED");
- IntentFilter filter = new IntentFilter();
- filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
- mContext.registerReceiver(mWifiStateIntentReceiver, filter);
- mWifiStateIntentEnabled = true;
- }
- } else {
- if (mWifiStateIntentEnabled) {
- Log.d(mTag, "unregisterReceiver RSSI_CHANGED");
- mContext.unregisterReceiver(mWifiStateIntentReceiver);
- mWifiStateIntentEnabled = false;
- }
- }
- }
-
@VisibleForTesting
int getRegisteredThreshold() {
return mRegisteredThreshold;
@@ -383,19 +342,15 @@ public class WifiQualityMonitor extends QualityMonitor {
public void handleMessage(Message msg) {
Log.d(mTag, "handleMessage what = " + msg.what);
switch (msg.what) {
- case EVENT_WIFI_STATE_CHANGED:
- registerWiFiReceiver(mIsWifiConnected);
- break;
case EVENT_WIFI_RSSI_CHANGED:
- validateForWifiBackhaul();
+ Log.d(mTag, "start validating for rssi = " + msg.arg1);
+ validateForWifiBackhaul(msg.arg1);
break;
case EVENT_WIFI_NOTIFY_TIMER_EXPIRED:
mWifiRssi = getCurrentQuality(SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI);
Log.d(mTag, "Backhaul timer expired, wifi rssi = " + mWifiRssi);
- if (mRegisteredThreshold != SIGNAL_STRENGTH_UNSPECIFIED
- && mWifiRssi < 0
- && mWifiRssi > SIGNAL_STRENGTH_UNSPECIFIED) {
- validateThresholdsAfterBackHaul();
+ if (isWifiRssiValid(mWifiRssi)) {
+ validateThresholdsAfterBackHaul(mWifiRssi);
}
break;
default:
@@ -407,7 +362,6 @@ public class WifiQualityMonitor extends QualityMonitor {
@VisibleForTesting
@Override
public void close() {
- registerWiFiReceiver(false);
unregisterCallback();
mWifiRssi = SIGNAL_STRENGTH_UNSPECIFIED;
mIsRegistered = false;
@@ -422,14 +376,10 @@ public class WifiQualityMonitor extends QualityMonitor {
super.dump(pw, prefix);
pw.println(
prefix
- + "mIsWifiConnected="
- + mIsWifiConnected
+ ", mIsRegistered="
+ mIsRegistered
- + ", mWifiStateIntentEnabled="
- + mWifiStateIntentEnabled
- + ", mIsBackhaulRunning="
- + mIsBackhaulRunning);
+ + ", backhaulstatus ="
+ + mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED));
pw.println(
prefix
+ "mWifiRssi="
diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/WifiQualityMonitorTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/WifiQualityMonitorTest.java
index 980152d..75d8db7 100644
--- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/WifiQualityMonitorTest.java
+++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/WifiQualityMonitorTest.java
@@ -16,12 +16,21 @@
package com.android.telephony.qns;
+import static android.net.NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED;
+
+import static com.android.telephony.qns.QualityMonitor.EVENT_WIFI_NOTIFY_TIMER_EXPIRED;
+import static com.android.telephony.qns.QualityMonitor.EVENT_WIFI_RSSI_CHANGED;
+import static com.android.telephony.qns.WifiQualityMonitor.INVALID_RSSI;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.Intent;
import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
@@ -31,7 +40,6 @@ import android.telephony.SignalThresholdInfo;
import androidx.test.core.app.ApplicationProvider;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,16 +49,18 @@ import org.mockito.MockitoAnnotations;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
@RunWith(JUnit4.class)
-public class WifiQualityMonitorTest {
+public class WifiQualityMonitorTest extends QnsTest {
Context mContext;
@Mock ConnectivityManager mConnectivityManager;
@Mock WifiManager mWifiManager;
+ @Mock NetworkCapabilities mNetworkCapabilityManager;
+ @Mock private Network mMockNetwork;
private WifiInfo mWifiInfo;
private WifiQualityMonitor mWifiQualityMonitor;
+ private Threshold[] mRetThresholds;
Threshold[] mThs1 = new Threshold[1];
Threshold[] mThs2 = new Threshold[1];
Threshold[] mThs3 = new Threshold[1];
@@ -68,6 +78,7 @@ public class WifiQualityMonitorTest {
@Override
public void onWifiThresholdChanged(Threshold[] thresholds) {
+ mRetThresholds = thresholds;
mLatch.countDown();
}
}
@@ -80,6 +91,8 @@ public class WifiQualityMonitorTest {
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
+ when(mContext.getSystemService(NetworkCapabilities.class))
+ .thenReturn(mNetworkCapabilityManager);
mWifiInfo = new WifiInfo.Builder().setRssi(mSetRssi).build();
mLatch = new CountDownLatch(1);
mThresholdListener = new ThresholdListener(mExecutor);
@@ -89,15 +102,15 @@ public class WifiQualityMonitorTest {
@Test
public void testGetCurrentQuality() {
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
- int receiveRssi =
+ int recv_rssi =
mWifiQualityMonitor.getCurrentQuality(
AccessNetworkConstants.AccessNetworkType.IWLAN,
SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI);
- Assert.assertEquals(mSetRssi, receiveRssi);
+ assertEquals(mSetRssi, recv_rssi);
}
@Test
- public void testRegisterThresholdChange_RoveIn() {
+ public void testRegisterThresholdChange_RoveIn() throws InterruptedException {
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
mThs1[0] =
new Threshold(
@@ -119,15 +132,15 @@ public class WifiQualityMonitorTest {
mThresholdListener, NetworkCapabilities.NET_CAPABILITY_XCAP, mThs2, 0);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
// smaller threshold should register
- Assert.assertEquals(mThs1[0].getThreshold(), regThreshold);
+ assertEquals(mThs1[0].getThreshold(), regThreshold);
}
@Test
- public void testUnregisterThresholdChange_RoveIn() {
+ public void testUnregisterThresholdChange_RoveIn() throws InterruptedException {
testRegisterThresholdChange_RoveIn();
mWifiQualityMonitor.unregisterThresholdChange(NetworkCapabilities.NET_CAPABILITY_IMS, 0);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs2[0].getThreshold(), regThreshold);
+ assertEquals(mThs2[0].getThreshold(), regThreshold);
}
@Test
@@ -153,19 +166,23 @@ public class WifiQualityMonitorTest {
mThresholdListener, NetworkCapabilities.NET_CAPABILITY_XCAP, mThs2, 0);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
// bigger threshold should register
- Assert.assertEquals(mThs2[0].getThreshold(), regThreshold);
+ assertEquals(mThs2[0].getThreshold(), regThreshold);
}
@Test
- public void testUnregisterThresholdChange_RoveOut() {
+ public void testUnregisterThresholdChange_RoveOut() throws InterruptedException {
testRegisterThresholdChange_RoveOut();
mWifiQualityMonitor.unregisterThresholdChange(NetworkCapabilities.NET_CAPABILITY_XCAP, 0);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs1[0].getThreshold(), regThreshold);
+ assertEquals(mThs1[0].getThreshold(), regThreshold);
+
+ mWifiQualityMonitor.unregisterThresholdChange(NetworkCapabilities.NET_CAPABILITY_IMS, 0);
+ regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
+ assertEquals(SIGNAL_STRENGTH_UNSPECIFIED, regThreshold);
}
@Test
- public void testUpdateThresholdsForNetCapability_RoveIn_Add() {
+ public void testUpdateThresholdsForNetCapability_RoveIn_Add() throws InterruptedException {
testRegisterThresholdChange_RoveIn();
mThs3[0] =
new Threshold(
@@ -177,16 +194,16 @@ public class WifiQualityMonitorTest {
mWifiQualityMonitor.updateThresholdsForNetCapability(
NetworkCapabilities.NET_CAPABILITY_IMS, 0, mThs3);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs3[0].getThreshold(), regThreshold);
+ assertEquals(mThs3[0].getThreshold(), regThreshold);
}
@Test
- public void testUpdateThresholdsForNetCapability_RoveIn_Remove() {
+ public void testUpdateThresholdsForNetCapability_RoveIn_Remove() throws InterruptedException {
testUpdateThresholdsForNetCapability_RoveIn_Add();
mWifiQualityMonitor.updateThresholdsForNetCapability(
NetworkCapabilities.NET_CAPABILITY_IMS, 0, null);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs2[0].getThreshold(), regThreshold);
+ assertEquals(mThs2[0].getThreshold(), regThreshold);
}
@Test
@@ -202,7 +219,7 @@ public class WifiQualityMonitorTest {
mWifiQualityMonitor.updateThresholdsForNetCapability(
NetworkCapabilities.NET_CAPABILITY_IMS, 0, mThs3);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs3[0].getThreshold(), regThreshold);
+ assertEquals(mThs3[0].getThreshold(), regThreshold);
}
@Test
@@ -211,13 +228,13 @@ public class WifiQualityMonitorTest {
mWifiQualityMonitor.updateThresholdsForNetCapability(
NetworkCapabilities.NET_CAPABILITY_IMS, 0, null);
int regThreshold = mWifiQualityMonitor.getRegisteredThreshold();
- Assert.assertEquals(mThs2[0].getThreshold(), regThreshold);
+ assertEquals(mThs2[0].getThreshold(), regThreshold);
}
@Test
public void testBackhaulTimer() throws InterruptedException {
mSetRssi = -65;
- mLatch = new CountDownLatch(4);
+ mLatch = new CountDownLatch(1);
mWifiInfo = new WifiInfo.Builder().setRssi(mSetRssi).build();
when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
mThs1[0] =
@@ -257,11 +274,102 @@ public class WifiQualityMonitorTest {
mThresholdListener, NetworkCapabilities.NET_CAPABILITY_EIMS, mThs2, 0);
mWifiQualityMonitor.registerThresholdChange(
mThresholdListener, NetworkCapabilities.NET_CAPABILITY_MMS, mThs3, 0);
- Intent i = new Intent();
- i.setAction(WifiManager.RSSI_CHANGED_ACTION);
- i.putExtra(WifiManager.EXTRA_NEW_RSSI, -75);
- mWifiQualityMonitor.mWifiStateIntentReceiver.onReceive(mContext, i);
- Assert.assertTrue(mLatch.await(5, TimeUnit.SECONDS));
+
+ mWifiQualityMonitor.mHandler.obtainMessage(EVENT_WIFI_RSSI_CHANGED, -65, 0).sendToTarget();
+ waitForDelayedHandlerAction(mWifiQualityMonitor.mHandler, 1000, 200);
+ assertTrue(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED));
+ waitForDelayedHandlerAction(mWifiQualityMonitor.mHandler, 4000, 200);
+ assertFalse(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED));
+ }
+
+ @Test
+ public void testValidateWqmStatus_ValidRange() {
+ mSetRssi = -65;
+ mLatch = new CountDownLatch(1);
+ mWifiInfo = new WifiInfo.Builder().setRssi(mSetRssi).build();
+ when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
+
+ setWqmThreshold();
+ mWifiQualityMonitor.validateWqmStatus(-65);
+ assertTrue(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_RSSI_CHANGED));
+ }
+
+ @Test
+ public void testValidateWqmStatus_InValidRssiWithValidThreshold() {
+ mSetRssi = -65;
+ mLatch = new CountDownLatch(1);
+ mWifiInfo = new WifiInfo.Builder().setRssi(mSetRssi).build();
+ when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
+
+ setWqmThreshold();
+
+ mWifiQualityMonitor.validateWqmStatus(SIGNAL_STRENGTH_UNSPECIFIED);
+ isWifiRssiChangedHandlerNotPosted();
+
+ mWifiQualityMonitor.validateWqmStatus(INVALID_RSSI);
+ isWifiRssiChangedHandlerNotPosted();
+
+ mWifiQualityMonitor.validateWqmStatus(50);
+ isWifiRssiChangedHandlerNotPosted();
+ }
+
+ @Test
+ public void testValidateWqmStatus_ValidRssiWithInValidThreshold() {
+ mThs1[0] =
+ new Threshold(
+ AccessNetworkConstants.AccessNetworkType.IWLAN,
+ SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI,
+ SIGNAL_STRENGTH_UNSPECIFIED,
+ QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
+ QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER);
+ mWifiQualityMonitor.registerThresholdChange(
+ mThresholdListener, NetworkCapabilities.NET_CAPABILITY_IMS, mThs1, 0);
+
+ mWifiQualityMonitor.validateWqmStatus(-65);
+ isWifiRssiChangedHandlerNotPosted();
+ }
+
+ @Test
+ public void testSkipValidateWqmStatus_WithBackhaulInProgress() {
+ mSetRssi = -65;
+ mLatch = new CountDownLatch(1);
+ mWifiInfo = new WifiInfo.Builder().setRssi(mSetRssi).build();
+ when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
+
+ setWqmThreshold();
+ mWifiQualityMonitor.validateWqmStatus(-65);
+
+ waitForDelayedHandlerAction(mWifiQualityMonitor.mHandler, 1000, 200);
+ assertTrue(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_NOTIFY_TIMER_EXPIRED));
+
+ mWifiQualityMonitor.validateWqmStatus(-68);
+ assertFalse(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_RSSI_CHANGED));
+ }
+
+ private void setWqmThreshold() {
+ mThs1[0] =
+ new Threshold(
+ AccessNetworkConstants.AccessNetworkType.IWLAN,
+ SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSI,
+ -70,
+ QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
+ QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER);
+ mWifiQualityMonitor.registerThresholdChange(
+ mThresholdListener, NetworkCapabilities.NET_CAPABILITY_IMS, mThs1, 0);
+ }
+
+ private void isWifiRssiChangedHandlerNotPosted() {
+ waitForDelayedHandlerAction(mWifiQualityMonitor.mHandler, 1000, 200);
+ assertFalse(mWifiQualityMonitor.mHandler.hasMessages(EVENT_WIFI_RSSI_CHANGED));
+ }
+
+ @Test
+ public void testUpdateThresholdsForNetCapabilityException() {
+ assertThrows(
+ IllegalStateException.class,
+ () ->
+ mWifiQualityMonitor.updateThresholdsForNetCapability(
+ NetworkCapabilities.NET_CAPABILITY_IMS, 0, mThs1));
}
@After