From 30b8b6b9406403142cc497513d4415030f62bdd1 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Tue, 10 Nov 2020 17:30:14 -0800 Subject: [PATCH] [Suggestion] Add API to help app get user approval status. Bug: 160648511 Test: atest android.net.wifi Change-Id: If93db55b1e0bc33dd7b82dad4e297c442b628e44 --- api/current.txt | 6 ++ wifi/api/current.txt | 6 ++ wifi/java/android/net/wifi/IWifiManager.aidl | 2 + wifi/java/android/net/wifi/WifiManager.java | 59 +++++++++++++++++++ .../src/android/net/wifi/WifiManagerTest.java | 9 +++ 5 files changed, 82 insertions(+) diff --git a/api/current.txt b/api/current.txt index 576f3f241a7a6..cc2c1b9eb7bbc 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 getNetworkSuggestions(); method @Deprecated @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", "android.permission.NETWORK_SETUP_WIZARD"}) public java.util.List getPasspointConfigurations(); method public java.util.List 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 3b8c33cae5162..f418eb6fc74b1 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 getNetworkSuggestions(); method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD}) public java.util.List getPasspointConfigurations(); method public java.util.List 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 7329c16d68d09..48e23125e03c9 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 ef55a56a494c5..7e04d8ff117de 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; @@ -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 diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 7340b145e8b20..572924757226a 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); + } }