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

Commit 50fff3b2 authored by Winson's avatar Winson
Browse files

Rebuild actor map if it's queried before onSystemReady

If a package is installed shortly after initial boot, it's possible
to query app filtering before the onSystemReady callback.

Instead of throwing an exception, this makes it just rebuild the map
on demand. This may result in a slight delay with the first initial
query, but that will be the extent of the performance impact.

Scanning should still prevent querying until the mapping is ready,
which avoids large rebuliding costs. Effectively the map is ready
to be built in this edge case, but the callback isn't instant.

Bug: 161816449

Test: atest com.android.server.om.OverlayReferenceMapperTests

Change-Id: I1c815cdc037e297198294b1517805ffebc759e3a
parent f6f77de3
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -18,14 +18,15 @@ package com.android.server.om;

import android.annotation.NonNull;
import android.annotation.Nullable;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import android.text.TextUtils;
import android.util.Pair;
import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.CollectionUtils;
import com.android.server.SystemConfig;
import com.android.server.pm.parsing.pkg.AndroidPackage;

import java.util.Collections;
import java.util.HashMap;
@@ -72,6 +73,8 @@ import java.util.Set;
 */
public class OverlayReferenceMapper {

    private static final String TAG = "OverlayReferenceMapper";

    private final Object mLock = new Object();

    /**
@@ -144,7 +147,7 @@ public class OverlayReferenceMapper {

    public boolean isValidActor(@NonNull String targetName, @NonNull String actorPackageName) {
        synchronized (mLock) {
            assertMapBuilt();
            ensureMapBuilt();
            Set<String> validSet = mActorPkgToPkgs.get(actorPackageName);
            return validSet != null && validSet.contains(targetName);
        }
@@ -292,10 +295,11 @@ public class OverlayReferenceMapper {
        }
    }

    private void assertMapBuilt() {
    private void ensureMapBuilt() {
        if (mDeferRebuild) {
            throw new IllegalStateException("The actor map must be built by calling "
                    + "rebuildIfDeferred before it is queried");
            rebuildIfDeferred();
            Slog.w(TAG, "The actor map was queried before the system was ready, which may"
                    + "result in decreased performance.");
        }
    }

@@ -360,7 +364,7 @@ public class OverlayReferenceMapper {
         * Given the actor string from an overlayable definition, return the actor's package name.
         */
        @Nullable
        String getActorPkg(String actor);
        String getActorPkg(@NonNull String actor);

        /**
         * Mock response of multiple overlay tags.
+1 −5
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.testng.Assert.assertThrows

@RunWith(Parameterized::class)
class OverlayReferenceMapperTests {
@@ -160,9 +159,6 @@ class OverlayReferenceMapperTests {
        expected.forEach { (actorPkgName, expectedPkgNames) ->
            expectedPkgNames.forEach { expectedPkgName ->
                if (deferRebuild) {
                    assertThrows(IllegalStateException::class.java) {
                        mapper.isValidActor(expectedPkgName, actorPkgName)
                    }
                    mapper.rebuildIfDeferred()
                    deferRebuild = false
                }
@@ -187,7 +183,7 @@ class OverlayReferenceMapperTests {
                )
        )
    ) = OverlayReferenceMapper(deferRebuild, object : OverlayReferenceMapper.Provider {
        override fun getActorPkg(actor: String?) =
        override fun getActorPkg(actor: String) =
                OverlayActorEnforcer.getPackageNameForActor(actor, namedActors).first

        override fun getTargetToOverlayables(pkg: AndroidPackage) =