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

Commit 6daef580 authored by bsears's avatar bsears Committed by Android (Google) Code Review
Browse files

Merge "Add checks to detect wrong conditions when creating Applications"

parents 29795b0b 9b9ee9dc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4535,6 +4535,12 @@ public final class ActivityThread extends ClientTransactionHandler
        // we are back active so skip it.
        unscheduleGcIdler();

        // To investigate "duplciate Application objects" bug (b/185177290)
        if (UserHandle.myUserId() != UserHandle.getUserId(data.info.applicationInfo.uid)) {
            Slog.wtf(TAG, "handleCreateService called with wrong appinfo UID: myUserId="
                    + UserHandle.myUserId() + " appinfo.uid=" + data.info.applicationInfo.uid);
        }

        LoadedApk packageInfo = getPackageInfoNoCheck(
                data.info.applicationInfo, data.compatInfo);
        Service service = null;
+32 −1
Original line number Diff line number Diff line
@@ -1341,15 +1341,43 @@ public final class LoadedApk {
        return mResources;
    }

    /**
     * Used to investigate "duplicate app objects" bug (b/185177290).
     * makeApplication() should only be called on the main thread, so no synchronization should
     * be needed, but syncing anyway just in case.
     */
    @GuardedBy("sApplicationCache")
    private static final ArrayMap<String, Application> sApplicationCache = new ArrayMap<>(4);

    @UnsupportedAppUsage
    public Application makeApplication(boolean forceDefaultAppClass,
            Instrumentation instrumentation) {
        if (mApplication != null) {
            return mApplication;
        }

        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "makeApplication");

        // For b/185177290.
        final boolean wrongUser =
                UserHandle.myUserId() != UserHandle.getUserId(mApplicationInfo.uid);
        if (wrongUser) {
            Slog.wtf(TAG, "makeApplication called with wrong appinfo UID: myUserId="
                    + UserHandle.myUserId() + " appinfo.uid=" + mApplicationInfo.uid);
        }
        synchronized (sApplicationCache) {
            final Application cached = sApplicationCache.get(mPackageName);
            if (cached != null) {
                // Looks like this is always happening for the system server, because
                // the LoadedApk created in systemMain() -> attach() isn't cached properly?
                if (!"android".equals(mPackageName)) {
                    Slog.wtf(TAG, "App instance already created for package=" + mPackageName
                            + " instance=" + cached);
                }
                // TODO Return the cached one, unles it's for the wrong user?
                // For now, we just add WTF checks.
            }
        }

        Application app = null;

        final String myProcessName = Process.myProcessName();
@@ -1397,6 +1425,9 @@ public final class LoadedApk {
        }
        mActivityThread.mAllApplications.add(app);
        mApplication = app;
        synchronized (sApplicationCache) {
            sApplicationCache.put(mPackageName, app);
        }

        if (instrumentation != null) {
            try {