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

Commit 761f72e9 authored by Ben Lin's avatar Ben Lin
Browse files

WindowContainerTransaction: add KeyguardState.

This adds a HOP.KeyguardState class that keyguard related transitions
can pass to wct to communicate to core. Currently, it does nothing (all
the variables are default values), and Core does not really handle it
(it just no-ops), and is only set on the most simple case (Simple unlock
via swipe up).

Subsequent changes will address the TODOs.

Bug: 364930619
Test: Manually swipe up to make sure nothing breaks
Flag: EXEMPT no-op at the moment

Change-Id: I5e5890d8e82a1a3d1d9b930071fbd968f2c437bb
parent 56beffab
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

/**
 * @hide
 */
parcelable KeyguardState;
+160 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * Data object of params for Keyguard related {@link WindowContainerTransaction} operation.
 *
 * @hide
 */
public final class KeyguardState implements Parcelable {

    private final int mDisplayId;

    private final boolean mKeyguardShowing;

    private final boolean mAodShowing;


    private KeyguardState(int displayId, boolean keyguardShowing, boolean aodShowing) {
        mDisplayId = displayId;
        mKeyguardShowing = keyguardShowing;
        mAodShowing = aodShowing;
    }

    private KeyguardState(Parcel in) {
        mDisplayId = in.readInt();
        mKeyguardShowing = in.readBoolean();
        mAodShowing = in.readBoolean();
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mDisplayId);
        dest.writeBoolean(mKeyguardShowing);
        dest.writeBoolean(mAodShowing);
    }

    @NonNull
    public static final Creator<KeyguardState> CREATOR =
            new Creator<KeyguardState>() {
                @Override
                public KeyguardState createFromParcel(Parcel in) {
                    return new KeyguardState(in);
                }

                @Override
                public KeyguardState[] newArray(int size) {
                    return new KeyguardState[size];
                }
            };

    /**
     * Gets the display id of this {@link KeyguardState}.
     */
    public int getDisplayId() {
        return mDisplayId;
    }

    /** Returns the keyguard showing value. */
    public boolean getKeyguardShowing() {
        return mKeyguardShowing;
    }

    /** Returns the aod showing value. */
    public boolean getAodShowing() {
        return mAodShowing;
    }

    @Override
    public String toString() {
        return "KeyguardState{ displayId=" + mDisplayId
                + ", keyguardShowing=" + mKeyguardShowing
                + ", aodShowing=" + mAodShowing
                + '}';
    }

    @Override
    public int hashCode() {
        return Objects.hash(mDisplayId, mKeyguardShowing, mAodShowing);
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (!(obj instanceof KeyguardState other)) {
            return false;
        }
        return mDisplayId == other.mDisplayId
                && mKeyguardShowing == other.mKeyguardShowing
                && mAodShowing == other.mAodShowing;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    /** Builder to construct the {@link KeyguardState}. */
    public static final class Builder {

        private final int mDisplayId;

        private boolean mKeyguardShowing;

        private boolean mAodShowing;

        /**
         * @param displayId the display of this {@link KeyguardState}.
         */
        public Builder(int displayId) {
            mDisplayId = displayId;
        }

        /**
         * Sets the boolean value for this operation.
         */
        @NonNull
        public Builder setKeyguardShowing(boolean keyguardShowing) {
            mKeyguardShowing = keyguardShowing;
            return this;
        }

        /**
         * Sets the boolean value for this operation.
         */
        @NonNull
        public Builder setAodShowing(boolean aodShowing) {
            mAodShowing = aodShowing;
            return this;
        }

        /**
         * Constructs the {@link KeyguardState}.
         */
        @NonNull
        public KeyguardState build() {
            return new KeyguardState(mDisplayId, mKeyguardShowing, mAodShowing);
        }
    }
}
+43 −0
Original line number Diff line number Diff line
@@ -868,6 +868,24 @@ public final class WindowContainerTransaction implements Parcelable {
        return this;
    }

    /**
     * Adds a {@link KeyguardState} to apply to the given displays.
     *
     * @hide
     */
    @NonNull
    public WindowContainerTransaction addKeyguardState(
            @NonNull KeyguardState keyguardState) {
        Objects.requireNonNull(keyguardState);
        final HierarchyOp hierarchyOp =
                new HierarchyOp.Builder(
                        HierarchyOp.HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE)
                        .setKeyguardState(keyguardState)
                        .build();
        mHierarchyOps.add(hierarchyOp);
        return this;
    }

    /**
     * Sets/removes the always on top flag for this {@code windowContainer}. See
     * {@link com.android.server.wm.ConfigurationContainer#setAlwaysOnTop(boolean)}.
@@ -1469,6 +1487,7 @@ public final class WindowContainerTransaction implements Parcelable {
        public static final int HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE = 19;
        public static final int HIERARCHY_OP_TYPE_RESTORE_BACK_NAVIGATION = 20;
        public static final int HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES = 21;
        public static final int HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE = 22;

        // The following key(s) are for use with mLaunchOptions:
        // When launching a task (eg. from recents), this is the taskId to be launched.
@@ -1515,6 +1534,9 @@ public final class WindowContainerTransaction implements Parcelable {
        @Nullable
        private TaskFragmentOperation mTaskFragmentOperation;

        @Nullable
        private KeyguardState mKeyguardState;

        @Nullable
        private PendingIntent mPendingIntent;

@@ -1666,6 +1688,7 @@ public final class WindowContainerTransaction implements Parcelable {
            mLaunchOptions = copy.mLaunchOptions;
            mActivityIntent = copy.mActivityIntent;
            mTaskFragmentOperation = copy.mTaskFragmentOperation;
            mKeyguardState = copy.mKeyguardState;
            mPendingIntent = copy.mPendingIntent;
            mShortcutInfo = copy.mShortcutInfo;
            mAlwaysOnTop = copy.mAlwaysOnTop;
@@ -1689,6 +1712,7 @@ public final class WindowContainerTransaction implements Parcelable {
            mLaunchOptions = in.readBundle();
            mActivityIntent = in.readTypedObject(Intent.CREATOR);
            mTaskFragmentOperation = in.readTypedObject(TaskFragmentOperation.CREATOR);
            mKeyguardState = in.readTypedObject(KeyguardState.CREATOR);
            mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
            mShortcutInfo = in.readTypedObject(ShortcutInfo.CREATOR);
            mAlwaysOnTop = in.readBoolean();
@@ -1769,6 +1793,11 @@ public final class WindowContainerTransaction implements Parcelable {
            return mTaskFragmentOperation;
        }

        @Nullable
        public KeyguardState getKeyguardState() {
            return mKeyguardState;
        }

        @Nullable
        public PendingIntent getPendingIntent() {
            return mPendingIntent;
@@ -1902,6 +1931,9 @@ public final class WindowContainerTransaction implements Parcelable {
                            .append(" mExcludeInsetsTypes= ")
                            .append(WindowInsets.Type.toString(mExcludeInsetsTypes));
                    break;
                case HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE:
                    sb.append("KeyguardState= ").append(mKeyguardState);
                    break;
                case HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE:
                    sb.append("container= ").append(mContainer)
                            .append(" isTrimmable= ")
@@ -1932,6 +1964,7 @@ public final class WindowContainerTransaction implements Parcelable {
            dest.writeBundle(mLaunchOptions);
            dest.writeTypedObject(mActivityIntent, flags);
            dest.writeTypedObject(mTaskFragmentOperation, flags);
            dest.writeTypedObject(mKeyguardState, flags);
            dest.writeTypedObject(mPendingIntent, flags);
            dest.writeTypedObject(mShortcutInfo, flags);
            dest.writeBoolean(mAlwaysOnTop);
@@ -1992,6 +2025,9 @@ public final class WindowContainerTransaction implements Parcelable {
            @Nullable
            private TaskFragmentOperation mTaskFragmentOperation;

            @Nullable
            private KeyguardState mKeyguardState;

            @Nullable
            private PendingIntent mPendingIntent;

@@ -2081,6 +2117,12 @@ public final class WindowContainerTransaction implements Parcelable {
                return this;
            }

            Builder setKeyguardState(
                    @Nullable KeyguardState keyguardState) {
                mKeyguardState = keyguardState;
                return this;
            }

            Builder setReparentLeafTaskIfRelaunch(boolean reparentLeafTaskIfRelaunch) {
                mReparentLeafTaskIfRelaunch = reparentLeafTaskIfRelaunch;
                return this;
@@ -2130,6 +2172,7 @@ public final class WindowContainerTransaction implements Parcelable {
                hierarchyOp.mPendingIntent = mPendingIntent;
                hierarchyOp.mAlwaysOnTop = mAlwaysOnTop;
                hierarchyOp.mTaskFragmentOperation = mTaskFragmentOperation;
                hierarchyOp.mKeyguardState = mKeyguardState;
                hierarchyOp.mShortcutInfo = mShortcutInfo;
                hierarchyOp.mBounds = mBounds;
                hierarchyOp.mIncludingParents = mIncludingParents;
+19 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import static android.window.WindowContainerTransaction.Change.CHANGE_FOCUSABLE;
import static android.window.WindowContainerTransaction.Change.CHANGE_FORCE_TRANSLUCENT;
import static android.window.WindowContainerTransaction.Change.CHANGE_HIDDEN;
import static android.window.WindowContainerTransaction.Change.CHANGE_RELATIVE_BOUNDS;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT;
@@ -121,6 +122,7 @@ import android.window.ITransitionMetricsReporter;
import android.window.ITransitionPlayer;
import android.window.IWindowContainerTransactionCallback;
import android.window.IWindowOrganizerController;
import android.window.KeyguardState;
import android.window.RemoteTransition;
import android.window.TaskFragmentAnimationParams;
import android.window.TaskFragmentCreationParams;
@@ -1253,6 +1255,10 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                        caller, errorCallbackToken, organizer);
                break;
            }
            case HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE: {
                effects |= applyKeyguardState(hop);
                break;
            }
            case HIERARCHY_OP_TYPE_PENDING_INTENT: {
                final Bundle launchOpts = hop.getLaunchOptions();
                ActivityOptions activityOptions = launchOpts != null
@@ -1788,6 +1794,19 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        return effects;
    }

    private int applyKeyguardState(@NonNull WindowContainerTransaction.HierarchyOp hop) {
        int effects = TRANSACT_EFFECTS_NONE;

        final KeyguardState keyguardState = hop.getKeyguardState();
        if (keyguardState != null) {
            int displayId = keyguardState.getDisplayId();
            boolean keyguardShowing = keyguardState.getKeyguardShowing();
            boolean aodShowing = keyguardState.getAodShowing();
        }
        // TODO: At the moment, this does nothing.
        return effects;
    }

    /**
     * Executes the provided {@code runnable} after the {@code transition}. If the
     * {@code transition} is {@code null}, the {@code runnable} is executed immediately.