• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021, 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.aidl.tests;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 public class BadParcelable implements Parcelable {
23   private boolean mBad;
24   private String mName;
25   private int mNumber;
26 
BadParcelable()27   BadParcelable() {}
BadParcelable(boolean bad, String name, int number)28   BadParcelable(boolean bad, String name, int number) {
29     this.mBad = bad;
30     this.mName = name;
31     this.mNumber = number;
32   }
33 
describeContents()34   public int describeContents() { return 0; }
35 
writeToParcel(Parcel dest, int flags)36   public void writeToParcel(Parcel dest, int flags) {
37     dest.writeBoolean(mBad);
38     dest.writeString(mName);
39     dest.writeInt(mNumber);
40     // BAD! write superfluous data
41     if (mBad) {
42       dest.writeInt(42);
43     }
44   }
45 
readFromParcel(Parcel source)46   public void readFromParcel(Parcel source) {
47     mBad = source.readBoolean();
48     mName = source.readString();
49     mNumber = source.readInt();
50   }
51 
equals(Object o)52   public boolean equals(Object o) {
53     if (o == null) {
54       return false;
55     }
56     if (!(o instanceof BadParcelable)) {
57       return false;
58     }
59     BadParcelable p = (BadParcelable) o;
60     if (mBad != p.mBad) {
61       return false;
62     }
63     if ((mName == null && p.mName != null) || (mName != null && !mName.equals(p.mName))) {
64       return false;
65     }
66     return mNumber == p.mNumber;
67   }
68 
toString()69   public String toString() {
70     return "BadParcelable(bad=" + mBad + ",name=" + mName + ",number=" + mNumber + "}";
71   }
72 
73   public static final Parcelable.Creator<BadParcelable> CREATOR =
74       new Parcelable.Creator<BadParcelable>() {
75         public BadParcelable createFromParcel(Parcel source) {
76           BadParcelable p = new BadParcelable();
77           p.readFromParcel(source);
78           return p;
79         }
80 
81         public BadParcelable[] newArray(int size) { return new BadParcelable[size]; }
82       };
83 }
84