Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 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 | |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 21 | import android.app.ClientTransactionHandler; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 22 | import android.content.res.Configuration; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.Parcel; |
| 25 | import android.os.Trace; |
| 26 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 27 | import java.util.Objects; |
| 28 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Activity move to a different display message. |
| 31 | * @hide |
| 32 | */ |
| 33 | public class MoveToDisplayItem extends ClientTransactionItem { |
| 34 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 35 | private int mTargetDisplayId; |
| 36 | private Configuration mConfiguration; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 37 | |
| 38 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 39 | public void execute(ClientTransactionHandler client, IBinder token, |
| 40 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 41 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay"); |
| 42 | client.handleActivityConfigurationChanged(token, mConfiguration, mTargetDisplayId); |
| 43 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 44 | } |
| 45 | |
| 46 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 47 | // 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 Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 71 | // 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 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 86 | public static final @android.annotation.NonNull Creator<MoveToDisplayItem> CREATOR = new Creator<MoveToDisplayItem>() { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 87 | 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 Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 95 | |
| 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 Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 106 | && Objects.equals(mConfiguration, other.mConfiguration); |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 107 | } |
| 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 Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 116 | |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | return "MoveToDisplayItem{targetDisplayId=" + mTargetDisplayId |
| 120 | + ",configuration=" + mConfiguration + "}"; |
| 121 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 122 | } |