Debian Codegraph @

core/java/android/app/servertransaction/ActivityConfigurationChangeItem.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 import static android.view.Display.INVALID_DISPLAY;
21
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.app.ActivityThread.ActivityClientRecord;
25 import android.app.ClientTransactionHandler;
26 import android.content.res.Configuration;
27 import android.os.IBinder;
28 import android.os.Parcel;
29 import android.os.Trace;
30
31 import java.util.Objects;
32
33 /**
34 * Activity configuration changed callback.
35 * @hide
36 */
37 public class ActivityConfigurationChangeItem extends ActivityTransactionItem {
38
39 private Configuration mConfiguration;
40
41 @Override
42 public void preExecute(android.app.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 // TODO(lifecycler): detect if PIP or multi-window mode changed and report it here.
52 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged");
53 client.handleActivityConfigurationChanged(r, mConfiguration, INVALID_DISPLAY);
54 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
55 }
56
57
58 // ObjectPoolItem implementation
59
60 private ActivityConfigurationChangeItem() {}
61
62 /** Obtain an instance initialized with provided params. */
63 public static ActivityConfigurationChangeItem obtain(@NonNull Configuration config) {
64 if (config == null) {
65 throw new IllegalArgumentException("Config must not be null.");
66 }
67
68 ActivityConfigurationChangeItem instance =
69 ObjectPool.obtain(ActivityConfigurationChangeItem.class);
70 if (instance == null) {
71 instance = new ActivityConfigurationChangeItem();
72 }
73 instance.mConfiguration = config;
74
75 return instance;
76 }
77
78 @Override
79 public void recycle() {
80 mConfiguration = Configuration.EMPTY;
81 ObjectPool.recycle(this);
82 }
83
84
85 // Parcelable implementation
86
87 /** Write to Parcel. */
88 @Override
89 public void writeToParcel(Parcel dest, int flags) {
90 dest.writeTypedObject(mConfiguration, flags);
91 }
92
93 /** Read from Parcel. */
94 private ActivityConfigurationChangeItem(Parcel in) {
95 mConfiguration = in.readTypedObject(Configuration.CREATOR);
96 }
97
98 public static final @NonNull Creator<ActivityConfigurationChangeItem> CREATOR =
99 new Creator<ActivityConfigurationChangeItem>() {
100 public ActivityConfigurationChangeItem createFromParcel(Parcel in) {
101 return new ActivityConfigurationChangeItem(in);
102 }
103
104 public ActivityConfigurationChangeItem[] newArray(int size) {
105 return new ActivityConfigurationChangeItem[size];
106 }
107 };
108
109 @Override
110 public boolean equals(@Nullable Object o) {
111 if (this == o) {
112 return true;
113 }
114 if (o == null || getClass() != o.getClass()) {
115 return false;
116 }
117 final ActivityConfigurationChangeItem other = (ActivityConfigurationChangeItem) o;
118 return Objects.equals(mConfiguration, other.mConfiguration);
119 }
120
121 @Override
122 public int hashCode() {
123 return mConfiguration.hashCode();
124 }
125
126 @Override
127 public String toString() {
128 return "ActivityConfigurationChange{config=" + mConfiguration + "}";
129 }
130 }