FileDocCategorySizeDatePackage
PackageVerificationStateTest.javaAPI DocAndroid 5.1 API8198Thu Mar 12 22:22:42 GMT 2015com.android.server.pm

PackageVerificationStateTest

public class PackageVerificationStateTest extends android.test.AndroidTestCase

Fields Summary
private static final int
REQUIRED_UID
private static final int
SUFFICIENT_UID_1
private static final int
SUFFICIENT_UID_2
Constructors Summary
Methods Summary
public voidtestPackageVerificationState_OnlyRequiredVerifier_AllowedInstall()


       
        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_ALLOW);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_OnlyRequiredVerifier_DeniedInstall()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_REJECT);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertFalse("Installation should be marked as allowed",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_RequiredAndOneSufficient_RequiredDeniedInstall()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.addSufficientVerifier(SUFFICIENT_UID_1);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(SUFFICIENT_UID_1, PackageManager.VERIFICATION_ALLOW);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_REJECT);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertFalse("Installation should be marked as allowed",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_RequiredAndOneSufficient_SufficientDeniedInstall()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.addSufficientVerifier(SUFFICIENT_UID_1);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(SUFFICIENT_UID_1, PackageManager.VERIFICATION_REJECT);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_ALLOW);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertFalse("Installation should be marked as allowed",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_RequiredAndTwoSufficient_OneSufficientIsEnough()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.addSufficientVerifier(SUFFICIENT_UID_1);
        state.addSufficientVerifier(SUFFICIENT_UID_2);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(SUFFICIENT_UID_1, PackageManager.VERIFICATION_ALLOW);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_ALLOW);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_RequiredAndTwoSufficient_RequiredOverrides()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.addSufficientVerifier(SUFFICIENT_UID_1);
        state.addSufficientVerifier(SUFFICIENT_UID_2);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID,
                PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);

        assertTrue("Verification should be marked as complete immediately",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed",
                state.isInstallAllowed());

        state.setVerifierResponse(SUFFICIENT_UID_1, PackageManager.VERIFICATION_REJECT);

        assertTrue("Verification should still be marked as completed",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed still",
                state.isInstallAllowed());

        state.setVerifierResponse(SUFFICIENT_UID_2, PackageManager.VERIFICATION_ALLOW);

        assertTrue("Verification should still be complete",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed still",
                state.isInstallAllowed());
    
public voidtestPackageVerificationState_RequiredAndTwoSufficient_SecondSufficientIsEnough()

        PackageVerificationState state = new PackageVerificationState(REQUIRED_UID, null);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.addSufficientVerifier(SUFFICIENT_UID_1);
        state.addSufficientVerifier(SUFFICIENT_UID_2);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(REQUIRED_UID, PackageManager.VERIFICATION_ALLOW);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(SUFFICIENT_UID_1, PackageManager.VERIFICATION_REJECT);

        assertFalse("Verification should not be marked as complete yet",
                state.isVerificationComplete());

        state.setVerifierResponse(SUFFICIENT_UID_2, PackageManager.VERIFICATION_ALLOW);

        assertTrue("Verification should be considered complete now",
                state.isVerificationComplete());

        assertTrue("Installation should be marked as allowed",
                state.isInstallAllowed());