public boolean runPermissionTest()

in niap-cc/Permissions/Tester/app/src/main/java/com/android/certifications/niap/permissions/BasePermissionTester.java [153:202]


    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 = permissionGranted;
                StatusLogger.logTestStatus(permission, permissionGranted, true);
            } catch (BypassTestException bte) {
                StatusLogger.logTestSkipped(permission, permissionGranted, bte.getMessage());
            } 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.
                testPassed = !permissionGranted;
                mLogger.logDebug("Caught a SecurityException for permission " + permission + ": ",
                        e);
                if (e.getCause() != null) {
                    mLogger.logDebug("SecuritionException cause: ", e.getCause());
                }
                StatusLogger.logTestStatus(permission, permissionGranted, false);
            } catch (Throwable t) {
                testPassed = false;
                StatusLogger.logTestError(permission, t);
            }
        }
        return testPassed;
    }