[Suggestion] Add API to help app get user approval status.

Bug: 160648511
Test: atest android.net.wifi

Change-Id: If93db55b1e0bc33dd7b82dad4e297c442b628e44
This commit is contained in:
Nate Jiang
2020-11-10 17:30:14 -08:00
parent 5d1ebbbb31
commit 30b8b6b940
5 changed files with 82 additions and 0 deletions

View File

@@ -31682,6 +31682,7 @@ package android.net.wifi {
method public android.net.DhcpInfo getDhcpInfo();
method public int getMaxNumberOfNetworkSuggestionsPerApp();
method @IntRange(from=0) public int getMaxSignalLevel();
method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public int getNetworkSuggestionUserApprovalStatus();
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();
@@ -31752,6 +31753,11 @@ package android.net.wifi {
field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1; // 0x1
field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5; // 0x5
field public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0; // 0x0
field public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_CARRIER_PRIVILEGE = 4; // 0x4
field public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER = 2; // 0x2
field public static final int STATUS_SUGGESTION_APPROVAL_PENDING = 1; // 0x1
field public static final int STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER = 3; // 0x3
field public static final int STATUS_SUGGESTION_APPROVAL_UNKNOWN = 0; // 0x0
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_ASSOCIATION = 1; // 0x1
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_AUTHENTICATION = 2; // 0x2
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_IP_PROVISIONING = 3; // 0x3

View File

@@ -323,6 +323,7 @@ package android.net.wifi {
method public android.net.DhcpInfo getDhcpInfo();
method public int getMaxNumberOfNetworkSuggestionsPerApp();
method @IntRange(from=0) public int getMaxSignalLevel();
method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public int getNetworkSuggestionUserApprovalStatus();
method @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public java.util.List<android.net.wifi.WifiNetworkSuggestion> getNetworkSuggestions();
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.List<android.net.wifi.hotspot2.PasspointConfiguration> getPasspointConfigurations();
method public java.util.List<android.net.wifi.ScanResult> getScanResults();
@@ -393,6 +394,11 @@ package android.net.wifi {
field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1; // 0x1
field public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5; // 0x5
field public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0; // 0x0
field public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_CARRIER_PRIVILEGE = 4; // 0x4
field public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER = 2; // 0x2
field public static final int STATUS_SUGGESTION_APPROVAL_PENDING = 1; // 0x1
field public static final int STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER = 3; // 0x3
field public static final int STATUS_SUGGESTION_APPROVAL_UNKNOWN = 0; // 0x0
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_ASSOCIATION = 1; // 0x1
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_AUTHENTICATION = 2; // 0x2
field public static final int STATUS_SUGGESTION_CONNECTION_FAILURE_IP_PROVISIONING = 3; // 0x3

View File

@@ -275,4 +275,6 @@ interface IWifiManager
void setAutoWakeupEnabled(boolean enable);
boolean isAutoWakeupEnabled();
int getNetworkSuggestionUserApprovalStatus(String packageName);
}

View File

@@ -53,6 +53,7 @@ import android.os.Looper;
import android.os.RemoteException;
import android.os.WorkSource;
import android.os.connectivity.WifiActivityEnergyInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.CloseGuard;
import android.util.Log;
@@ -263,6 +264,44 @@ public class WifiManager {
@Retention(RetentionPolicy.SOURCE)
public @interface SuggestionConnectionStatusCode {}
/**
* Status code if suggestion approval status is unknown, an App which hasn't made any
* suggestions will get this code.
*/
public static final int STATUS_SUGGESTION_APPROVAL_UNKNOWN = 0;
/**
* Status code if the calling app is still pending user approval for suggestions.
*/
public static final int STATUS_SUGGESTION_APPROVAL_PENDING = 1;
/**
* Status code if the calling app got the user approval for suggestions.
*/
public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER = 2;
/**
* Status code if the calling app suggestions were rejected by the user.
*/
public static final int STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER = 3;
/**
* Status code if the calling app was approved by virtue of being a carrier privileged app.
* @see TelephonyManager#hasCarrierPrivileges().
*/
public static final int STATUS_SUGGESTION_APPROVAL_APPROVED_BY_CARRIER_PRIVILEGE = 4;
/** @hide */
@IntDef(prefix = {"STATUS_SUGGESTION_APPROVAL_"},
value = {STATUS_SUGGESTION_APPROVAL_UNKNOWN,
STATUS_SUGGESTION_APPROVAL_PENDING,
STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER,
STATUS_SUGGESTION_APPROVAL_REJECTED_BY_USER,
STATUS_SUGGESTION_APPROVAL_APPROVED_BY_CARRIER_PRIVILEGE
})
@Retention(RetentionPolicy.SOURCE)
public @interface SuggestionUserApprovalStatus {}
/**
* Broadcast intent action indicating whether Wi-Fi scanning is currently available.
* Available extras:
@@ -2009,6 +2048,26 @@ public class WifiManager {
: NETWORK_SUGGESTIONS_MAX_PER_APP_HIGH_RAM;
}
/**
* Get the Suggestion approval status of the calling app. When an app makes suggestions using
* the {@link #addNetworkSuggestions(List)} API they may trigger a user approval flow. This API
* provides the current approval status.
*
* @return Status code for the user approval. One of the STATUS_SUGGESTION_APPROVAL_ values.
* @throws {@link SecurityException} if the caller is missing required permissions.
*/
@RequiresPermission(ACCESS_WIFI_STATE)
public @SuggestionUserApprovalStatus int getNetworkSuggestionUserApprovalStatus() {
if (!SdkLevel.isAtLeastS()) {
throw new UnsupportedOperationException();
}
try {
return mService.getNetworkSuggestionUserApprovalStatus(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Add or update a Passpoint configuration. The configuration provides a credential
* for connecting to Passpoint networks that are operated by the Passpoint

View File

@@ -2415,4 +2415,13 @@ public class WifiManagerTest {
assertFalse(mWifiManager.isScanAlwaysAvailable());
verify(mWifiService).isScanAlwaysAvailable();
}
@Test
public void testGetNetworkSuggestionUserApprovalStatus() throws Exception {
when(mWifiService.getNetworkSuggestionUserApprovalStatus(TEST_PACKAGE_NAME))
.thenReturn(WifiManager.STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER);
assertEquals(WifiManager.STATUS_SUGGESTION_APPROVAL_APPROVED_BY_USER,
mWifiManager.getNetworkSuggestionUserApprovalStatus());
verify(mWifiService).getNetworkSuggestionUserApprovalStatus(TEST_PACKAGE_NAME);
}
}