Debian Codegraph @

core/java/android/app/servertransaction/MoveToDisplayItem.java

raw symbols SCIP
1 /*
2 * Copyright 2017 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.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
20
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.app.ActivityThread.ActivityClientRecord;
24 import android.app.ClientTransactionHandler;
25 import android.content.res.Configuration;
26 import android.os.IBinder;
27 import android.os.Parcel;
28 import android.os.Trace;
29
30 import java.util.Objects;
31
32 /**
33 * Activity move to a different display message.
34 * @hide
35 */
36 public class MoveToDisplayItem extends ActivityTransactionItem {
37
38 private int mTargetDisplayId;
39 private Configuration mConfiguration;
40
41 @Override
42 public void preExecute(ClientTransactionHandler client, IBinder token) {
43 // Notify the client of an upcoming change in the token configuration. This ensures that
44 // batches of config change items only process the newest configuration.
45 client.updatePendingActivityConfiguration(token, mConfiguration);
46 }
47
48 @Override
49 public void execute(ClientTransactionHandler client, ActivityClientRecord r,
50 PendingTransactionActions pendingActions) {
51 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay");
52 client.handleActivityConfigurationChanged(r, mConfiguration, mTargetDisplayId);
53 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
54 }
55
56
57 // ObjectPoolItem implementation
58
59 private MoveToDisplayItem() {}
60
61 /** Obtain an instance initialized with provided params. */
62 public static MoveToDisplayItem obtain(int targetDisplayId,
63 @NonNull Configuration configuration) {
64 if (configuration == null) {
65 throw new IllegalArgumentException("Configuration must not be null");
66 }
67
68 MoveToDisplayItem instance = ObjectPool.obtain(MoveToDisplayItem.class);
69 if (instance == null) {
70 instance = new MoveToDisplayItem();
71 }
72 instance.mTargetDisplayId = targetDisplayId;
73 instance.mConfiguration = configuration;
74
75 return instance;
76 }
77
78 @Override
79 public void recycle() {
80 mTargetDisplayId = 0;
81 mConfiguration = Configuration.EMPTY;
82 ObjectPool.recycle(this);
83 }
84
85
86 // Parcelable implementation
87
88 /** Write to Parcel. */
89 @Override
90 public void writeToParcel(Parcel dest, int flags) {
91 dest.writeInt(mTargetDisplayId);
92 dest.writeTypedObject(mConfiguration, flags);
93 }
94
95 /** Read from Parcel. */
96 private MoveToDisplayItem(Parcel in) {
97 mTargetDisplayId = in.readInt();
98 mConfiguration = in.readTypedObject(Configuration.CREATOR);
99 }
100
101 public static final @NonNull Creator<MoveToDisplayItem> CREATOR =
102 new Creator<MoveToDisplayItem>() {
103 public MoveToDisplayItem createFromParcel(Parcel in) {
104 return new MoveToDisplayItem(in);
105 }
106
107 public MoveToDisplayItem[] newArray(int size) {
108 return new MoveToDisplayItem[size];
109 }
110 };
111
112 @Override
113 public boolean equals(@Nullable Object o) {
114 if (this == o) {
115 return true;
116 }
117 if (o == null || getClass() != o.getClass()) {
118 return false;
119 }
120 final MoveToDisplayItem other = (MoveToDisplayItem) o;
121 return mTargetDisplayId == other.mTargetDisplayId
122 && Objects.equals(mConfiguration, other.mConfiguration);
123 }
124
125 @Override
126 public int hashCode() {
127 int result = 17;
128 result = 31 * result + mTargetDisplayId;
129 result = 31 * result + mConfiguration.hashCode();
130 return result;
131 }
132
133 @Override
134 public String toString() {
135 return "MoveToDisplayItem{targetDisplayId=" + mTargetDisplayId
136 + ",configuration=" + mConfiguration + "}";
137 }
138 }