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

Commit 095da031 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Send latest configuration for binding process

Before a process completes attaching, its configuration won't be
updated with system. Then if there is a global change happens in
this period, the client process will get old configuration which
is assigned when creating the process record.

So this change popluates the needed info in a single invocation
when the process is attaching. Then the client can start with the
latest configuration.

This would also benefit:
- Reduce entering WM lock from AM's compatibilityInfoForPackage.
- Copy configuration inside WM lock to ensure data consistency.

Bug: 362215030
Flag: EXEMPT bugfix
Test: atest ActivityTaskManagerServiceTests

Change-Id: I4af30c62864eefb9897120ba46ebd0c7e3fc8231
parent 2f4e0476
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -299,7 +299,6 @@ import android.content.pm.TestUtilityService;
import android.content.pm.UserInfo;
import android.content.pm.UserProperties;
import android.content.pm.VersionedPackage;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
@@ -2971,10 +2970,6 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) {
        return mAtmInternal.compatibilityInfoForPackage(ai);
    }
    /**
     * Enforces that the uid that calls a method is not an
     * {@link UserHandle#isIsolated(int) isolated} uid.
@@ -4635,7 +4630,6 @@ public class ActivityManagerService extends IActivityManager.Stub
            ProtoLog.v(WM_DEBUG_CONFIGURATION, "Binding proc %s with config %s",
                    processName, app.getWindowProcessController().getConfiguration());
            ApplicationInfo appInfo = instr != null ? instr.mTargetInfo : app.info;
            app.setCompat(compatibilityInfoForPackage(appInfo));
            ProfilerInfo profilerInfo = mAppProfiler.setupProfilerInfoLocked(thread, app, instr);
@@ -4674,7 +4668,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            checkTime(startTime, "attachApplicationLocked: immediately before bindApplication");
            bindApplicationTimeMillis = SystemClock.uptimeMillis();
            bindApplicationTimeNanos = SystemClock.uptimeNanos();
            mAtmInternal.preBindApplication(app.getWindowProcessController());
            final ActivityTaskManagerInternal.PreBindInfo preBindInfo =
                    mAtmInternal.preBindApplication(app.getWindowProcessController(), appInfo);
            app.setCompat(preBindInfo.compatibilityInfo);
            final ActiveInstrumentation instr2 = app.getActiveInstrumentation();
            if (mPlatformCompat != null) {
                mPlatformCompat.resetReporting(app.info);
@@ -4716,7 +4712,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        enableTrackAllocation,
                        isRestrictedBackupMode || !normalMode,
                        app.isPersistent(),
                        new Configuration(app.getWindowProcessController().getConfiguration()),
                        preBindInfo.configuration,
                        app.getCompat(),
                        getCommonServicesLocked(app.isolated),
                        mCoreSettingsObserver.getCoreSettingsLocked(),
+13 −2
Original line number Diff line number Diff line
@@ -380,7 +380,16 @@ public abstract class ActivityTaskManagerInternal {
    public abstract void onPackageAdded(String name, boolean replacing);
    public abstract void onPackageReplaced(ApplicationInfo aInfo);

    public abstract CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai);
    /** The data for IApplicationThread#bindApplication. */
    public static final class PreBindInfo {
        public final @NonNull CompatibilityInfo compatibilityInfo;
        public final @NonNull Configuration configuration;

        PreBindInfo(@NonNull CompatibilityInfo compatInfo, @NonNull Configuration config) {
            compatibilityInfo = compatInfo;
            configuration = config;
        }
    }

    public final class ActivityTokens {
        private final @NonNull IBinder mActivityToken;
@@ -502,7 +511,9 @@ public abstract class ActivityTaskManagerInternal {
    public abstract void resumeTopActivities(boolean scheduleIdle);

    /** Called by AM just before it binds to an application process. */
    public abstract void preBindApplication(WindowProcessController wpc);
    @NonNull
    public abstract PreBindInfo preBindApplication(@NonNull WindowProcessController wpc,
            @NonNull ApplicationInfo info);

    /** Called by AM when an application process attaches. */
    public abstract boolean attachApplication(WindowProcessController wpc) throws RemoteException;
+5 −8
Original line number Diff line number Diff line
@@ -6420,13 +6420,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public CompatibilityInfo compatibilityInfoForPackage(ApplicationInfo ai) {
            synchronized (mGlobalLock) {
                return compatibilityInfoForPackageLocked(ai);
            }
        }

        @Override
        public void sendActivityResult(int callingUid, IBinder activityToken, String resultWho,
                int requestCode, int resultCode, Intent data) {
@@ -6705,9 +6698,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

        @HotPath(caller = HotPath.PROCESS_CHANGE)
        @Override
        public void preBindApplication(WindowProcessController wpc) {
        public PreBindInfo preBindApplication(WindowProcessController wpc, ApplicationInfo info) {
            synchronized (mGlobalLockWithoutBoost) {
                mTaskSupervisor.getActivityMetricsLogger().notifyBindApplication(wpc.mInfo);
                wpc.onConfigurationChanged(getGlobalConfiguration());
                // The "info" can be the target of instrumentation.
                return new PreBindInfo(compatibilityInfoForPackageLocked(info),
                        new Configuration(wpc.getConfiguration()));
            }
        }

+0 −1
Original line number Diff line number Diff line
@@ -357,7 +357,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        mUseFifoUiScheduling = com.android.window.flags.Flags.fifoPriorityForMajorUiProcesses()
                && (isSysUiPackage || mAtm.isCallerRecents(uid));

        onConfigurationChanged(atm.getGlobalConfiguration());
        mAtm.mPackageConfigPersister.updateConfigIfNeeded(this, mUserId, mInfo.packageName);
    }

+1 −0
Original line number Diff line number Diff line
@@ -1047,6 +1047,7 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
        info.packageName = packageName;
        WindowProcessController wpc = new WindowProcessController(
                mAtm, info, packageName, 0, userId, null, mMockListener);
        mAtm.mInternal.preBindApplication(wpc, info);
        wpc.setThread(mock(IApplicationThread.class));
        return wpc;
    }