in niap-cc/Permissions/Tester/app/src/main/java/com/android/certifications/niap/permissions/SignaturePermissionTester.java [3023:3076]
public boolean runPermissionTest(String permission, PermissionTest test) {
boolean testPassed = true;
// if the permission does not exist then skp the test and return immediately
if (!mPlatformPermissions.contains(permission)) {
mLogger.logDebug("The permission " + permission
+ " is not declared by the platform on this device");
return true;
}
if (mDeviceApiLevel < test.mMinApiLevel) {
mLogger.logDebug(
"permission " + permission + " is targeted for min API " + test.mMinApiLevel
+ "; device API is " + mDeviceApiLevel);
return true;
} else if (mDeviceApiLevel > test.mMaxApiLevel) {
mLogger.logDebug(
"permission " + permission + " is targeted for max API " + test.mMaxApiLevel
+ "; device API is " + mDeviceApiLevel);
return true;
}
if (test.mIsCustom) {
test.runTest();
} else {
boolean permissionGranted = isPermissionGranted(permission);
try {
test.runTest();
// If the permission was granted then a SecurityException should not have been
// thrown so the result of the test should match whether the permission was granted.
testPassed = getAndLogTestStatus(permission, permissionGranted, true);
} catch (SecurityException e) {
// Similar to above if the permission was not granted then a SecurityException
// should have been thrown so the result of the test should be the opposite of
// whether the permission was granted.
mLogger.logDebug(
"Caught a SecurityException for permission " + permission + ": ", e);
if (e.getCause() != null) {
mLogger.logDebug("Cause of SecurityException: ", e.getCause());
}
testPassed = getAndLogTestStatus(permission, permissionGranted, false);
} catch (BypassTestException bte) {
StatusLogger.logTestSkipped(permission, permissionGranted, bte.getMessage());
} catch (Throwable t) {
// Some of the signature / privileged tests can fail for other reasons (primarily
// due to the test app not having access to all necessary classes to invoke the
// APIs guarded by signature permissions), but if they make it past the
// SecurityException then the API should be considered successfully invoked.
if (Constants.DEBUG) {
mLogger.logDebug("Caught a Throwable for permission " + permission + ": ", t);
}
testPassed = getAndLogTestStatus(permission, permissionGranted, true);
}
}
return testPassed;
}