From b774c31798b0abe4910cd8658304fe12ae0b3160 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Wed, 22 Apr 2020 11:42:10 -0700 Subject: SavedNetworkNominator: Log all network ignore reasons Bug: 154658750 Test: Compiles Change-Id: I873f179c00e9c825adc866498e47ba995fbfb9b7 --- service/java/com/android/server/wifi/SavedNetworkNominator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/service/java/com/android/server/wifi/SavedNetworkNominator.java b/service/java/com/android/server/wifi/SavedNetworkNominator.java index 2d91881a0..a3039096e 100644 --- a/service/java/com/android/server/wifi/SavedNetworkNominator.java +++ b/service/java/com/android/server/wifi/SavedNetworkNominator.java @@ -97,7 +97,6 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat // One ScanResult can be associated with more than one network, hence we calculate all // the scores and use the highest one as the ScanResult's score. - // TODO(b/112196799): this has side effects, rather not do that in a nominator WifiConfiguration network = mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); @@ -117,20 +116,21 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat // Ignore networks that the user has disallowed auto-join for. if (!network.allowAutojoin) { + localLog("Ignoring auto join disabled SSID: " + network.SSID); continue; } WifiConfiguration.NetworkSelectionStatus status = network.getNetworkSelectionStatus(); - // TODO (b/112196799): another side effect status.setSeenInLastQualifiedNetworkSelection(true); if (mWifiConfigManager.isNetworkTemporarilyDisabledByUser(network.SSID)) { - mLocalLog.log("Ignoring user disabled SSID: " + network.SSID); + localLog("Ignoring user disabled SSID: " + network.SSID); continue; } if (!status.isNetworkEnabled()) { + localLog("Ignoring network selection disabled SSID: " + network.SSID); continue; } if (network.BSSID != null && !network.BSSID.equals("any") @@ -143,6 +143,7 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat continue; } if (isNetworkSimBasedCredential(network) && !isSimBasedNetworkAbleToAutoJoin(network)) { + localLog("Ignoring SIM auto join disabled SSID: " + network.SSID); continue; } -- cgit v1.2.3 From d3233e508ebb6c1919ec1dd1559e2516873f1611 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Wed, 22 Apr 2020 16:07:13 -0700 Subject: WifiServiceImpl: Restore the system alert bypass for legacy API surface This was prematurely removed in R even though we later changed that decision. Bug: 153615530 Test: atest com.android.server.wifi Change-Id: I8373e0f287102dd3d29a1b7c2c7d4b75a8c36433 --- .../com/android/server/wifi/WifiServiceImpl.java | 8 +++----- .../android/server/wifi/WifiServiceImplTest.java | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 6e339044a..a147c247e 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -735,10 +735,10 @@ public class WifiServiceImpl extends BaseWifiService { private boolean isTargetSdkLessThanQOrPrivileged(String packageName, int pid, int uid) { return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.Q, uid) || isPrivileged(pid, uid) - // DO/PO apps should be able to add/modify saved networks. || isDeviceOrProfileOwner(uid, packageName) - // TODO: Remove this system app bypass once Q is released. - || isSystem(packageName, uid); + || isSystem(packageName, uid) + // TODO(b/140540984): Remove this bypass. + || mWifiPermissionsUtil.checkSystemAlertWindowPermission(uid, packageName); } /** @@ -749,9 +749,7 @@ public class WifiServiceImpl extends BaseWifiService { private boolean isTargetSdkLessThanROrPrivileged(String packageName, int pid, int uid) { return mWifiPermissionsUtil.isTargetSdkLessThan(packageName, Build.VERSION_CODES.R, uid) || isPrivileged(pid, uid) - // DO/PO apps should be able to add/modify saved networks. || isDeviceOrProfileOwner(uid, packageName) - // TODO: Remove this system app bypass once R is released. || isSystem(packageName, uid); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index a11fc6dcb..45f49615a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -4252,6 +4252,30 @@ public class WifiServiceImplTest extends WifiBaseTest { verify(mWifiMetrics).incrementNumAddOrUpdateNetworkCalls(); } + /** + * Verify that add or update networks is allowed for apps holding system alert permission. + */ + @Test + public void testAddOrUpdateNetworkIsAllowedForAppsWithSystemAlertPermission() throws Exception { + doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager) + .noteOp(AppOpsManager.OPSTR_CHANGE_WIFI_STATE, Process.myUid(), TEST_PACKAGE_NAME); + when(mWifiConfigManager.addOrUpdateNetwork(any(), anyInt(), any())).thenReturn( + new NetworkUpdateResult(0)); + + when(mWifiPermissionsUtil.checkSystemAlertWindowPermission( + Process.myUid(), TEST_PACKAGE_NAME)).thenReturn(true); + + WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); + mLooper.startAutoDispatch(); + assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); + mLooper.stopAutoDispatchAndIgnoreExceptions(); + + verifyCheckChangePermission(TEST_PACKAGE_NAME); + verify(mWifiPermissionsUtil).checkSystemAlertWindowPermission(anyInt(), anyString()); + verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any()); + verify(mWifiMetrics).incrementNumAddOrUpdateNetworkCalls(); + } + /** * Verify that add or update networks is allowed for DeviceOwner app. */ -- cgit v1.2.3