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

Commit 2e9c51f5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Added test to check package whitelisting." into rvc-dev am: 8c211a71

Change-Id: I4422798ae7204786f4e845fff9eda27f1c0b1821
parents 33d5f932 8c211a71
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -344,7 +344,7 @@ class UserSystemPackageInstaller {
     */
    @NonNull
    private List<String> getPackagesWhitelistErrors(@PackageWhitelistMode int mode) {
        if ((!isEnforceMode(mode) || isImplicitWhitelistMode(mode)) && !isLogMode(mode)) {
        if ((!isEnforceMode(mode) || isImplicitWhitelistMode(mode))) {
            return Collections.emptyList();
        }

@@ -752,6 +752,10 @@ class UserSystemPackageInstaller {
        } else if (mode == USER_TYPE_PACKAGE_WHITELIST_MODE_DEVICE_DEFAULT) {
            mode = getDeviceDefaultWhitelistMode();
        }
        if (criticalOnly) {
            // Flip-out log mode
            mode &= ~USER_TYPE_PACKAGE_WHITELIST_MODE_LOG;
        }
        Slog.v(TAG, "dumpPackageWhitelistProblems(): using mode " + modeToString(mode));

        final List<String> errors = getPackagesWhitelistErrors(mode);
+16 −0
Original line number Diff line number Diff line
@@ -22,10 +22,14 @@ import android.os.FileUtils;
import android.os.Parcelable;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.test.uiautomator.UiDevice;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
import android.util.AtomicFile;

import androidx.test.InstrumentationRegistry;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -74,6 +78,14 @@ public class UserManagerServiceTest extends AndroidTestCase {
        assertEquals(accountName, um.getUserAccount(tempUserId));
    }

    public void testUserSystemPackageWhitelist() throws Exception {
        String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only";
        final String result = runShellCommand(cmd);
        if (!TextUtils.isEmpty(result)) {
            fail("Command '" + cmd + " reported errors:\n" + result);
        }
    }

    private Bundle createBundle() {
        Bundle result = new Bundle();
        // Tests for 6 allowed types: Integer, Boolean, String, String[], Bundle and Parcelable[]
@@ -118,4 +130,8 @@ public class UserManagerServiceTest extends AndroidTestCase {
        assertEquals(1, childBundle.getInt("bundle_int"));
    }

    private static String runShellCommand(String cmd) throws Exception {
        return UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
                .executeShellCommand(cmd);
    }
}