Wifi usability: Add CTS test to check permission is granted to <= 1 app

1. Need to add the access permission into android_manifest.xml in CTS test
folder in order to pass the presubmit verification.
2. Check the access permission is granted to <=1 app.

Bug: 113262380

Test: atest WifiManagerTest#testUpdateWifiUsabilityStatsScorePermission

Change-Id: Iaa4ac3140f2bca0b0971bba4943e8f7d08231a65
Signed-off-by: Mingguang Xu <mingguangxu@google.com>
This commit is contained in:
Mingguang Xu
2019-01-22 19:07:50 -08:00
parent 3c65c1d114
commit 6db2aa983b

View File

@@ -1023,6 +1023,30 @@ public class WifiManagerTest extends AndroidTestCase {
}
}
/**
* Verify that the {@link android.Manifest.permission#WIFI_UPDATE_USABILITY_STATS_SCORE}
* permission is held by at most one application.
*/
public void testUpdateWifiUsabilityStatsScorePermission() {
final PackageManager pm = getContext().getPackageManager();
final List<PackageInfo> holding = pm.getPackagesHoldingPermissions(new String[] {
android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE
}, PackageManager.MATCH_UNINSTALLED_PACKAGES);
List<String> uniquePackageNames = holding
.stream()
.map(pi -> pi.packageName)
.distinct()
.collect(Collectors.toList());
if (uniquePackageNames.size() > 1) {
fail("The WIFI_UPDATE_USABILITY_STATS_SCORE permission must not be held by more than "
+ "one application, but is held by " + uniquePackageNames.size() + " applications: "
+ String.join(", ", uniquePackageNames));
}
}
private void turnScreenOnNoDelay() throws Exception {
mUiDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP");
mUiDevice.executeShellCommand("wm dismiss-keyguard");