Add new WifiManager API to calculate signal levels

New calculateSignalLevel() overload allows RSSI level
thresholds to be potentially overlaid.

Bug: 140781184
Test: compiles
Change-Id: Ic6c84885dbe17ca39600dc8d8eb5aeff641a0ad3
This commit is contained in:
David Su
2019-11-18 12:49:59 -08:00
parent 5c52237456
commit 3c9241075a
5 changed files with 62 additions and 9 deletions

View File

@@ -30059,7 +30059,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);
@@ -30072,6 +30073,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();

View File

@@ -242,4 +242,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);
}

View File

@@ -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.
*

View File

@@ -42,7 +42,6 @@ import android.net.wifi.hotspot2.IProvisioningCallback;
import android.net.wifi.hotspot2.OsuProvider;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.IBinder;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.WorkSource;
@@ -537,4 +536,9 @@ public class BaseWifiService extends IWifiManager.Stub {
String packageName) {
throw new UnsupportedOperationException();
}
@Override
public int calculateSignalLevel(int rssi) {
throw new UnsupportedOperationException();
}
}

View File

@@ -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);
}
}