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

Commit 868651a7 authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Respect the app requested orientation in kids mode" into main

parents f4604875 695d061a
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -70,20 +70,4 @@ interface ITaskOrganizerController {

    /** Updates a state of camera compat control for stretched issues in the viewfinder. */
    void updateCameraCompatControlState(in WindowContainerToken task, int state);

    /**
     * Controls whether ignore orientation request logic in {@link
     * com.android.server.wm.DisplayArea} is disabled at runtime and how to optionally map some
     * requested orientations to others.
     *
     * @param isDisabled when {@code true}, the system always ignores the value of {@link
     *                   com.android.server.wm.DisplayArea#getIgnoreOrientationRequest} and app
     *                   requested orientation is respected.
     * @param fromOrientations The orientations we want to map to the correspondent orientations
     *                        in toOrientation.
     * @param toOrientations The orientations we map to the ones in fromOrientations at the same
     *                       index
     */
     void setOrientationRequestPolicy(boolean isIgnoreOrientationRequestDisabled,
            in int[] fromOrientations, in int[] toOrientations);
}
+0 −25
Original line number Diff line number Diff line
@@ -265,31 +265,6 @@ public class TaskOrganizer extends WindowOrganizer {
        }
    }

    /**
     * Controls whether ignore orientation request logic in {@link
     * com.android.server.wm.DisplayArea} is disabled at runtime and how to optionally map some
     * requested orientation to others.
     *
     * @param isIgnoreOrientationRequestDisabled when {@code true}, the system always ignores the
     *           value of  {@link com.android.server.wm.DisplayArea#getIgnoreOrientationRequest}
     *           and app requested orientation is respected.
     * @param fromOrientations The orientations we want to map to the correspondent orientations
     *                        in toOrientation.
     * @param toOrientations The orientations we map to the ones in fromOrientations at the same
     *                       index
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_TASKS)
    public void setOrientationRequestPolicy(boolean isIgnoreOrientationRequestDisabled,
            @Nullable int[] fromOrientations, @Nullable int[] toOrientations) {
        try {
            mTaskOrganizerController.setOrientationRequestPolicy(isIgnoreOrientationRequestDisabled,
                    fromOrientations, toOrientations);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Gets the executor to run callbacks on.
     * @hide
+40 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import static android.Manifest.permission.SYSTEM_APPLICATION_OVERLAY;
import static android.app.AppOpsManager.OP_CREATE_ACCESSIBILITY_OVERLAY;
import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
import static android.app.AppOpsManager.OP_TOAST_WINDOW;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
import static android.content.pm.PackageManager.FEATURE_AUTOMOTIVE;
import static android.content.pm.PackageManager.FEATURE_HDMI_CEC;
import static android.content.pm.PackageManager.FEATURE_LEANBACK;
@@ -563,6 +566,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    int mShortPressOnWindowBehavior;
    int mPowerVolUpBehavior;
    boolean mStylusButtonsEnabled = true;
    boolean mKidsModeEnabled;
    boolean mHasSoftInput = false;
    boolean mUseTvRouting;
    boolean mAllowStartActivityForLongPressOnPowerDuringSetup;
@@ -887,6 +891,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.STYLUS_BUTTONS_ENABLED), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.NAV_BAR_KIDS_MODE), false, this,
                    UserHandle.USER_ALL);
            updateSettings();
        }

@@ -2964,12 +2971,44 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mStylusButtonsEnabled = Settings.Secure.getIntForUser(resolver,
                    Secure.STYLUS_BUTTONS_ENABLED, 1, UserHandle.USER_CURRENT) == 1;
            mInputManagerInternal.setStylusButtonMotionEventsEnabled(mStylusButtonsEnabled);

            final boolean kidsModeEnabled = Settings.Secure.getIntForUser(resolver,
                    Settings.Secure.NAV_BAR_KIDS_MODE, 0, UserHandle.USER_CURRENT) == 1;
            if (mKidsModeEnabled != kidsModeEnabled) {
                mKidsModeEnabled = kidsModeEnabled;
                updateKidsModeSettings();
            }
        }
        if (updateRotation) {
            updateRotation(true);
        }
    }

    private void updateKidsModeSettings() {
        if (mKidsModeEnabled) {
            // Needed since many Kids apps aren't optimised to support both orientations and it
            // will be hard for kids to understand the app compat mode.
            // TODO(229961548): Remove ignoreOrientationRequest exception for Kids Mode once
            //                  possible.
            if (mContext.getResources().getBoolean(R.bool.config_reverseDefaultRotation)) {
                mWindowManagerInternal.setOrientationRequestPolicy(
                        true /* isIgnoreOrientationRequestDisabled */,
                        new int[]{SCREEN_ORIENTATION_LANDSCAPE,
                                SCREEN_ORIENTATION_REVERSE_LANDSCAPE},
                        new int[]{SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
                                SCREEN_ORIENTATION_SENSOR_LANDSCAPE});
            } else {
                mWindowManagerInternal.setOrientationRequestPolicy(
                        true /* isIgnoreOrientationRequestDisabled */,
                        null /* fromOrientations */, null /* toOrientations */);
            }
        } else {
            mWindowManagerInternal.setOrientationRequestPolicy(
                    false /* isIgnoreOrientationRequestDisabled */,
                    null /* fromOrientations */, null /* toOrientations */);
        }
    }

    private DreamManagerInternal getDreamManagerInternal() {
        if (mDreamManagerInternal == null) {
            // If mDreamManagerInternal is null, attempt to re-fetch it.
@@ -6421,6 +6460,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                pw.print(!mAllowLockscreenWhenOnDisplays.isEmpty());
                pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
                pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
        pw.print(prefix); pw.print("mKidsModeEnabled="); pw.println(mKidsModeEnabled);

        mHapticFeedbackVibrationProvider.dump(prefix, pw);
        mGlobalKeyManager.dump(prefix, pw);
+0 −16
Original line number Diff line number Diff line
@@ -1182,22 +1182,6 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
        }
    }

    @Override
    public void setOrientationRequestPolicy(boolean isIgnoreOrientationRequestDisabled,
            @Nullable int[] fromOrientations, @Nullable int[] toOrientations) {
        enforceTaskPermission("setOrientationRequestPolicy()");
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                mService.mWindowManager
                        .setOrientationRequestPolicy(isIgnoreOrientationRequestDisabled,
                                fromOrientations, toOrientations);
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    public boolean handleInterceptBackPressedOnTaskRoot(Task task) {
        if (!shouldInterceptBackPressedOnRootTask(task)) {
            return false;
+14 −0
Original line number Diff line number Diff line
@@ -993,4 +993,18 @@ public abstract class WindowManagerInternal {
     * @param displayId the id of display to check if there is a software navigation bar.
     */
    public abstract boolean hasNavigationBar(int displayId);

    /**
     * Controls whether the app-requested screen orientation is always respected.
     *
     * @param respected If {@code true}, the app requested orientation is always respected.
     *                  Otherwise, the system might ignore the request due to
     *                  {@link com.android.server.wm.DisplayArea#getIgnoreOrientationRequest}.
     * @param fromOrientations The orientations we want to map to the correspondent orientations
     *                         in toOrientation.
     * @param toOrientations The orientations we map to the ones in fromOrientations at the same
     *                       index
     */
    public abstract void setOrientationRequestPolicy(boolean respected,
            int[] fromOrientations, int[] toOrientations);
}
Loading