1 /* 2 * Copyright (C) 2023 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 static java.util.Objects.requireNonNull; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.res.Configuration; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 import java.util.Objects; 28 29 /** 30 * Stores information about a particular window that a {@link WindowContext} is attached to. 31 * @hide 32 */ 33 public class WindowContextInfo implements Parcelable { 34 35 /** 36 * Configuration of the window. 37 */ 38 @NonNull 39 private final Configuration mConfiguration; 40 41 /** 42 * The display id that the window is attached to. 43 */ 44 private final int mDisplayId; 45 WindowContextInfo(@onNull Configuration configuration, int displayId)46 public WindowContextInfo(@NonNull Configuration configuration, int displayId) { 47 mConfiguration = requireNonNull(configuration); 48 mDisplayId = displayId; 49 } 50 51 @NonNull getConfiguration()52 public Configuration getConfiguration() { 53 return mConfiguration; 54 } 55 getDisplayId()56 public int getDisplayId() { 57 return mDisplayId; 58 } 59 60 // Parcelable implementation 61 62 /** Writes to Parcel. */ 63 @Override writeToParcel(@onNull Parcel dest, int flags)64 public void writeToParcel(@NonNull Parcel dest, int flags) { 65 dest.writeTypedObject(mConfiguration, flags); 66 dest.writeInt(mDisplayId); 67 } 68 69 /** Reads from Parcel. */ WindowContextInfo(@onNull Parcel in)70 private WindowContextInfo(@NonNull Parcel in) { 71 mConfiguration = in.readTypedObject(Configuration.CREATOR); 72 mDisplayId = in.readInt(); 73 } 74 75 public static final @NonNull Creator<WindowContextInfo> CREATOR = new Creator<>() { 76 public WindowContextInfo createFromParcel(Parcel in) { 77 return new WindowContextInfo(in); 78 } 79 80 public WindowContextInfo[] newArray(int size) { 81 return new WindowContextInfo[size]; 82 } 83 }; 84 85 @Override describeContents()86 public int describeContents() { 87 return 0; 88 } 89 90 @Override equals(@ullable Object o)91 public boolean equals(@Nullable Object o) { 92 if (this == o) { 93 return true; 94 } 95 if (o == null || getClass() != o.getClass()) { 96 return false; 97 } 98 final WindowContextInfo other = (WindowContextInfo) o; 99 return Objects.equals(mConfiguration, other.mConfiguration) 100 && mDisplayId == other.mDisplayId; 101 } 102 103 @Override hashCode()104 public int hashCode() { 105 int result = 17; 106 result = 31 * result + Objects.hashCode(mConfiguration); 107 result = 31 * result + mDisplayId; 108 return result; 109 } 110 111 @Override toString()112 public String toString() { 113 return "WindowContextInfo{config=" + mConfiguration 114 + ", displayId=" + mDisplayId 115 + "}"; 116 } 117 } 118