Fix template for test network needs fine location permission

For a template with MATCH_TEST, since the wifi network key is
just a placeholder to identify a specific test network, it is
not related to track user location. Hence the check is not
really needed.

Test: 1. atest NetworkStatsIntegrationTest with use location turned off
      2. atest FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Fix: 280686048
Change-Id: Ic128cfbbb2d03c427c9030c99bf205eb65a33e58
This commit is contained in:
Junyu Lai
2023-05-04 11:01:33 +08:00
parent 69b6ca4ff1
commit a58914b548
2 changed files with 9 additions and 1 deletions

View File

@@ -1926,12 +1926,17 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
// Templates w/o wifi network keys can query stats as usual.
assertNetworkTotal(sTemplateCarrierWifi1, 0L, 0L, 0L, 0L, 0);
assertNetworkTotal(sTemplateImsi1, 0L, 0L, 0L, 0L, 0);
// Templates for test network does not need to enforce location permission.
final NetworkTemplate templateTestIface1 = new NetworkTemplate.Builder(MATCH_TEST)
.setWifiNetworkKeys(Set.of(TEST_IFACE)).build();
assertNetworkTotal(templateTestIface1, 0L, 0L, 0L, 0L, 0);
doReturn(true).when(mLocationPermissionChecker)
.checkCallersLocationPermission(any(), any(), anyInt(), anyBoolean(), any());
assertNetworkTotal(sTemplateCarrierWifi1, 0L, 0L, 0L, 0L, 0);
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
assertNetworkTotal(sTemplateImsi1, 0L, 0L, 0L, 0L, 0);
assertNetworkTotal(templateTestIface1, 0L, 0L, 0L, 0L, 0);
}
/**