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

Commit ac9e76c8 authored by Winson's avatar Winson
Browse files

Migrate DomainVerificationUtils to no log ChangeId

Uses the isChangeEnabledInternalNoLogging variant, which skips the
caller permission check, which improves performance. Also removes
the need to clear calling identity.

This uses a mocked ApplicationInfo as it can be called during package
update, which means the PM lock cannot be taken. This, and in all other
cases, the method is being called as part of a service side check, post
feature/permission app visibility enforcement, so it should be safe to
skip permission checks.

This isn't enforced, but since DomainVerificationUtils#isChangeEnabled
is only visible inside the DVS package, it should be fine.

Bug: 159952358

Test: atest com.android.server.pm.verify.domain

Change-Id: I9c54e8653d843cfb67fb9d6e12349cf06de90fce
parent 3c05313b
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Binder;

import com.android.internal.util.CollectionUtils;
import com.android.server.compat.PlatformCompat;
@@ -77,9 +76,7 @@ public final class DomainVerificationUtils {

    static boolean isChangeEnabled(PlatformCompat platformCompat, AndroidPackage pkg,
            long changeId) {
        //noinspection ConstantConditions
        return Binder.withCleanCallingIdentity(
                () -> platformCompat.isChangeEnabled(changeId, buildMockAppInfo(pkg)));
        return  platformCompat.isChangeEnabledInternalNoLogging(changeId, buildMockAppInfo(pkg));
    }

    /**
+6 −1
Original line number Diff line number Diff line
@@ -41,7 +41,12 @@ class DomainVerificationCollectorTest {
    }

    private val platformCompat: PlatformCompat = mockThrowOnUnmocked {
        whenever(isChangeEnabled(eq(DomainVerificationCollector.RESTRICT_DOMAINS), any())) {
        whenever(
            isChangeEnabledInternalNoLogging(
                eq(DomainVerificationCollector.RESTRICT_DOMAINS),
                any()
            )
        ) {
            (arguments[1] as ApplicationInfo).targetSdkVersion >= Build.VERSION_CODES.S
        }
    }
+1 −6
Original line number Diff line number Diff line
@@ -114,12 +114,7 @@ class DomainVerificationEnforcerTest {
                    it,
                    mockThrowOnUnmocked { whenever(linkedApps) { ArraySet<String>() } },
                    mockThrowOnUnmocked {
                        whenever(
                            isChangeEnabled(
                                anyLong(),
                                any()
                            )
                        ) { true }
                        whenever(isChangeEnabledInternalNoLogging(anyLong(), any())) { true }
                    }).apply {
                    setConnection(connection)
                }
+1 −1
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ class DomainVerificationManagerApiTest {
            }, mockThrowOnUnmocked {
                whenever(linkedApps) { ArraySet<String>() }
            }, mockThrowOnUnmocked {
                whenever(isChangeEnabled(anyLong(), any())) { true }
                whenever(isChangeEnabledInternalNoLogging(anyLong(), any())) { true }
            }).apply {
                setConnection(mockThrowOnUnmocked {
                    whenever(filterAppAccess(anyString(), anyInt(), anyInt())) { false }
+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.anyString
import java.util.UUID

@@ -366,7 +367,7 @@ class DomainVerificationPackageTest {
            }, mockThrowOnUnmocked {
                whenever(linkedApps) { ArraySet<String>() }
            }, mockThrowOnUnmocked {
                whenever(isChangeEnabled(ArgumentMatchers.anyLong(), any())) { true }
                whenever(isChangeEnabledInternalNoLogging(anyLong(), any())) { true }
            }).apply {
                setConnection(mockThrowOnUnmocked {
                    whenever(filterAppAccess(anyString(), anyInt(), anyInt())) { false }
Loading