diff options
| author | 2020-11-10 17:30:14 -0800 | |
|---|---|---|
| committer | 2020-11-12 16:40:00 -0800 | |
| commit | 30b8b6b9406403142cc497513d4415030f62bdd1 (patch) | |
| tree | 615f605d4dae3e0b9ae396631375721cbb10d453 | |
| parent | 5d1ebbbb31fb5e89bcc432f9b359a5f7b9653856 (diff) | |
[Suggestion] Add API to help app get user approval status.
Bug: 160648511
Test: atest android.net.wifi
Change-Id: If93db55b1e0bc33dd7b82dad4e297c442b628e44
| -rw-r--r-- | api/current.txt | 6 | ||||
| -rw-r--r-- | wifi/api/current.txt | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 2 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 59 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/WifiManagerTest.java | 9 |
5 files changed, 82 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 576f3f241a7a..cc2c1b9eb7bb 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 diff --git a/wifi/api/current.txt b/wifi/api/current.txt index 3b8c33cae516..f418eb6fc74b 100644 --- a/wifi/api/current.txt +++ b/wifi/api/current.txt @@ -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 diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 7329c16d68d0..48e23125e03c 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -275,4 +275,6 @@ interface IWifiManager void setAutoWakeupEnabled(boolean enable); boolean isAutoWakeupEnabled(); + + int getNetworkSuggestionUserApprovalStatus(String packageName); } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index ef55a56a494c..7e04d8ff117d 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -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; @@ -264,6 +265,44 @@ public class WifiManager { 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: * - {@link #EXTRA_SCAN_AVAILABLE} @@ -2010,6 +2049,26 @@ public class WifiManager { } /** + * 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 * service provider specified in the configuration. diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 7340b145e8b2..572924757226 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -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); + } } |