Debian Codegraph @

core/java/android/app/servertransaction/RefreshCallbackItem.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 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 import static android.app.servertransaction.ActivityLifecycleItem.LifecycleState;
20 import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE;
21 import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP;
22
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.app.ActivityThread.ActivityClientRecord;
26 import android.app.ClientTransactionHandler;
27 import android.os.IBinder;
28 import android.os.Parcel;
29
30 /**
31 * Callback that allows to {@link TransactionExecutor#cycleToPath} to {@link ON_PAUSE} or
32 * {@link ON_STOP} in {@link TransactionExecutor#executeCallbacks} for activity "refresh" flow
33 * that goes through "paused -> resumed" or "stopped -> resumed" cycle.
34 *
35 * <p>This is used in combination with {@link com.android.server.wm.DisplayRotationCompatPolicy}
36 * for camera compatibility treatment that handles orientation mismatch between camera buffers and
37 * an app window. This allows to clear cached values in apps (e.g. display or camera rotation) that
38 * influence camera preview and can lead to sideways or stretching issues.
39 *
40 * @hide
41 */
42 public class RefreshCallbackItem extends ActivityTransactionItem {
43
44 // Whether refresh should happen using the "stopped -> resumed" cycle or
45 // "paused -> resumed" cycle.
46 @LifecycleState
47 private int mPostExecutionState;
48
49 @Override
50 public void execute(@NonNull ClientTransactionHandler client,
51 @NonNull ActivityClientRecord r, PendingTransactionActions pendingActions) {}
52
53 @Override
54 public void postExecute(ClientTransactionHandler client, IBinder token,
55 PendingTransactionActions pendingActions) {
56 final ActivityClientRecord r = getActivityClientRecord(client, token);
57 client.reportRefresh(r);
58 }
59
60 @Override
61 public int getPostExecutionState() {
62 return mPostExecutionState;
63 }
64
65 @Override
66 boolean shouldHaveDefinedPreExecutionState() {
67 return false;
68 }
69
70 // ObjectPoolItem implementation
71
72 @Override
73 public void recycle() {
74 ObjectPool.recycle(this);
75 }
76
77 /**
78 * Obtain an instance initialized with provided params.
79 * @param postExecutionState indicating whether refresh should happen using the
80 * "stopped -> resumed" cycle or "paused -> resumed" cycle.
81 */
82 public static RefreshCallbackItem obtain(@LifecycleState int postExecutionState) {
83 if (postExecutionState != ON_STOP && postExecutionState != ON_PAUSE) {
84 throw new IllegalArgumentException(
85 "Only ON_STOP or ON_PAUSE are allowed as a post execution state for "
86 + "RefreshCallbackItem but got " + postExecutionState);
87 }
88 RefreshCallbackItem instance =
89 ObjectPool.obtain(RefreshCallbackItem.class);
90 if (instance == null) {
91 instance = new RefreshCallbackItem();
92 }
93 instance.mPostExecutionState = postExecutionState;
94 return instance;
95 }
96
97 private RefreshCallbackItem() {}
98
99 // Parcelable implementation
100
101 @Override
102 public void writeToParcel(Parcel dest, int flags) {
103 dest.writeInt(mPostExecutionState);
104 }
105
106 @Override
107 public boolean equals(@Nullable Object o) {
108 if (this == o) {
109 return true;
110 }
111 if (o == null || getClass() != o.getClass()) {
112 return false;
113 }
114 final RefreshCallbackItem other = (RefreshCallbackItem) o;
115 return mPostExecutionState == other.mPostExecutionState;
116 }
117
118 @Override
119 public int hashCode() {
120 int result = 17;
121 result = 31 * result + mPostExecutionState;
122 return result;
123 }
124
125 @Override
126 public String toString() {
127 return "RefreshCallbackItem{mPostExecutionState=" + mPostExecutionState + "}";
128 }
129
130 private RefreshCallbackItem(Parcel in) {
131 mPostExecutionState = in.readInt();
132 }
133
134 public static final @NonNull Creator<RefreshCallbackItem> CREATOR =
135 new Creator<RefreshCallbackItem>() {
136
137 public RefreshCallbackItem createFromParcel(Parcel in) {
138 return new RefreshCallbackItem(in);
139 }
140
141 public RefreshCallbackItem[] newArray(int size) {
142 return new RefreshCallbackItem[size];
143 }
144 };
145 }