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

Commit 7ae1299c authored by Alex Light's avatar Alex Light Committed by Gerrit Code Review
Browse files

Merge "Perform agent startup-attach before bind"

parents 8172f451 2d0691c7
Loading
Loading
Loading
Loading
+30 −20
Original line number Diff line number Diff line
@@ -1157,6 +1157,10 @@ public final class ActivityThread extends ClientTransactionHandler {
            sendMessage(H.ATTACH_AGENT, agent);
        }

        public void attachStartupAgents(String dataDir) {
            sendMessage(H.ATTACH_STARTUP_AGENTS, dataDir);
        }

        public void setSchedulingGroup(int group) {
            // Note: do this immediately, since going into the foreground
            // should happen regardless of what pending work we have to do
@@ -1806,6 +1810,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        public static final int EXECUTE_TRANSACTION = 159;
        public static final int RELAUNCH_ACTIVITY = 160;
        public static final int PURGE_RESOURCES = 161;
        public static final int ATTACH_STARTUP_AGENTS = 162;

        String codeToString(int code) {
            if (DEBUG_MESSAGES) {
@@ -1849,6 +1854,7 @@ public final class ActivityThread extends ClientTransactionHandler {
                    case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION";
                    case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY";
                    case PURGE_RESOURCES: return "PURGE_RESOURCES";
                    case ATTACH_STARTUP_AGENTS: return "ATTACH_STARTUP_AGENTS";
                }
            }
            return Integer.toString(code);
@@ -2031,6 +2037,9 @@ public final class ActivityThread extends ClientTransactionHandler {
                case PURGE_RESOURCES:
                    schedulePurgeIdler();
                    break;
                case ATTACH_STARTUP_AGENTS:
                    handleAttachStartupAgents((String) msg.obj);
                    break;
            }
            Object obj = msg.obj;
            if (obj instanceof SomeArgs) {
@@ -3729,6 +3738,27 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
    }

    static void handleAttachStartupAgents(String dataDir) {
        try {
            Path code_cache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath();
            if (!Files.exists(code_cache)) {
                return;
            }
            Path startup_path = code_cache.resolve("startup_agents");
            if (Files.exists(startup_path)) {
                for (Path p : Files.newDirectoryStream(startup_path)) {
                    handleAttachAgent(
                            p.toAbsolutePath().toString()
                            + "="
                            + dataDir,
                            null);
                }
            }
        } catch (Exception e) {
            // Ignored.
        }
    }

    private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();

    /**
@@ -6366,26 +6396,6 @@ public final class ActivityThread extends ClientTransactionHandler {
        NetworkSecurityConfigProvider.install(appContext);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);


        if (isAppDebuggable) {
            try {
                // Load all the agents in the code_cache/startup_agents directory.
                // We pass the absolute path to the data_dir as an argument.
                Path startup_path = appContext.getCodeCacheDir().toPath().resolve("startup_agents");
                if (Files.exists(startup_path)) {
                    for (Path p : Files.newDirectoryStream(startup_path)) {
                        handleAttachAgent(
                                p.toAbsolutePath().toString()
                                + "="
                                + appContext.getDataDir().toPath().toAbsolutePath().toString(),
                                data.info);
                    }
                }
            } catch (Exception e) {
                // Ignored.
            }
        }

        // Continue loading instrumentation.
        if (ii != null) {
            ApplicationInfo instrApp;
+10 −1
Original line number Diff line number Diff line
@@ -739,12 +739,21 @@ class ContextImpl extends Context {
    public File getCodeCacheDir() {
        synchronized (mSync) {
            if (mCodeCacheDir == null) {
                mCodeCacheDir = new File(getDataDir(), "code_cache");
                mCodeCacheDir = getCodeCacheDirBeforeBind(getDataDir());
            }
            return ensurePrivateCacheDirExists(mCodeCacheDir, XATTR_INODE_CODE_CACHE);
        }
    }

    /**
     * Helper for getting code-cache dir potentially before application bind.
     *
     * @hide
     */
    static File getCodeCacheDirBeforeBind(File dataDir) {
        return new File(dataDir, "code_cache");
    }

    @Override
    public File getExternalCacheDir() {
        // Operates on primary external storage
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ oneway interface IApplicationThread {
            IVoiceInteractor voiceInteractor);
    void handleTrustStorageUpdate();
    void attachAgent(String path);
    void attachStartupAgents(String dataDir);
    void scheduleApplicationInfoChanged(in ApplicationInfo ai);
    void setNetworkBlockSeq(long procStateSeq);
    void scheduleTransaction(in ClientTransaction transaction);
+4 −0
Original line number Diff line number Diff line
@@ -610,6 +610,10 @@ public class TransactionParcelTests {
        public void attachAgent(String s) throws RemoteException {
        }

        @Override
        public void attachStartupAgents(String s) throws RemoteException {
        }

        @Override
        public void scheduleApplicationInfoChanged(ApplicationInfo applicationInfo)
                throws RemoteException {
+4 −2
Original line number Diff line number Diff line
@@ -271,8 +271,8 @@ import android.os.WorkSource;
import android.os.storage.IStorageManager;
import android.os.storage.StorageManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.DeviceConfig.Properties;
import android.provider.Settings;
import android.server.ServerProtoEnums;
import android.sysprop.VoldProperties;
import android.text.TextUtils;
@@ -5013,7 +5013,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            if (preBindAgent != null) {
                thread.attachAgent(preBindAgent);
            }
            if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
                thread.attachStartupAgents(app.info.dataDir);
            }
            // Figure out whether the app needs to run in autofill compat mode.
            AutofillOptions autofillOptions = null;