blob: d9956b1348b1a733aa819e749e74eecf3471719f [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.os.IBinder;
23import android.os.Parcel;
24import android.os.Trace;
25
26/**
27 * Window visibility change message.
28 * @hide
29 */
30public class WindowVisibilityItem extends ClientTransactionItem {
31
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080032 private boolean mShowWindow;
Andrii Kulian446e8242017-10-26 15:17:29 -070033
34 @Override
Andrii Kulian88e05cb2017-12-05 17:21:10 -080035 public void execute(ClientTransactionHandler client, IBinder token,
36 PendingTransactionActions pendingActions) {
Andrii Kulian446e8242017-10-26 15:17:29 -070037 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow");
38 client.handleWindowVisibility(token, mShowWindow);
39 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
40 }
41
42
Andrii Kulian9c5ea9c2017-12-07 09:31:01 -080043 // ObjectPoolItem implementation
44
45 private WindowVisibilityItem() {}
46
47 /** Obtain an instance initialized with provided params. */
48 public static WindowVisibilityItem obtain(boolean showWindow) {
49 WindowVisibilityItem instance = ObjectPool.obtain(WindowVisibilityItem.class);
50 if (instance == null) {
51 instance = new WindowVisibilityItem();
52 }
53 instance.mShowWindow = showWindow;
54
55 return instance;
56 }
57
58 @Override
59 public void recycle() {
60 mShowWindow = false;
61 ObjectPool.recycle(this);
62 }
63
64
Andrii Kulian446e8242017-10-26 15:17:29 -070065 // Parcelable implementation
66
67 /** Write to Parcel. */
68 @Override
69 public void writeToParcel(Parcel dest, int flags) {
70 dest.writeBoolean(mShowWindow);
71 }
72
73 /** Read from Parcel. */
74 private WindowVisibilityItem(Parcel in) {
75 mShowWindow = in.readBoolean();
76 }
77
78 public static final Creator<WindowVisibilityItem> CREATOR =
79 new Creator<WindowVisibilityItem>() {
80 public WindowVisibilityItem createFromParcel(Parcel in) {
81 return new WindowVisibilityItem(in);
82 }
83
84 public WindowVisibilityItem[] newArray(int size) {
85 return new WindowVisibilityItem[size];
86 }
87 };
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080088
89 @Override
90 public boolean equals(Object o) {
91 if (this == o) {
92 return true;
93 }
94 if (o == null || getClass() != o.getClass()) {
95 return false;
96 }
97 final WindowVisibilityItem other = (WindowVisibilityItem) o;
98 return mShowWindow == other.mShowWindow;
99 }
100
101 @Override
102 public int hashCode() {
103 return 17 + 31 * (mShowWindow ? 1 : 0);
104 }
Andrii Kulian88e05cb2017-12-05 17:21:10 -0800105
106 @Override
107 public String toString() {
108 return "WindowVisibilityItem{showWindow=" + mShowWindow + "}";
109 }
Andrii Kulian446e8242017-10-26 15:17:29 -0700110}