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

Commit a10d9b94 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify legacy screen compat mode a bit

The entry of changing legacy screen compat mode is almost a dead code.
The current usage is only from command:
  adb shell am screen-compat [on|off] $packageName

But because the manifest attributes are still valid:
 android:smallScreens/normalScreens/largeScreens
It might be better to preserve the behavior for now.

By caching the legacy compat state in server side and reusing
restartProcessIfVisible for compatibility info change, this can
reduce unnecessary Configuration comparison on every frame from
Display#getDisplayAdjustments(). Also the fields can be removed:
 ViewRootImpl#mLastInCompatMode
 WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW
 ActivityRecord#forceNewConfig

Bug: 163976519
Test: atest CompatModePackagesTests
Test: adb install --bypass-low-target-sdk-block test.apk
      which declares minSdkVersion="1"
      The appearance is not changed and touch can still work.
Test: App (without always/never-compat) can be relaunched and
      scaled when using command:
      adb shell am screen-compat [on|off] $packageName

Change-Id: I661ddaee15014201aa1109671cfd6619df91ea4a
parent c7faccbd
Loading
Loading
Loading
Loading
+1 −28
Original line number Diff line number Diff line
@@ -530,8 +530,6 @@ public final class ViewRootImpl implements ViewParent,
    // Set to true to stop input during an Activity Transition.
    boolean mPausedForTransition = false;

    boolean mLastInCompatMode = false;

    SurfaceHolder.Callback2 mSurfaceHolderCallback;
    BaseSurfaceHolder mSurfaceHolder;
    boolean mIsCreating;
@@ -1362,11 +1360,6 @@ public final class ViewRootImpl implements ViewParent,
                }
                if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs);

                if (!compatibilityInfo.supportsScreen()) {
                    attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
                    mLastInCompatMode = true;
                }

                mSoftInputMode = attrs.softInputMode;
                mWindowAttributesChanged = true;
                mAttachInfo.mRootView = view;
@@ -1900,10 +1893,6 @@ public final class ViewRootImpl implements ViewParent,
            // Keep track of the actual window flags supplied by the client.
            mClientWindowLayoutFlags = attrs.flags;

            // Preserve compatible window flag if exists.
            final int compatibleWindowFlag = mWindowAttributes.privateFlags
                    & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;

            // Preserve system UI visibility.
            final int systemUiVisibility = mWindowAttributes.systemUiVisibility;
            final int subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility;
