blob: b3dddfb37eaa1994c3faec55031a6ef884589cdd [file] [log] [blame]
Andrii Kulian446e8242017-10-26 15:17:29 -07001/*
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
17package android.app.servertransaction;
18
19import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
20
Andrii Kulian88e05cb2017-12-05 17:21:10 -080021import android.app.ClientTransactionHandler;
Andrii Kulian446e8242017-10-26 15:17:29 -070022import android.content.res.Configuration;
23import android.os.IBinder;
24import android.os.Parcel;
25import android.os.Trace;
26
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080027import java.util.Objects;
28
Andrii Kulian446e8242017-10-26 15:17:29 -070029/**
30 * Activity move to a different display message.
31 * @hide
32 */
33public class MoveToDisplayItem extends ClientTransactionItem {
34
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080035 private int mTargetDisplayId;
36 private Configuration mConfiguration;
Andrii Kulian446e8242017-10-26 15:17:29 -070037
38 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080039 public void execute(ClientTransactionHandler client, IBinder token,
40 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070041 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay");
42 client.handleActivityConfigurationChanged(token, mConfiguration, mTargetDisplayId);
43 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
44 }
45
46
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080047 // ObjectPoolItem implementation
48
49 private MoveToDisplayItem() {}
50
51 /** Obtain an instance initialized with provided params. */
52 public static MoveToDisplayItem obtain(int targetDisplayId, Configuration configuration) {
53 MoveToDisplayItem instance = ObjectPool.obtain(MoveToDisplayItem.class);
54 if (instance == null) {
55 instance = new MoveToDisplayItem();
56 }
57 instance.mTargetDisplayId = targetDisplayId;
58 instance.mConfiguration = configuration;
59
60 return instance;
61 }
62
63 @Override
64 public void recycle() {
65 mTargetDisplayId = 0;
66 mConfiguration = null;
67 ObjectPool.recycle(this);
68 }
69
70
Andrii Kulian446e8242017-10-26 15:17:29 -070071 // Parcelable implementation
72
73 /** Write to Parcel. */
74 @Override
75 public void writeToParcel(Parcel dest, int flags) {
76 dest.writeInt(mTargetDisplayId);
77 dest.writeTypedObject(mConfiguration, flags);
78 }
79
80 /** Read from Parcel. */
81 private MoveToDisplayItem(Parcel in) {
82 mTargetDisplayId = in.readInt();
83 mConfiguration = in.readTypedObject(Configuration.CREATOR);
84 }
85
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080086 public static final Creator<MoveToDisplayItem> CREATOR = new Creator<MoveToDisplayItem>() {
Andrii Kulian446e8242017-10-26 15:17:29 -070087 public MoveToDisplayItem createFromParcel(Parcel in) {
88 return new MoveToDisplayItem(in);
89 }
90
91 public MoveToDisplayItem[] newArray(int size) {
92 return new MoveToDisplayItem[size];
93 }
94 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080095
96 @Override
97 public boolean equals(Object o) {
98 if (this == o) {
99 return true;
100 }
101 if (o == null || getClass() != o.getClass()) {
102 return false;
103 }
104 final MoveToDisplayItem other = (MoveToDisplayItem) o;
105 return mTargetDisplayId == other.mTargetDisplayId
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800106 && Objects.equals(mConfiguration, other.mConfiguration);
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800107 }
108
109 @Override
110 public int hashCode() {
111 int result = 17;
112 result = 31 * result + mTargetDisplayId;
113 result = 31 * result + mConfiguration.hashCode();
114 return result;
115 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800116
117 @Override
118 public String toString() {
119 return "MoveToDisplayItem{targetDisplayId=" + mTargetDisplayId
120 + ",configuration=" + mConfiguration + "}";
121 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700122}