1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.appsecurity.cts; 18 19 import android.platform.test.annotations.AppModeFull; 20 import android.platform.test.annotations.Presubmit; 21 22 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; 23 import com.android.tradefed.build.IBuildInfo; 24 import com.android.tradefed.device.DeviceNotAvailableException; 25 import com.android.tradefed.testtype.DeviceTestCase; 26 import com.android.tradefed.testtype.IAbi; 27 import com.android.tradefed.testtype.IAbiReceiver; 28 import com.android.tradefed.testtype.IBuildReceiver; 29 30 /** 31 * Set of tests that verify behavior of runtime permissions, including both 32 * dynamic granting and behavior of legacy apps. 33 */ 34 public class PermissionsHostTest extends DeviceTestCase implements IAbiReceiver, IBuildReceiver { 35 private static final String USES_PERMISSION_PKG = "com.android.cts.usepermission"; 36 private static final String ESCALATE_PERMISSION_PKG = "com.android.cts.escalate.permission"; 37 38 private static final String APK_22 = "CtsUsePermissionApp22.apk"; 39 private static final String APK_22_ONLY_CALENDAR = "RequestsOnlyCalendarApp22.apk"; 40 private static final String APK_23 = "CtsUsePermissionApp23.apk"; 41 private static final String APK_25 = "CtsUsePermissionApp25.apk"; 42 private static final String APK_26 = "CtsUsePermissionApp26.apk"; 43 private static final String APK_28 = "CtsUsePermissionApp28.apk"; 44 private static final String APK_29 = "CtsUsePermissionApp29.apk"; 45 private static final String APK_Latest = "CtsUsePermissionAppLatest.apk"; 46 47 private static final String APK_PERMISSION_POLICY_25 = "CtsPermissionPolicyTest25.apk"; 48 private static final String PERMISSION_POLICY_25_PKG = "com.android.cts.permission.policy"; 49 50 private static final String APK_DECLARE_NON_RUNTIME_PERMISSIONS = 51 "CtsDeclareNonRuntimePermissions.apk"; 52 private static final String APK_ESCLATE_TO_RUNTIME_PERMISSIONS = 53 "CtsEscalateToRuntimePermissions.apk"; 54 55 private static final String REVIEW_HELPER_APK = "ReviewPermissionHelper.apk"; 56 private static final String REVIEW_HELPER_PKG = "com.android.cts.reviewpermissionhelper"; 57 private static final String REVIEW_HELPER_TEST_CLASS = REVIEW_HELPER_PKG 58 + ".ReviewPermissionsTest"; 59 60 private static final String SCREEN_OFF_TIMEOUT_NS = "system"; 61 private static final String SCREEN_OFF_TIMEOUT_KEY = "screen_off_timeout"; 62 private String mScreenTimeoutBeforeTest; 63 64 private IAbi mAbi; 65 private CompatibilityBuildHelper mBuildHelper; 66 67 @Override setAbi(IAbi abi)68 public void setAbi(IAbi abi) { 69 mAbi = abi; 70 } 71 72 @Override setBuild(IBuildInfo buildInfo)73 public void setBuild(IBuildInfo buildInfo) { 74 mBuildHelper = new CompatibilityBuildHelper(buildInfo); 75 } 76 77 /** 78 * Approve the review permission prompt 79 */ approveReviewPermissionDialog()80 private void approveReviewPermissionDialog() throws Exception { 81 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 82 true)); 83 84 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, "approveReviewPermissions"); 85 } 86 87 @Override setUp()88 protected void setUp() throws Exception { 89 super.setUp(); 90 91 Utils.prepareSingleUser(getDevice()); 92 assertNotNull(mAbi); 93 assertNotNull(mBuildHelper); 94 95 getDevice().uninstallPackage(USES_PERMISSION_PKG); 96 getDevice().uninstallPackage(ESCALATE_PERMISSION_PKG); 97 getDevice().uninstallPackage(PERMISSION_POLICY_25_PKG); 98 99 // Set screen timeout to 30 min to not timeout while waiting for UI to change 100 mScreenTimeoutBeforeTest = getDevice().getSetting(SCREEN_OFF_TIMEOUT_NS, 101 SCREEN_OFF_TIMEOUT_KEY); 102 getDevice().setSetting(SCREEN_OFF_TIMEOUT_NS, SCREEN_OFF_TIMEOUT_KEY, "1800000"); 103 104 // Wake up device 105 getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP"); 106 getDevice().disableKeyguard(); 107 } 108 109 @Override tearDown()110 protected void tearDown() throws Exception { 111 super.tearDown(); 112 113 getDevice().setSetting(SCREEN_OFF_TIMEOUT_NS, SCREEN_OFF_TIMEOUT_KEY, 114 mScreenTimeoutBeforeTest); 115 116 getDevice().uninstallPackage(USES_PERMISSION_PKG); 117 getDevice().uninstallPackage(ESCALATE_PERMISSION_PKG); 118 getDevice().uninstallPackage(PERMISSION_POLICY_25_PKG); 119 } 120 testFail()121 public void testFail() throws Exception { 122 // Sanity check that remote failure is host failure 123 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 124 boolean didThrow = false; 125 try { 126 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 127 "testFail"); 128 } catch (AssertionError expected) { 129 didThrow = true; 130 } 131 if (!didThrow) { 132 fail("Expected remote failure"); 133 } 134 } 135 testKill()136 public void testKill() throws Exception { 137 // Sanity check that remote kill is host failure 138 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 139 boolean didThrow = false; 140 try { 141 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 142 "testKill"); 143 } catch (AssertionError expected) { 144 didThrow = true; 145 } 146 if (!didThrow) { 147 fail("Expected remote failure"); 148 } 149 } 150 151 @AppModeFull(reason = "Instant applications must be at least SDK 26") testCompatDefault22()152 public void testCompatDefault22() throws Exception { 153 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false)); 154 155 approveReviewPermissionDialog(); 156 157 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 158 "testCompatDefault"); 159 } 160 161 @AppModeFull(reason = "Instant applications must be at least SDK 26") testCompatRevoked22()162 public void testCompatRevoked22() throws Exception { 163 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false)); 164 165 approveReviewPermissionDialog(); 166 167 boolean didThrow = false; 168 try { 169 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 170 "testCompatRevoked_part1"); 171 } catch (AssertionError expected) { 172 didThrow = true; 173 } 174 if (!didThrow) { 175 fail("App must be killed on a permission revoke"); 176 } 177 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 178 "testCompatRevoked_part2"); 179 } 180 181 @AppModeFull(reason = "Instant applications must be at least SDK 26") testNoRuntimePrompt22()182 public void testNoRuntimePrompt22() throws Exception { 183 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false)); 184 185 approveReviewPermissionDialog(); 186 187 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 188 "testNoRuntimePrompt"); 189 } 190 testDefault23()191 public void testDefault23() throws Exception { 192 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 193 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 194 "testDefault"); 195 } 196 testGranted23()197 public void testGranted23() throws Exception { 198 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 199 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 200 "testGranted"); 201 } 202 testInteractiveGrant23()203 public void testInteractiveGrant23() throws Exception { 204 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 205 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 206 "testInteractiveGrant"); 207 } 208 testRuntimeGroupGrantSpecificity23()209 public void testRuntimeGroupGrantSpecificity23() throws Exception { 210 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 211 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 212 "testRuntimeGroupGrantSpecificity"); 213 } 214 testRuntimeGroupGrantExpansion23()215 public void testRuntimeGroupGrantExpansion23() throws Exception { 216 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 217 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 218 "testRuntimeGroupGrantExpansion"); 219 } 220 testRuntimeGroupGrantExpansion25()221 public void testRuntimeGroupGrantExpansion25() throws Exception { 222 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_25), false, false)); 223 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 224 "testRuntimeGroupGrantExpansion"); 225 } 226 testRuntimeGroupGrantExpansion26()227 public void testRuntimeGroupGrantExpansion26() throws Exception { 228 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_26), false, false)); 229 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest26", 230 "testRuntimeGroupGrantNoExpansion"); 231 } 232 testRuntimeGroupGrantExpansionLatest()233 public void testRuntimeGroupGrantExpansionLatest() throws Exception { 234 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_Latest), false, false)); 235 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest26", 236 "testRuntimeGroupGrantNoExpansion"); 237 } 238 testCancelledPermissionRequest23()239 public void testCancelledPermissionRequest23() throws Exception { 240 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 241 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 242 "testCancelledPermissionRequest"); 243 } 244 testRequestGrantedPermission23()245 public void testRequestGrantedPermission23() throws Exception { 246 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 247 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 248 "testRequestGrantedPermission"); 249 } 250 testDenialWithPrejudice23()251 public void testDenialWithPrejudice23() throws Exception { 252 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 253 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 254 "testDenialWithPrejudice"); 255 } 256 testRevokeAffectsWholeGroup23()257 public void testRevokeAffectsWholeGroup23() throws Exception { 258 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 259 boolean didThrow = false; 260 try { 261 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 262 "testRevokeAffectsWholeGroup_part1"); 263 } catch (AssertionError expected) { 264 didThrow = true; 265 } 266 if (!didThrow) { 267 fail("Should have thrown an exception."); 268 } 269 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 270 "testRevokeAffectsWholeGroup_part2"); 271 } 272 testGrantPreviouslyRevokedWithPrejudiceShowsPrompt23()273 public void testGrantPreviouslyRevokedWithPrejudiceShowsPrompt23() throws Exception { 274 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 275 boolean didThrow = false; 276 try { 277 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 278 "testGrantPreviouslyRevokedWithPrejudiceShowsPrompt_part1"); 279 } catch (Throwable expected) { 280 didThrow = true; 281 } 282 if (!didThrow) { 283 fail("App must be killed on a permission revoke"); 284 } 285 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 286 "testGrantPreviouslyRevokedWithPrejudiceShowsPrompt_part2"); 287 } 288 testRequestNonRuntimePermission23()289 public void testRequestNonRuntimePermission23() throws Exception { 290 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 291 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 292 "testRequestNonRuntimePermission"); 293 } 294 testRequestNonExistentPermission23()295 public void testRequestNonExistentPermission23() throws Exception { 296 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 297 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 298 "testRequestNonExistentPermission"); 299 } 300 301 @Presubmit testRequestPermissionFromTwoGroups23()302 public void testRequestPermissionFromTwoGroups23() throws Exception { 303 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 304 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 305 "testRequestPermissionFromTwoGroups"); 306 } 307 testUpgradeKeepsPermissions()308 public void testUpgradeKeepsPermissions() throws Exception { 309 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false)); 310 311 approveReviewPermissionDialog(); 312 313 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 314 "testAllPermissionsGrantedByDefault"); 315 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), true, false)); 316 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 317 "testAllPermissionsGrantedOnUpgrade"); 318 } 319 testNoDowngradePermissionModel()320 public void testNoDowngradePermissionModel() throws Exception { 321 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 322 boolean didThrow = false; 323 try { 324 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), true, false)); 325 } catch (AssertionError expected) { 326 didThrow = true; 327 } 328 if (!didThrow) { 329 fail("Permission mode downgrade not allowed"); 330 } 331 } 332 testNoResidualPermissionsOnUninstall()333 public void testNoResidualPermissionsOnUninstall() throws Exception { 334 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 335 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 336 "testNoResidualPermissionsOnUninstall_part1"); 337 assertNull(getDevice().uninstallPackage(USES_PERMISSION_PKG)); 338 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 339 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 340 "testNoResidualPermissionsOnUninstall_part2"); 341 } 342 testRevokePropagatedOnUpgradeOldToNewModel()343 public void testRevokePropagatedOnUpgradeOldToNewModel() throws Exception { 344 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false)); 345 346 approveReviewPermissionDialog(); 347 348 boolean didThrow = false; 349 try { 350 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 351 "testRevokePropagatedOnUpgradeOldToNewModel_part1"); 352 } catch (AssertionError expected) { 353 didThrow = true; 354 } 355 if (!didThrow) { 356 fail("App must be killed on a permission revoke"); 357 } 358 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), true, false)); 359 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 360 "testRevokePropagatedOnUpgradeOldToNewModel_part2"); 361 } 362 testRevokePropagatedOnUpgradeNewToNewModel()363 public void testRevokePropagatedOnUpgradeNewToNewModel() throws Exception { 364 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 365 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 366 "testRevokePropagatedOnUpgradeNewToNewModel_part1"); 367 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), true, false)); 368 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 369 "testRevokePropagatedOnUpgradeNewToNewModel_part2"); 370 } 371 testNoPermissionEscalation()372 public void testNoPermissionEscalation() throws Exception { 373 assertNull(getDevice().installPackage(mBuildHelper.getTestFile( 374 APK_DECLARE_NON_RUNTIME_PERMISSIONS), false, false)); 375 assertNull(getDevice().installPackage(mBuildHelper.getTestFile( 376 APK_ESCLATE_TO_RUNTIME_PERMISSIONS), true, false)); 377 runDeviceTests(ESCALATE_PERMISSION_PKG, 378 "com.android.cts.escalatepermission.PermissionEscalationTest", 379 "testCannotEscalateNonRuntimePermissionsToRuntime"); 380 } 381 testNoProtectionFlagsAddedToNonSignatureProtectionPermissions25()382 public void testNoProtectionFlagsAddedToNonSignatureProtectionPermissions25() throws Exception { 383 assertNull(getDevice().installPackage(mBuildHelper.getTestFile( 384 APK_PERMISSION_POLICY_25), false, false)); 385 runDeviceTests(PERMISSION_POLICY_25_PKG, 386 "com.android.cts.permission.policy.PermissionPolicyTest25", 387 "testNoProtectionFlagsAddedToNonSignatureProtectionPermissions"); 388 } 389 testLegacyAppAccessSerial()390 public void testLegacyAppAccessSerial() throws Exception { 391 assertNull(getDevice().installPackage(mBuildHelper.getTestFile( 392 APK_PERMISSION_POLICY_25), false, false)); 393 runDeviceTests(PERMISSION_POLICY_25_PKG, 394 "com.android.cts.permission.policy.PermissionPolicyTest25", 395 "testNoProtectionFlagsAddedToNonSignatureProtectionPermissions"); 396 } 397 testNullPermissionRequest()398 public void testNullPermissionRequest() throws Exception { 399 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 400 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 401 "testNullPermissionRequest"); 402 } 403 testNullAndRealPermission()404 public void testNullAndRealPermission() throws Exception { 405 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 406 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 407 "testNullAndRealPermission"); 408 } 409 testInvalidPermission()410 public void testInvalidPermission() throws Exception { 411 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false)); 412 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23", 413 "testInvalidPermission"); 414 } 415 testPermissionSplit28()416 public void testPermissionSplit28() throws Exception { 417 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_28), false, false)); 418 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest28", 419 "testLocationPermissionWasSplit"); 420 } 421 testPermissionNotSplit29()422 public void testPermissionNotSplit29() throws Exception { 423 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 424 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 425 "locationPermissionIsNotSplit"); 426 } 427 testRequestOnlyBackgroundNotPossible()428 public void testRequestOnlyBackgroundNotPossible() throws Exception { 429 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 430 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 431 "requestOnlyBackgroundNotPossible"); 432 } 433 testRequestBoth()434 public void testRequestBoth() throws Exception { 435 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 436 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 437 "requestBoth"); 438 } 439 testRequestBothInSequence()440 public void testRequestBothInSequence() throws Exception { 441 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 442 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 443 "requestBothInSequence"); 444 } 445 testRequestBothButGrantInSequence()446 public void testRequestBothButGrantInSequence() throws Exception { 447 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 448 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 449 "requestBothButGrantInSequence"); 450 } 451 testDenyBackgroundWithPrejudice()452 public void testDenyBackgroundWithPrejudice() throws Exception { 453 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_29), false, false)); 454 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 455 "denyBackgroundWithPrejudice"); 456 } 457 testPermissionNotSplitLatest()458 public void testPermissionNotSplitLatest() throws Exception { 459 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_Latest), false, false)); 460 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest29", 461 "locationPermissionIsNotSplit"); 462 } 463 testDenyCalendarDuringReview()464 public void testDenyCalendarDuringReview() throws Exception { 465 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22_ONLY_CALENDAR), false, 466 false)); 467 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 468 true)); 469 470 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, "denyCalendarPermissions"); 471 472 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 473 "testAssertNoCalendarAccess"); 474 } 475 testDenyGrantCalendarDuringReview()476 public void testDenyGrantCalendarDuringReview() throws Exception { 477 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22_ONLY_CALENDAR), false, 478 false)); 479 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 480 true)); 481 482 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, "denyGrantCalendarPermissions"); 483 484 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 485 "testAssertCalendarAccess"); 486 } 487 testDenyGrantDenyCalendarDuringReview()488 public void testDenyGrantDenyCalendarDuringReview() throws Exception { 489 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22_ONLY_CALENDAR), false, 490 false)); 491 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 492 true)); 493 494 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, 495 "denyGrantDenyCalendarPermissions"); 496 497 runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22", 498 "testAssertNoCalendarAccess"); 499 } 500 testCancelReview()501 public void testCancelReview() throws Exception { 502 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22_ONLY_CALENDAR), false, 503 false)); 504 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 505 true)); 506 507 // Start APK_22_ONLY_CALENDAR, but cancel review 508 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, 509 "cancelReviewPermissions"); 510 511 // Start APK_22_ONLY_CALENDAR again, now approve review 512 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, "approveReviewPermissions"); 513 514 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, 515 "assertNoReviewPermissionsNeeded"); 516 } 517 testReviewPermissionWhenServiceIsBound()518 public void testReviewPermissionWhenServiceIsBound() throws Exception { 519 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, 520 false)); 521 assertNull(getDevice().installPackage(mBuildHelper.getTestFile(REVIEW_HELPER_APK), true, 522 true)); 523 524 // Check if service of APK_22 has permissions 525 runDeviceTests(REVIEW_HELPER_PKG, REVIEW_HELPER_TEST_CLASS, 526 "reviewPermissionWhenServiceIsBound"); 527 } 528 runDeviceTests(String packageName, String testClassName, String testMethodName)529 private void runDeviceTests(String packageName, String testClassName, String testMethodName) 530 throws DeviceNotAvailableException { 531 Utils.runDeviceTestsAsCurrentUser(getDevice(), packageName, testClassName, testMethodName); 532 } 533 } 534