@@ -1935,8 +1924,7 @@ public final class ViewRootImpl implements ViewParent,
            mWindowAttributes.subtreeSystemUiVisibility = subtreeSystemUiVisibility;
            mWindowAttributes.insetsFlags.appearance = appearance;
            mWindowAttributes.insetsFlags.behavior = behavior;
            mWindowAttributes.privateFlags |= compatibleWindowFlag
                    | appearanceAndBehaviorPrivateFlags;
            mWindowAttributes.privateFlags |= appearanceAndBehaviorPrivateFlags;

            if (mWindowAttributes.preservePreviousSurfaceInsets) {
                // Restore old surface insets.
@@ -3137,21 +3125,6 @@ public final class ViewRootImpl implements ViewParent,
        final boolean shouldOptimizeMeasure = shouldOptimizeMeasure(lp);

        WindowManager.LayoutParams params = null;
        CompatibilityInfo compatibilityInfo =
                mDisplay.getDisplayAdjustments().getCompatibilityInfo();
        if (compatibilityInfo.supportsScreen() == mLastInCompatMode) {
            params = lp;
            mFullRedrawNeeded = true;
            mLayoutRequested = true;
            if (mLastInCompatMode) {
                params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
                mLastInCompatMode = false;
            } else {
                params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
                mLastInCompatMode = true;
            }
        }

        Rect frame = mWinFrame;
        if (mFirst) {
            mFullRedrawNeeded = true;
+0 −12
Original line number Diff line number Diff line
@@ -3137,13 +3137,6 @@ public interface WindowManager extends ViewManager {
        @UnsupportedAppUsage
        public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 1 << 6;

        /** Window flag: special flag to limit the size of the window to be
         * original size ([320x480] x density). Used to create window for applications
         * running under compatibility mode.
         *
         * {@hide} */
        public static final int PRIVATE_FLAG_COMPATIBLE_WINDOW = 1 << 7;

        /** Window flag: a special option intended for system dialogs.  When
         * this flag is set, the window will demand focus unconditionally when
         * it is created.
@@ -3339,7 +3332,6 @@ public interface WindowManager extends ViewManager {
                SYSTEM_FLAG_SHOW_FOR_ALL_USERS,
                PRIVATE_FLAG_UNRESTRICTED_GESTURE_EXCLUSION,
                PRIVATE_FLAG_NO_MOVE_ANIMATION,
                PRIVATE_FLAG_COMPATIBLE_WINDOW,
                PRIVATE_FLAG_SYSTEM_ERROR,
                PRIVATE_FLAG_OPTIMIZE_MEASURE,
                PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS,
@@ -3392,10 +3384,6 @@ public interface WindowManager extends ViewManager {
                        mask = PRIVATE_FLAG_NO_MOVE_ANIMATION,
                        equals = PRIVATE_FLAG_NO_MOVE_ANIMATION,
                        name = "NO_MOVE_ANIMATION"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_COMPATIBLE_WINDOW,
                        equals = PRIVATE_FLAG_COMPATIBLE_WINDOW,
                        name = "COMPATIBLE_WINDOW"),
                @ViewDebug.FlagToString(
                        mask = PRIVATE_FLAG_SYSTEM_ERROR,
                        equals = PRIVATE_FLAG_SYSTEM_ERROR,
+0 −5
Original line number Diff line number Diff line
@@ -277,11 +277,6 @@ public class SplashscreenContentDrawer {
        params.token = appToken;
        params.packageName = activityInfo.packageName;
        params.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;

        if (!context.getResources().getCompatibilityInfo().supportsScreen()) {
            params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
        }

        params.setTitle("Splash Screen " + title);
        return params;
    }
+3 −7
Original line number Diff line number Diff line
@@ -563,7 +563,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    boolean idle;           // has the activity gone idle?
    boolean hasBeenLaunched;// has this activity ever been launched?
    boolean immersive;      // immersive mode (don't interrupt if possible)
    boolean forceNewConfig; // force re-create with new config next time
    boolean supportsEnterPipOnTaskSwitch;  // This flag is set by the system to indicate that the
        // activity can enter picture in picture while pausing (only when switching to another task)
    // The PiP params used when deferring the entering of picture-in-picture.
@@ -9592,7 +9591,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // configurations because there are cases (like moving a task to the root pinned task) where
        // the combine configurations are equal, but would otherwise differ in the override config
        mTmpConfig.setTo(mLastReportedConfiguration.getMergedConfiguration());
        if (getConfiguration().equals(mTmpConfig) && !forceNewConfig && !displayChanged) {
        if (getConfiguration().equals(mTmpConfig) && !displayChanged) {
            ProtoLog.v(WM_DEBUG_CONFIGURATION, "Configuration & display "
                    + "unchanged in %s", this);
            return true;
@@ -9619,7 +9618,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return true;
        }

        if (changes == 0 && !forceNewConfig) {
        if (changes == 0) {
            ProtoLog.v(WM_DEBUG_CONFIGURATION, "Configuration no differences in %s",
                    this);
            // There are no significant differences, so we won't relaunch but should still deliver
@@ -9641,7 +9640,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // pick that up next time it starts.
        if (!attachedToProcess()) {
            ProtoLog.v(WM_DEBUG_CONFIGURATION, "Configuration doesn't matter not running %s", this);
            forceNewConfig = false;
            return true;
        }

@@ -9651,11 +9649,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                Integer.toHexString(changes), Integer.toHexString(info.getRealConfigChanged()),
                mLastReportedConfiguration);

        if (shouldRelaunchLocked(changes, mTmpConfig) || forceNewConfig) {
        if (shouldRelaunchLocked(changes, mTmpConfig)) {
            // Aha, the activity isn't handling the change, so DIE DIE DIE.
            configChangeFlags |= changes;
            startFreezingScreenLocked(globalChanges);
            forceNewConfig = false;
            // Do not preserve window if it is freezing screen because the original window won't be
            // able to update drawn state that causes freeze timeout.
            preserveWindow &= isResizeOnlyChange(changes) && !mFreezingScreen;
@@ -9875,7 +9872,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        try {
            ProtoLog.i(WM_DEBUG_STATES, "Moving to %s Relaunching %s callers=%s" ,
                    (andResume ? "RESUMED" : "PAUSED"), this, Debug.getCallers(6));
            forceNewConfig = false;
            final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(token,
                    pendingResults, pendingNewIntents, configChangeFlags,
                    new MergedConfiguration(getProcessGlobalConfiguration(),
+0 −1
Original line number Diff line number Diff line
@@ -906,7 +906,6 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                }
                mService.getPackageManagerInternalLocked().notifyPackageUse(
                        r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY);
                r.forceNewConfig = false;
                mService.getAppWarningsLocked().onStartActivity(r);

                // Because we could be starting an Activity in the system process this may not go
Loading