Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 648e6c83 authored by Songchun Fan's avatar Songchun Fan Committed by Android Build Coastguard Worker
Browse files

Revert "[ADI][UserConfirmation][3/4] Add unit tests for ConfirmVerification dialogs"

FLAG: EXEMPT just revert
BUG: 422535876
Test: n/a just revert

This reverts commit ab82951d.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d2fda58cc1847b4d84c88dfe435fbf868535f21d)
Merged-In: I575ae1d4b3587bebbe019088b89bb430b22eee9b
Change-Id: I575ae1d4b3587bebbe019088b89bb430b22eee9b
parent 9b806154
Loading
Loading
Loading
Loading
+0 −23
Original line number Original line Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test {
    name: "PackageInstallerAppUnitTests",
    manifest: "AndroidManifest.xml",
    srcs: ["src/**/*.java"],
    static_libs: [
        "androidx.test.runner",
        "androidx.test.rules",
        "mockito-target-minus-junit4",
        "junit",
        "truth",
    ],
    instrumentation_for: "PackageInstaller",
    certificate: "platform",
}
+0 −14
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.packageinstaller.test">

  <application android:label="PackageInstallerApplication Tests">
    <uses-library android:name="android.test.runner" />
  </application>

  <instrumentation
      android:name="androidx.test.runner.AndroidJUnitRunner"
      android:label="PackageInstallerApp Unit Tests"
      android:targetPackage="com.android.packageinstaller" />
</manifest>
+0 −95
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.packageinstaller.test;

import static android.content.pm.PackageInstaller.VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE;
import static android.content.pm.PackageInstaller.VERIFICATION_FAILED_REASON_PACKAGE_BLOCKED;
import static android.content.pm.PackageInstaller.VERIFICATION_FAILED_REASON_UNKNOWN;
import static android.content.pm.PackageInstaller.VERIFICATION_POLICY_BLOCK_FAIL_CLOSED;
import static android.content.pm.PackageInstaller.VERIFICATION_POLICY_BLOCK_FAIL_OPEN;

import static com.android.packageinstaller.ConfirmVerification.FLAG_VERIFICATION_FAILED_MAY_BYPASS;
import static com.android.packageinstaller.ConfirmVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY;
import static com.android.packageinstaller.ConfirmVerification.FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS;

import static com.google.common.truth.Truth.assertThat;

import android.content.pm.PackageInstaller.VerificationUserConfirmationInfo;

import com.android.packageinstaller.ConfirmVerification;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class VerificationConfirmationDialogTest {

    @Test
    public void policyOpen_packageBlocked_onlyAck() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        VERIFICATION_FAILED_REASON_PACKAGE_BLOCKED));

        assertThat(flag).isEqualTo(0);
    }

    @Test
    public void policyOpen_noNetwork_mayRetryMayBypass() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_RETRY_MAY_BYPASS);
    }

    @Test
    public void policyOpen_unknown_mayBypass() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_OPEN,
                        VERIFICATION_FAILED_REASON_UNKNOWN));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_BYPASS);
    }

    @Test
    public void policyClosed_packageBlocked_onlyAck() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        VERIFICATION_FAILED_REASON_PACKAGE_BLOCKED));

        assertThat(flag).isEqualTo(0);
    }

    @Test
    public void policyClosed_noNetwork_mayRetry() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        VERIFICATION_FAILED_REASON_NETWORK_UNAVAILABLE));

        assertThat(flag).isEqualTo(FLAG_VERIFICATION_FAILED_MAY_RETRY);
    }

    @Test
    public void policyClosed_unknown_onlyAck() {
        int flag = ConfirmVerification.getUserConfirmationDialogFlag(
                new VerificationUserConfirmationInfo(VERIFICATION_POLICY_BLOCK_FAIL_CLOSED,
                        VERIFICATION_FAILED_REASON_UNKNOWN));

        assertThat(flag).isEqualTo(0);
    }
}