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

Commit 639393e1 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Add overlayable configurator resources

This change adds string/config_overlayableConfigurator and
array/config_overlayableConfiguratorTargets.

string/config_overlayableConfigurator represent the package name that
is recognized as an actor for the packages listed in
@array/config_overlayableConfiguratorTargets. If an overlay targeting
one of the listed targets is signed with the same signature as the
configurator, the overlay will be granted the "actor" policy.

This change does not affect package visibility nor does it grant the
configurator permission to enable/disable overlays targeting the
listed target packages.

Bug: 154610560
Test: atest OverlayManagerServiceImplTests
Change-Id: Id4a803ec179bfeba1b4c5e14bedd18f4cd5d5b23
parent 745202ff
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -4437,4 +4437,11 @@
    <bool name="config_pdp_reject_enable_retry">false</bool>
    <!-- pdp data reject retry delay in ms -->
    <integer name="config_pdp_reject_retry_delay_ms">-1</integer>

    <!-- Package name that is recognized as an actor for the packages listed in
         @array/config_overlayableConfiguratorTargets. If an overlay targeting one of the listed
         targets is signed with the same signature as the configurator, the overlay will be granted
         the "actor" policy. -->
    <string name="config_overlayableConfigurator" translatable="false" />
    <string-array name="config_overlayableConfiguratorTargets" translatable="false" />
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -4021,4 +4021,6 @@
  <java-symbol type="string" name="config_pdp_reject_service_not_subscribed" />
  <java-symbol type="string" name="config_pdp_reject_multi_conn_to_same_pdn_not_allowed" />

  <java-symbol type="string" name="config_overlayableConfigurator" />
  <java-symbol type="array" name="config_overlayableConfiguratorTargets" />
</resources>
+7 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.util.Slog;

import com.android.server.FgThread;

import java.io.File;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

@@ -124,9 +125,13 @@ class IdmapDaemon {
        }
    }

    String getIdmapPath(String overlayPath, int userId) throws TimeoutException, RemoteException {
    boolean idmapExists(String overlayPath, int userId) {
        try (Connection c = connect()) {
            return mService.getIdmapPath(overlayPath, userId);
            return new File(mService.getIdmapPath(overlayPath, userId)).isFile();
        } catch (Exception e) {
            Slog.wtf(TAG, "failed to check if idmap exists for " + overlayPath + ": "
                    + e.getMessage());
            return false;
        }
    }

+20 −20
Original line number Diff line number Diff line
@@ -27,10 +27,10 @@ import android.content.pm.PackageInfo;
import android.os.Build.VERSION_CODES;
import android.os.OverlayablePolicy;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.Slog;

import java.io.File;
import com.android.internal.util.ArrayUtils;

import java.io.IOException;

/**
@@ -55,12 +55,16 @@ class IdmapManager {
        VENDOR_IS_Q_OR_LATER = isQOrLater;
    }

    private final OverlayableInfoCallback mOverlayableCallback;
    private final IdmapDaemon mIdmapDaemon;
    private final OverlayableInfoCallback mOverlayableCallback;
    private final String mOverlayableConfigurator;
    private final String[] mOverlayableConfiguratorTargets;

    IdmapManager(final OverlayableInfoCallback verifyCallback) {
    IdmapManager(final IdmapDaemon idmapDaemon, final OverlayableInfoCallback verifyCallback) {
        mOverlayableCallback = verifyCallback;
        mIdmapDaemon = IdmapDaemon.getInstance();
        mIdmapDaemon = idmapDaemon;
        mOverlayableConfigurator = verifyCallback.getOverlayableConfigurator();
        mOverlayableConfiguratorTargets = verifyCallback.getOverlayableConfiguratorTargets() ;
    }

    /**
@@ -103,23 +107,11 @@ class IdmapManager {
    }

    boolean idmapExists(@NonNull final OverlayInfo oi) {
        return new File(getIdmapPath(oi.baseCodePath, oi.userId)).isFile();
        return mIdmapDaemon.idmapExists(oi.baseCodePath, oi.userId);
    }

    boolean idmapExists(@NonNull final PackageInfo overlayPackage, final int userId) {
        return new File(getIdmapPath(overlayPackage.applicationInfo.getBaseCodePath(), userId))
            .isFile();
    }

    private @NonNull String getIdmapPath(@NonNull final String overlayPackagePath,
            final int userId) {
        try {
            return mIdmapDaemon.getIdmapPath(overlayPackagePath, userId);
        } catch (Exception e) {
            Slog.w(TAG, "failed to get idmap path for " + overlayPackagePath + ": "
                    + e.getMessage());
            return "";
        }
        return mIdmapDaemon.idmapExists(overlayPackage.applicationInfo.getBaseCodePath(), userId);
    }

    /**
@@ -198,9 +190,17 @@ class IdmapManager {
        String targetOverlayableName = overlayPackage.targetOverlayableName;
        if (targetOverlayableName != null) {
            try {
                if (!mOverlayableConfigurator.isEmpty()
                        && ArrayUtils.contains(mOverlayableConfiguratorTargets,
                                targetPackage.packageName)
                        && mOverlayableCallback.signaturesMatching(mOverlayableConfigurator,
                                overlayPackage.packageName, userId)) {
                    return true;
                }

                OverlayableInfo overlayableInfo = mOverlayableCallback.getOverlayableForTarget(
                        targetPackage.packageName, targetOverlayableName, userId);
                if (overlayableInfo != null) {
                if (overlayableInfo != null && overlayableInfo.actor != null) {
                    String actorPackageName = OverlayActorEnforcer.getPackageNameForActor(
                            overlayableInfo.actor, mOverlayableCallback.getNamedActors()).first;
                    if (mOverlayableCallback.signaturesMatching(actorPackageName,
+2 −2
Original line number Diff line number Diff line
@@ -50,8 +50,8 @@ public class OverlayActorEnforcer {
    /**
     * @return nullable actor result with {@link ActorState} failure status
     */
    static Pair<String, ActorState> getPackageNameForActor(String actorUriString,
            Map<String, Map<String, String>> namedActors) {
    static Pair<String, ActorState> getPackageNameForActor(@NonNull String actorUriString,
            @NonNull Map<String, Map<String, String>> namedActors) {
        Uri actorUri = Uri.parse(actorUriString);

        String actorScheme = actorUri.getScheme();
Loading