1 /* 2 * Copyright (C) 2020 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.window; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.TestApi; 22 import android.os.IBinder; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 /** 27 * Interface for a window container to communicate with the window manager. This also acts as a 28 * token. 29 * @hide 30 */ 31 @TestApi 32 public final class WindowContainerToken implements Parcelable { 33 34 private final IWindowContainerToken mRealToken; 35 36 /** @hide */ 37 public WindowContainerToken(IWindowContainerToken realToken) { 38 mRealToken = realToken; 39 } 40 41 private WindowContainerToken(Parcel in) { 42 mRealToken = IWindowContainerToken.Stub.asInterface(in.readStrongBinder()); 43 } 44 45 /** @hide */ 46 public IBinder asBinder() { 47 return mRealToken.asBinder(); 48 } 49 50 @Override 51 /** @hide */ 52 public void writeToParcel(@NonNull Parcel dest, int flags) { 53 dest.writeStrongBinder(mRealToken.asBinder()); 54 } 55 56 @NonNull 57 public static final Creator<WindowContainerToken> CREATOR = 58 new Creator<WindowContainerToken>() { 59 @Override 60 public WindowContainerToken createFromParcel(Parcel in) { 61 return new WindowContainerToken(in); 62 } 63 64 @Override 65 public WindowContainerToken[] newArray(int size) { 66 return new WindowContainerToken[size]; 67 } 68 }; 69 70 @Override 71 /** @hide */ 72 public int describeContents() { 73 return 0; 74 } 75 76 @Override 77 public int hashCode() { 78 return mRealToken.asBinder().hashCode(); 79 } 80 81 @Override 82 public String toString() { 83 return "WCT{" + mRealToken + "}"; 84 } 85 86 @Override 87 public boolean equals(@Nullable Object obj) { 88 if (!(obj instanceof WindowContainerToken)) { 89 return false; 90 } 91 return mRealToken.asBinder() == ((WindowContainerToken) obj).asBinder(); 92 } 93 } 94