summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-08-15 03:07:54 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-08-15 03:07:54 +0000
commitdb30833bf99d24aa88ab9c0541120d5ac50b2c84 (patch)
treef251989f46407cadcf736b41ed570abc8d96e9b5
parent29240d1419fd47fd88d816a17326ea3728ddeac9 (diff)
parent36aa13d2f3b0230dfbdb91baceece854e3fa4ee6 (diff)
downloadandroid_frameworks_opt_net_wifi-db30833bf99d24aa88ab9c0541120d5ac50b2c84.tar.gz
android_frameworks_opt_net_wifi-db30833bf99d24aa88ab9c0541120d5ac50b2c84.tar.bz2
android_frameworks_opt_net_wifi-db30833bf99d24aa88ab9c0541120d5ac50b2c84.zip
Snap for 5803866 from 36aa13d2f3b0230dfbdb91baceece854e3fa4ee6 to qt-qpr1-release
Change-Id: Id87dac1e1b91f7549b50cc38a0e96b4cccc989a8
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java2
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java148
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java37
4 files changed, 175 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index c30d78a08..e1d2a02e4 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -570,6 +570,8 @@ public class WifiNetworkSuggestionsManager {
if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) {
Log.i(TAG, "Setting the carrier provisioning app approved");
perAppInfo.hasUserApproved = true;
+ } else {
+ sendUserApprovalNotification(packageName, uid);
}
}
Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions =
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 51c3dc712..be75f96b3 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -875,7 +875,8 @@ public class WifiServiceImpl extends BaseWifiService {
}
boolean isPrivileged = isPrivileged(Binder.getCallingPid(), Binder.getCallingUid());
if (!isPrivileged && !isDeviceOrProfileOwner(Binder.getCallingUid())
- && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)) {
+ && !mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q)
+ && !isSystem(packageName)) {
mLog.info("setWifiEnabled not allowed for uid=%")
.c(Binder.getCallingUid()).flush();
return false;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index d0d792541..9b462681a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -837,7 +837,7 @@ public class WifiNetworkSuggestionsManagerTest {
validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion);
// Verify no more broadcast were sent out.
- verifyNoMoreInteractions(mContext);
+ mInorder.verifyNoMoreInteractions();
}
/**
@@ -866,7 +866,11 @@ public class WifiNetworkSuggestionsManagerTest {
verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectFailure();
// Verify no more broadcast were sent out.
- verifyNoMoreInteractions(mContext);
+ mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults(
+ anyString(), anyInt());
+ mInorder.verify(mContext, never()).sendBroadcastAsUser(
+ any(), any());
+
}
/**
@@ -927,7 +931,7 @@ public class WifiNetworkSuggestionsManagerTest {
}
// Verify no more broadcast were sent out.
- verifyNoMoreInteractions(mContext);
+ mInorder.verifyNoMoreInteractions();
}
/**
@@ -989,7 +993,7 @@ public class WifiNetworkSuggestionsManagerTest {
}
// Verify no more broadcast were sent out.
- verifyNoMoreInteractions(mContext);
+ mInorder.verifyNoMoreInteractions();
}
/**
@@ -1052,7 +1056,7 @@ public class WifiNetworkSuggestionsManagerTest {
}
// Verify no more broadcast were sent out.
- verifyNoMoreInteractions(mContext);
+ mInorder.verifyNoMoreInteractions();
}
/**
@@ -1084,7 +1088,10 @@ public class WifiNetworkSuggestionsManagerTest {
TEST_BSSID);
// Verify no broadcast was sent out.
- verifyNoMoreInteractions(mContext, mWifiPermissionsUtil);
+ mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults(
+ anyString(), anyInt());
+ mInorder.verify(mContext, never()).sendBroadcastAsUser(
+ any(), any());
}
/**
@@ -1115,7 +1122,10 @@ public class WifiNetworkSuggestionsManagerTest {
TEST_BSSID);
// Verify no broadcast was sent out.
- verifyNoMoreInteractions(mContext, mWifiPermissionsUtil);
+ mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults(
+ anyString(), anyInt());
+ mInorder.verify(mContext, never()).sendBroadcastAsUser(
+ any(), any());
}
/**
@@ -1152,7 +1162,7 @@ public class WifiNetworkSuggestionsManagerTest {
.enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1);
// Verify no broadcast was sent out.
- verifyNoMoreInteractions(mContext, mWifiPermissionsUtil);
+ mInorder.verifyNoMoreInteractions();
}
/**
@@ -1842,10 +1852,11 @@ public class WifiNetworkSuggestionsManagerTest {
}
/**
- * Verify handling of user dismissal of the user approval notification.
+ * Verify user dismissal notification when first time add suggestions and dismissal the user
+ * approval notification when framework gets scan results.
*/
@Test
- public void testUserApprovalNotificationDismissal() {
+ public void testUserApprovalNotificationDismissalWhenGetScanResult() {
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
TEST_PACKAGE_1);
@@ -1856,6 +1867,11 @@ public class WifiNetworkSuggestionsManagerTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+ // Simulate user dismissal notification.
+ sendBroadcastForUserAction(
+ NOTIFICATION_USER_DISMISSED_INTENT_ACTION, TEST_PACKAGE_1, TEST_UID_1);
+ reset(mNotificationManger);
// Simulate finding the network in scan results.
mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(
@@ -1877,10 +1893,11 @@ public class WifiNetworkSuggestionsManagerTest {
}
/**
- * Verify handling of user clicking allow on the user approval notification.
+ * Verify user dismissal notification when first time add suggestions and click on allow on
+ * the user approval notification when framework gets scan results.
*/
@Test
- public void testUserApprovalNotificationClickOnAllow() {
+ public void testUserApprovalNotificationClickOnAllowWhenGetScanResult() {
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
TEST_PACKAGE_1);
@@ -1891,6 +1908,12 @@ public class WifiNetworkSuggestionsManagerTest {
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+
+ // Simulate user dismissal notification.
+ sendBroadcastForUserAction(
+ NOTIFICATION_USER_DISMISSED_INTENT_ACTION, TEST_PACKAGE_1, TEST_UID_1);
+ reset(mNotificationManger);
// Simulate finding the network in scan results.
mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(
@@ -1916,10 +1939,11 @@ public class WifiNetworkSuggestionsManagerTest {
}
/**
- * Verify handling of user clicking disallow on the user approval notification.
+ * Verify user dismissal notification when first time add suggestions and click on disallow on
+ * the user approval notification when framework gets scan results.
*/
@Test
- public void testUserApprovalNotificationClickOnDisallow() {
+ public void testUserApprovalNotificationClickOnDisallowWhenGetScanResult() {
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
TEST_PACKAGE_1);
@@ -1932,6 +1956,12 @@ public class WifiNetworkSuggestionsManagerTest {
TEST_PACKAGE_1));
verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE),
eq(TEST_PACKAGE_1), mAppOpChangedListenerCaptor.capture());
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+
+ // Simulate user dismissal notification.
+ sendBroadcastForUserAction(
+ NOTIFICATION_USER_DISMISSED_INTENT_ACTION, TEST_PACKAGE_1, TEST_UID_1);
+ reset(mNotificationManger);
// Simulate finding the network in scan results.
mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(
@@ -2048,6 +2078,96 @@ public class WifiNetworkSuggestionsManagerTest {
}
/**
+ * Verify handling of user clicking allow on the user approval notification when first time
+ * add suggestions.
+ */
+ @Test
+ public void testUserApprovalNotificationClickOnAllowDuringAddingSuggestions() {
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1));
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+
+ // Simulate user clicking on allow in the notification.
+ sendBroadcastForUserAction(
+ NOTIFICATION_USER_ALLOWED_APP_INTENT_ACTION, TEST_PACKAGE_1, TEST_UID_1);
+ // Cancel the notification.
+ verify(mNotificationManger).cancel(SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE);
+
+ // Verify config store interactions.
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ assertTrue(mDataSource.hasNewDataToSerialize());
+
+ reset(mNotificationManger);
+ // We should not resend the notification next time the network is found in scan results.
+ mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(
+ createScanDetailForNetwork(networkSuggestion.wifiConfiguration));
+ verifyNoMoreInteractions(mNotificationManger);
+ }
+
+ /**
+ * Verify handling of user clicking Disallow on the user approval notification when first time
+ * add suggestions.
+ */
+ @Test
+ public void testUserApprovalNotificationClickOnDisallowWhenAddSuggestions() {
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1));
+ verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE),
+ eq(TEST_PACKAGE_1), mAppOpChangedListenerCaptor.capture());
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+
+ // Simulate user clicking on disallow in the notification.
+ sendBroadcastForUserAction(
+ NOTIFICATION_USER_DISALLOWED_APP_INTENT_ACTION, TEST_PACKAGE_1, TEST_UID_1);
+ // Ensure we turn off CHANGE_WIFI_STATE app-ops.
+ verify(mAppOpsManager).setMode(
+ OP_CHANGE_WIFI_STATE, TEST_UID_1,
+ TEST_PACKAGE_1, MODE_IGNORED);
+ // Cancel the notification.
+ verify(mNotificationManger).cancel(SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE);
+
+ // Verify config store interactions.
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ assertTrue(mDataSource.hasNewDataToSerialize());
+
+ reset(mNotificationManger);
+
+ // Now trigger the app-ops callback to ensure we remove all of their suggestions.
+ AppOpsManager.OnOpChangedListener listener = mAppOpChangedListenerCaptor.getValue();
+ assertNotNull(listener);
+ when(mAppOpsManager.unsafeCheckOpNoThrow(
+ OPSTR_CHANGE_WIFI_STATE, TEST_UID_1,
+ TEST_PACKAGE_1))
+ .thenReturn(MODE_IGNORED);
+ listener.onOpChanged(OPSTR_CHANGE_WIFI_STATE, TEST_PACKAGE_1);
+ mLooper.dispatchAll();
+ assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty());
+
+ // Assuming the user re-enabled the app again & added the same suggestions back.
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1));
+ validateUserApprovalNotification(TEST_APP_NAME_1);
+ verifyNoMoreInteractions(mNotificationManger);
+ }
+
+ /**
* Creates a scan detail corresponding to the provided network values.
*/
private ScanDetail createScanDetailForNetwork(WifiConfiguration configuration) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index af624da11..4f0ddc036 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -620,6 +620,24 @@ public class WifiServiceImplTest {
}
/**
+ * Verify that wifi can be enabled by the system apps targeting Q SDK.
+ */
+ @Test
+ public void testSetWifiEnabledSuccessForSystemAppsTargetingQSDK() throws Exception {
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME);
+ when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(),
+ eq(Build.VERSION_CODES.Q))).thenReturn(false);
+ mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+
+ when(mSettingsStore.handleWifiToggled(eq(true))).thenReturn(true);
+ when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
+ assertTrue(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, true));
+
+ verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
+ }
+
+ /**
* Verify that wifi can be enabled by the apps targeting pre-Q SDK.
*/
@Test
@@ -866,6 +884,25 @@ public class WifiServiceImplTest {
}
/**
+ * Verify that wifi can be disabled by the system apps targeting Q SDK.
+ */
+ @Test
+ public void testSetWifiDisabledSuccessForSystemAppsTargetingQSDK() throws Exception {
+ doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
+ .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME);
+ when(mWifiPermissionsUtil.isTargetSdkLessThan(anyString(),
+ eq(Build.VERSION_CODES.Q))).thenReturn(false);
+ mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+
+ when(mSettingsStore.handleWifiToggled(eq(false))).thenReturn(true);
+ when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
+ assertTrue(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, false));
+
+ verify(mWifiController).sendMessage(eq(CMD_WIFI_TOGGLED));
+ }
+
+
+ /**
* Verify that wifi can be disabled by the apps targeting pre-Q SDK.
*/
@Test