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.os.IBinder; |
| 23 | import android.os.Parcel; |
| 24 | import android.os.Trace; |
| 25 | |
| 26 | /** |
| 27 | * Window visibility change message. |
| 28 | * @hide |
| 29 | */ |
| 30 | public class WindowVisibilityItem extends ClientTransactionItem { |
| 31 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 32 | private boolean mShowWindow; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 33 | |
| 34 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 35 | public void execute(ClientTransactionHandler client, IBinder token, |
| 36 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 37 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityShowWindow"); |
| 38 | client.handleWindowVisibility(token, mShowWindow); |
| 39 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 40 | } |
| 41 | |
| 42 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 43 | // 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 Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 65 | // 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 Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 88 | |
| 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 Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 105 | |
| 106 | @Override |
| 107 | public String toString() { |
| 108 | return "WindowVisibilityItem{showWindow=" + mShowWindow + "}"; |
| 109 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 110 | } |