blob: 1955897665beab04dde5f908f795dfa8aef57e8b [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
Andrii Kulian88e05cb2017-12-05 17:21:10 -080019import android.app.ClientTransactionHandler;
Andrii Kulian446e8242017-10-26 15:17:29 -070020import android.content.res.Configuration;
21import android.os.IBinder;
22import android.os.Parcel;
23
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080024import java.util.Objects;
25
Andrii Kulian446e8242017-10-26 15:17:29 -070026/**
27 * Picture in picture mode change message.
28 * @hide
29 */
30// TODO(lifecycler): Remove the use of this and just use the configuration change message to
31// communicate multi-window mode change with WindowConfiguration.
32public class PipModeChangeItem extends ClientTransactionItem {
33
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080034 private boolean mIsInPipMode;
35 private Configuration mOverrideConfig;
Andrii Kulian446e8242017-10-26 15:17:29 -070036
37 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080038 public void execute(ClientTransactionHandler client, IBinder token,
39 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070040 client.handlePictureInPictureModeChanged(token, mIsInPipMode, mOverrideConfig);
41 }
42
43
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080044 // ObjectPoolItem implementation
45
46 private PipModeChangeItem() {}
47
48 /** Obtain an instance initialized with provided params. */
49 public static PipModeChangeItem obtain(boolean isInPipMode, Configuration overrideConfig) {
50 PipModeChangeItem instance = ObjectPool.obtain(PipModeChangeItem.class);
51 if (instance == null) {
52 instance = new PipModeChangeItem();
53 }
54 instance.mIsInPipMode = isInPipMode;
55 instance.mOverrideConfig = overrideConfig;
56
57 return instance;
58 }
59
60 @Override
61 public void recycle() {
62 mIsInPipMode = false;
63 mOverrideConfig = null;
64 ObjectPool.recycle(this);
65 }
66
67
Andrii Kulian446e8242017-10-26 15:17:29 -070068 // Parcelable implementation
69
70 /** Write to Parcel. */
71 public void writeToParcel(Parcel dest, int flags) {
72 dest.writeBoolean(mIsInPipMode);
73 dest.writeTypedObject(mOverrideConfig, flags);
74 }
75
76 /** Read from Parcel. */
77 private PipModeChangeItem(Parcel in) {
78 mIsInPipMode = in.readBoolean();
79 mOverrideConfig = in.readTypedObject(Configuration.CREATOR);
80 }
81
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070082 public static final @android.annotation.NonNull Creator<PipModeChangeItem> CREATOR =
Andrii Kulian446e8242017-10-26 15:17:29 -070083 new Creator<PipModeChangeItem>() {
84 public PipModeChangeItem createFromParcel(Parcel in) {
85 return new PipModeChangeItem(in);
86 }
87
88 public PipModeChangeItem[] newArray(int size) {
89 return new PipModeChangeItem[size];
90 }
91 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080092
93 @Override
94 public boolean equals(Object o) {
95 if (this == o) {
96 return true;
97 }
98 if (o == null || getClass() != o.getClass()) {
99 return false;
100 }
101 final PipModeChangeItem other = (PipModeChangeItem) o;
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -0800102 return mIsInPipMode == other.mIsInPipMode
103 && Objects.equals(mOverrideConfig, other.mOverrideConfig);
Andrii Kulian6b9d3a12017-11-16 14:36:36 -0800104 }
105
106 @Override
107 public int hashCode() {
108 int result = 17;
109 result = 31 * result + (mIsInPipMode ? 1 : 0);
110 result = 31 * result + mOverrideConfig.hashCode();
111 return result;
112 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800113
114 @Override
115 public String toString() {
116 return "PipModeChangeItem{isInPipMode=" + mIsInPipMode
117 + ",overrideConfig=" + mOverrideConfig + "}";
118 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700119}