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.telecom.cts;
18 
19 import android.os.Bundle;
20 import android.os.IBinder;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import androidx.annotation.NonNull;
25 
26 import java.util.Objects;
27 
28 /**
29  *  A test Parcelable that is used for testing out Bundle impls.
30  */
31 public class TestParcelable implements Parcelable {
32 
33     public static final String VAL_1_KEY = "val1";
34     public static final String VAL_2_KEY = "val2";
35     public static final String VAL_3_KEY = "val3";
36 
37     public final int mVal1;
38     public final String mVal2;
39     public final IBinder mVal3;
40 
TestParcelable(int val1, String val2, IBinder val3)41     public TestParcelable(int val1, String val2, IBinder val3) {
42         mVal1 = val1;
43         mVal2 = val2;
44         mVal3 = val3;
45     }
46 
TestParcelable(Parcel in)47     private TestParcelable(Parcel in) {
48         mVal1 = in.readInt();
49         mVal2 = in.readString();
50         mVal3 = in.readStrongBinder();
51     }
52 
53     public static final Creator<TestParcelable> CREATOR =  new Creator<>() {
54         @Override
55         public TestParcelable createFromParcel(Parcel source) {
56             return new TestParcelable(source);
57         }
58 
59         @Override
60         public TestParcelable[] newArray(int size) {
61             return new TestParcelable[size];
62         }
63     };
64 
65     @Override
describeContents()66     public int describeContents() {
67         return 0;
68     }
69 
70     @Override
writeToParcel(@onNull Parcel dest, int flags)71     public void writeToParcel(@NonNull Parcel dest, int flags) {
72         dest.writeInt(mVal1);
73         dest.writeString(mVal2);
74         dest.writeStrongBinder(mVal3);
75     }
76 
77     @Override
equals(Object o)78     public boolean equals(Object o) {
79         if (this == o) return true;
80         if (!(o instanceof TestParcelable)) return false;
81         TestParcelable that = (TestParcelable) o;
82         return mVal1 == that.mVal1 && Objects.equals(mVal2, that.mVal2)
83                 && Objects.equals(mVal3, that.mVal3);
84     }
85 
86     @Override
hashCode()87     public int hashCode() {
88         return Objects.hash(mVal1, mVal2, mVal3);
89     }
90 
copyIntoBundle(Bundle b)91     public void copyIntoBundle(Bundle b) {
92         b.putParcelable(TestParcelable.class.getSimpleName(),
93                 new TestParcelable(mVal1, mVal2, mVal3));
94     }
95 
getFromBundle(Bundle b)96     public static TestParcelable getFromBundle(Bundle b) {
97         return b.getParcelable(TestParcelable.class.getSimpleName(), TestParcelable.class);
98     }
99 }
100