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 21 import android.app.ClientTransactionHandler; 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 32 private boolean mShowWindow; 33 34 @Override execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions)35 public void execute(ClientTransactionHandler client, IBinder token, 36 PendingTransactionActions pendingActions) { 37 Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, 38 mShowWindow ? "activityShowWindow" : "activityHideWindow"); 39 client.handleWindowVisibility(token, mShowWindow); 40 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); 41 } 42 43 44 // ObjectPoolItem implementation 45 WindowVisibilityItem()46 private WindowVisibilityItem() {} 47 48 /** Obtain an instance initialized with provided params. */ obtain(boolean showWindow)49 public static WindowVisibilityItem obtain(boolean showWindow) { 50 WindowVisibilityItem instance = ObjectPool.obtain(WindowVisibilityItem.class); 51 if (instance == null) { 52 instance = new WindowVisibilityItem(); 53 } 54 instance.mShowWindow = showWindow; 55 56 return instance; 57 } 58 59 @Override recycle()60 public void recycle() { 61 mShowWindow = false; 62 ObjectPool.recycle(this); 63 } 64 65 66 // Parcelable implementation 67 68 /** Write to Parcel. */ 69 @Override writeToParcel(Parcel dest, int flags)70 public void writeToParcel(Parcel dest, int flags) { 71 dest.writeBoolean(mShowWindow); 72 } 73 74 /** Read from Parcel. */ WindowVisibilityItem(Parcel in)75 private WindowVisibilityItem(Parcel in) { 76 mShowWindow = in.readBoolean(); 77 } 78 79 public static final @android.annotation.NonNull Creator<WindowVisibilityItem> CREATOR = 80 new Creator<WindowVisibilityItem>() { 81 public WindowVisibilityItem createFromParcel(Parcel in) { 82 return new WindowVisibilityItem(in); 83 } 84 85 public WindowVisibilityItem[] newArray(int size) { 86 return new WindowVisibilityItem[size]; 87 } 88 }; 89 90 @Override equals(Object o)91 public boolean equals(Object o) { 92 if (this == o) { 93 return true; 94 } 95 if (o == null || getClass() != o.getClass()) { 96 return false; 97 } 98 final WindowVisibilityItem other = (WindowVisibilityItem) o; 99 return mShowWindow == other.mShowWindow; 100 } 101 102 @Override hashCode()103 public int hashCode() { 104 return 17 + 31 * (mShowWindow ? 1 : 0); 105 } 106 107 @Override toString()108 public String toString() { 109 return "WindowVisibilityItem{showWindow=" + mShowWindow + "}"; 110 } 111 } 112