Merge changes from topic "rssi-level-thresholds"
* changes: Add new WifiManager API to calculate signal levels Fix broken test caused by calculateSignalLevel() migration Migrate WifiStatusTracker calculateSignalLevel()
This commit is contained in:
@@ -30061,7 +30061,8 @@ package android.net.wifi {
|
||||
method public void addOrUpdatePasspointConfiguration(android.net.wifi.hotspot2.PasspointConfiguration);
|
||||
method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public void addScanResultsListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.ScanResultsListener);
|
||||
method @RequiresPermission(allOf={android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_WIFI_STATE}) public void addSuggestionConnectionStatusListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.WifiManager.SuggestionConnectionStatusListener);
|
||||
method public static int calculateSignalLevel(int, int);
|
||||
method @Deprecated public static int calculateSignalLevel(int, int);
|
||||
method public int calculateSignalLevel(int);
|
||||
method @Deprecated public void cancelWps(android.net.wifi.WifiManager.WpsCallback);
|
||||
method public static int compareSignalLevel(int, int);
|
||||
method public android.net.wifi.WifiManager.MulticastLock createMulticastLock(String);
|
||||
@@ -30074,6 +30075,7 @@ package android.net.wifi {
|
||||
method public android.net.wifi.WifiInfo getConnectionInfo();
|
||||
method public android.net.DhcpInfo getDhcpInfo();
|
||||
method public int getMaxNumberOfNetworkSuggestionsPerApp();
|
||||
method public int getMaxSignalLevel();
|
||||
method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public java.util.List<android.net.wifi.WifiNetworkSuggestion> getNetworkSuggestions();
|
||||
method @Deprecated @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", "android.permission.NETWORK_SETUP_WIZARD"}) public java.util.List<android.net.wifi.hotspot2.PasspointConfiguration> getPasspointConfigurations();
|
||||
method public java.util.List<android.net.wifi.ScanResult> getScanResults();
|
||||
|
||||
@@ -142,7 +142,7 @@ public class WifiStatusTracker extends ConnectivityManager.NetworkCallback {
|
||||
|
||||
private void updateRssi(int newRssi) {
|
||||
rssi = newRssi;
|
||||
level = WifiManager.calculateSignalLevel(rssi, WifiManager.RSSI_LEVELS);
|
||||
level = mWifiManager.calculateSignalLevel(rssi);
|
||||
}
|
||||
|
||||
private void maybeRequestNetworkScore() {
|
||||
|
||||
@@ -139,6 +139,14 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
|
||||
when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn(
|
||||
new NetworkCapabilities[] { mNetCapabilities });
|
||||
when(mMockTm.createForSubscriptionId(anyInt())).thenReturn(mMockTm);
|
||||
doAnswer(invocation -> {
|
||||
int rssi = invocation.getArgument(0);
|
||||
if (rssi < -88) return 0;
|
||||
if (rssi < -77) return 1;
|
||||
if (rssi < -66) return 2;
|
||||
if (rssi < -55) return 3;
|
||||
return 4;
|
||||
}).when(mMockWm).calculateSignalLevel(anyInt());
|
||||
|
||||
mSignalStrength = mock(SignalStrength.class);
|
||||
mServiceState = mock(ServiceState.class);
|
||||
|
||||
@@ -240,4 +240,6 @@ interface IWifiManager
|
||||
void registerSuggestionConnectionStatusListener(in IBinder binder, in ISuggestionConnectionStatusListener listener, int listenerIdentifier, String packageName, String featureId);
|
||||
|
||||
void unregisterSuggestionConnectionStatusListener(int listenerIdentifier, String packageName);
|
||||
|
||||
int calculateSignalLevel(int rssi);
|
||||
}
|
||||
|
||||
@@ -1153,8 +1153,6 @@ public class WifiManager {
|
||||
* @hide
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
// TODO(b/140781184): need to support custom number of RSSI levels, as well as levels that are
|
||||
// not evenly spaced
|
||||
public static final int RSSI_LEVELS = 5;
|
||||
|
||||
/**
|
||||
@@ -2782,11 +2780,13 @@ public class WifiManager {
|
||||
* is being shown.
|
||||
*
|
||||
* @param rssi The power of the signal measured in RSSI.
|
||||
* @param numLevels The number of levels to consider in the calculated
|
||||
* level.
|
||||
* @return A level of the signal, given in the range of 0 to numLevels-1
|
||||
* (both inclusive).
|
||||
* @param numLevels The number of levels to consider in the calculated level.
|
||||
* @return A level of the signal, given in the range of 0 to numLevels-1 (both inclusive).
|
||||
* @deprecated Callers should use {@link #calculateSignalLevel(int)} instead to get the
|
||||
* signal level using the system default RSSI thresholds, or otherwise compute the RSSI level
|
||||
* themselves using their own formula.
|
||||
*/
|
||||
@Deprecated
|
||||
public static int calculateSignalLevel(int rssi, int numLevels) {
|
||||
if (rssi <= MIN_RSSI) {
|
||||
return 0;
|
||||
@@ -2799,6 +2799,34 @@ public class WifiManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a raw RSSI, return the RSSI signal quality rating using the system default RSSI
|
||||
* quality rating thresholds.
|
||||
* @param rssi a raw RSSI value, in dBm, usually between -55 and -90
|
||||
* @return the RSSI signal quality rating, in the range
|
||||
* [0, {@link #getMaxSignalLevel()}], where 0 is the lowest (worst signal) RSSI
|
||||
* rating and {@link #getMaxSignalLevel()} is the highest (best signal) RSSI rating.
|
||||
*/
|
||||
public int calculateSignalLevel(int rssi) {
|
||||
try {
|
||||
IWifiManager iWifiManager = getIWifiManager();
|
||||
if (iWifiManager == null) {
|
||||
throw new RemoteException("Wifi service is not running");
|
||||
}
|
||||
return iWifiManager.calculateSignalLevel(rssi);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the system default maximum signal level.
|
||||
* This is the maximum RSSI level returned by {@link #calculateSignalLevel(int)}.
|
||||
*/
|
||||
public int getMaxSignalLevel() {
|
||||
return calculateSignalLevel(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two signal strengths.
|
||||
*
|
||||
|
||||
@@ -535,4 +535,9 @@ public class BaseWifiService extends IWifiManager.Stub {
|
||||
String packageName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateSignalLevel(int rssi) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1899,8 +1899,25 @@ public class WifiManagerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveSuggestionConnectionListener() throws Exception {
|
||||
|
||||
mWifiManager.removeSuggestionConnectionStatusListener(mListener);
|
||||
verify(mWifiService).unregisterSuggestionConnectionStatusListener(anyInt(), anyString());
|
||||
}
|
||||
|
||||
/** Test {@link WifiManager#calculateSignalLevel(int)} */
|
||||
@Test
|
||||
public void testCalculateSignalLevel() throws Exception {
|
||||
when(mWifiService.calculateSignalLevel(anyInt())).thenReturn(3);
|
||||
int actual = mWifiManager.calculateSignalLevel(-60);
|
||||
verify(mWifiService).calculateSignalLevel(-60);
|
||||
assertEquals(3, actual);
|
||||
}
|
||||
|
||||
/** Test {@link WifiManager#getMaxSignalLevel()} */
|
||||
@Test
|
||||
public void testGetMaxSignalLevel() throws Exception {
|
||||
when(mWifiService.calculateSignalLevel(anyInt())).thenReturn(4);
|
||||
int actual = mWifiManager.getMaxSignalLevel();
|
||||
verify(mWifiService).calculateSignalLevel(Integer.MAX_VALUE);
|
||||
assertEquals(4, actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user