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

Commit d1ff8ae8 authored by Garfield Tan's avatar Garfield Tan
Browse files

Use RootTDAOrganizer to determine caption visibility

This is a remnant of ag/26927955.

It's possible that root TDA info is unavailable when we need to decide
the visibility of decor captions if a display and a task on that display
show up roughly at the same time. Instead of ensuring the order of
events, it's easier to "guess" the need of captions using other signals.
Ultimately other modes of freeform tasks (e.g. desktop mode) need to
have their own implementations of window decors & window decor view
models, in which they have full knowledge of whether their window decors
should show up without relying on info from higher containers. Root
TDA's windowing mode should also be controlled by WM shell in those
cases as well.

Bug: 333724879
Test: Captions show up as expected.
Change-Id: Ia3f0ffb3ee02fb9a993952dc3cfa7ac210b2f160
parent 618d1f82
Loading
Loading
Loading
Loading
+45 −4
Original line number Original line Diff line number Diff line
@@ -19,14 +19,19 @@ package com.android.wm.shell.windowdecor;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.pm.PackageManager.FEATURE_PC;
import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CHANGE;


import android.app.ActivityManager.RunningTaskInfo;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Handler;
import android.provider.Settings;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Choreographer;
import android.view.Choreographer;
import android.view.Display;
import android.view.MotionEvent;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
import android.view.View;
import android.view.View;
@@ -163,10 +168,33 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
    }
    }


    private boolean shouldShowWindowDecor(RunningTaskInfo taskInfo) {
    private boolean shouldShowWindowDecor(RunningTaskInfo taskInfo) {
        return taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM
        if (taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM) {
                || (taskInfo.getActivityType() == ACTIVITY_TYPE_STANDARD
            return true;
                && taskInfo.configuration.windowConfiguration.getDisplayWindowingMode()
        }
                == WINDOWING_MODE_FREEFORM);
        if (taskInfo.getActivityType() != ACTIVITY_TYPE_STANDARD) {
            return false;
        }
        final DisplayAreaInfo rootDisplayAreaInfo =
                mRootTaskDisplayAreaOrganizer.getDisplayAreaInfo(taskInfo.displayId);
        if (rootDisplayAreaInfo != null) {
            return rootDisplayAreaInfo.configuration.windowConfiguration.getWindowingMode()
                    == WINDOWING_MODE_FREEFORM;
        }

        // It is possible that the rootDisplayAreaInfo is null when a task appears soon enough after
        // a new display shows up, because TDA may appear after task appears in WM shell. Instead of
        // fixing the synchronization issues, let's use other signals to "guess" the answer. It is
        // OK in this context because no other captions other than the legacy developer option
        // freeform and Kingyo/CF PC may use this class. WM shell should have full control over the
        // condition where captions should show up in all new cases such as desktop mode, for which
        // we should use different window decor view models. Ultimately Kingyo/CF PC may need to
        // spin up their own window decor view model when they start to care about multiple
        // displays.
        if (isPc()) {
            return true;
        }
        return taskInfo.displayId != Display.DEFAULT_DISPLAY
                && forcesDesktopModeOnExternalDisplays();
    }
    }


    private void createWindowDecoration(
    private void createWindowDecoration(
@@ -313,4 +341,17 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
            return true;
            return true;
        }
        }
    }
    }

    /**
     * Returns if this device is a PC.
     */
    private boolean isPc() {
        return mContext.getPackageManager().hasSystemFeature(FEATURE_PC);
    }

    private boolean forcesDesktopModeOnExternalDisplays() {
        final ContentResolver resolver = mContext.getContentResolver();
        return Settings.Global.getInt(resolver,
                DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0) != 0;
    }
}
}
 No newline at end of file