• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app.servertransaction;
18 
19 
20 import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
21 
22 import static java.util.Objects.requireNonNull;
23 
24 import android.annotation.CallSuper;
25 import android.annotation.NonNull;
26 import android.annotation.Nullable;
27 import android.app.ClientTransactionHandler;
28 import android.os.Parcel;
29 import android.view.IWindow;
30 
31 import com.android.internal.annotations.VisibleForTesting;
32 
33 import java.util.Objects;
34 
35 /**
36  * {@link ClientTransactionItem} to report changes to a window.
37  *
38  * @hide
39  */
40 public abstract class WindowStateTransactionItem extends ClientTransactionItem {
41 
42     /** The interface for IWindow to perform callback directly if possible. */
43     public interface TransactionListener {
44         /** Notifies that the transaction item is going to be executed. */
onExecutingWindowStateTransactionItem()45         void onExecutingWindowStateTransactionItem();
46     }
47 
48     /** Target window. */
49     @NonNull
50     private final IWindow mWindow;
51 
WindowStateTransactionItem(@onNull IWindow window)52     public WindowStateTransactionItem(@NonNull IWindow window) {
53         mWindow = requireNonNull(window);
54     }
55 
56     @Override
execute(@onNull ClientTransactionHandler client, @NonNull PendingTransactionActions pendingActions)57     public final void execute(@NonNull ClientTransactionHandler client,
58             @NonNull PendingTransactionActions pendingActions) {
59         if (mWindow instanceof TransactionListener listener) {
60             listener.onExecutingWindowStateTransactionItem();
61         }
62         execute(client, mWindow, pendingActions);
63     }
64 
65     /**
66      * Like {@link #execute(ClientTransactionHandler, PendingTransactionActions)},
67      * but take non-null {@link IWindow} as a parameter.
68      */
69     @VisibleForTesting(visibility = PACKAGE)
execute(@onNull ClientTransactionHandler client, @NonNull IWindow window, @NonNull PendingTransactionActions pendingActions)70     public abstract void execute(@NonNull ClientTransactionHandler client,
71             @NonNull IWindow window, @NonNull PendingTransactionActions pendingActions);
72 
73     // Parcelable implementation
74 
75     /** Writes to Parcel. */
76     @CallSuper
77     @Override
writeToParcel(@onNull Parcel dest, int flags)78     public void writeToParcel(@NonNull Parcel dest, int flags) {
79         dest.writeStrongBinder(mWindow.asBinder());
80     }
81 
82     /** Reads from Parcel. */
WindowStateTransactionItem(@onNull Parcel in)83     WindowStateTransactionItem(@NonNull Parcel in) {
84         mWindow = requireNonNull(IWindow.Stub.asInterface(in.readStrongBinder()));
85     }
86 
87     // Subclass must override and call super.equals to compare the mActivityToken.
88     @SuppressWarnings("EqualsGetClass")
89     @CallSuper
90     @Override
equals(@ullable Object o)91     public boolean equals(@Nullable Object o) {
92         if (this == o) {
93             return true;
94         }
95         if (o == null || getClass() != o.getClass()) {
96             return false;
97         }
98         final WindowStateTransactionItem other = (WindowStateTransactionItem) o;
99         return Objects.equals(mWindow, other.mWindow);
100     }
101 
102     @CallSuper
103     @Override
hashCode()104     public int hashCode() {
105         return Objects.hashCode(mWindow);
106     }
107 
108     @CallSuper
109     @Override
toString()110     public String toString() {
111         return "mWindow=" + mWindow;
112     }
113 }
114