• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 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;
18 
19 import android.annotation.Nullable;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.content.Intent;
22 import android.os.Build;
23 import android.os.IBinder;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import java.util.Objects;
28 
29 /**
30  * {@hide}
31  */
32 public class ResultInfo implements Parcelable {
33     @UnsupportedAppUsage
34     public final String mResultWho;
35     @UnsupportedAppUsage
36     public final int mRequestCode;
37     public final int mResultCode;
38     @UnsupportedAppUsage
39     public final Intent mData;
40     public final IBinder mCallerToken;
41 
42     @UnsupportedAppUsage
ResultInfo(String resultWho, int requestCode, int resultCode, Intent data)43     public ResultInfo(String resultWho, int requestCode, int resultCode,
44             Intent data) {
45         this(resultWho, requestCode, resultCode, data, /* callerToken */ null);
46     }
47 
ResultInfo(String resultWho, int requestCode, int resultCode, Intent data, IBinder callerToken)48     public ResultInfo(String resultWho, int requestCode, int resultCode,
49             Intent data, IBinder callerToken) {
50         mResultWho = resultWho;
51         mRequestCode = requestCode;
52         mResultCode = resultCode;
53         mData = data;
54         mCallerToken = callerToken;
55     }
56 
toString()57     public String toString() {
58         return "ResultInfo{who=" + mResultWho + ", request=" + mRequestCode
59             + ", result=" + mResultCode + ", data=" + mData + "}";
60     }
61 
describeContents()62     public int describeContents() {
63         return 0;
64     }
65 
writeToParcel(Parcel out, int flags)66     public void writeToParcel(Parcel out, int flags) {
67         out.writeString(mResultWho);
68         out.writeInt(mRequestCode);
69         out.writeInt(mResultCode);
70         if (mData != null) {
71             out.writeInt(1);
72             mData.writeToParcel(out, 0);
73         } else {
74             out.writeInt(0);
75         }
76         out.writeStrongBinder(mCallerToken);
77     }
78 
79     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
80     public static final @android.annotation.NonNull Parcelable.Creator<ResultInfo> CREATOR
81             = new Parcelable.Creator<ResultInfo>() {
82         public ResultInfo createFromParcel(Parcel in) {
83             return new ResultInfo(in);
84         }
85 
86         public ResultInfo[] newArray(int size) {
87             return new ResultInfo[size];
88         }
89     };
90 
ResultInfo(Parcel in)91     public ResultInfo(Parcel in) {
92         mResultWho = in.readString();
93         mRequestCode = in.readInt();
94         mResultCode = in.readInt();
95         if (in.readInt() != 0) {
96             mData = Intent.CREATOR.createFromParcel(in);
97         } else {
98             mData = null;
99         }
100         mCallerToken = in.readStrongBinder();
101     }
102 
103     @Override
equals(@ullable Object obj)104     public boolean equals(@Nullable Object obj) {
105         if (obj == null || !(obj instanceof ResultInfo)) {
106             return false;
107         }
108         final ResultInfo other = (ResultInfo) obj;
109         final boolean intentsEqual = mData == null ? (other.mData == null)
110                 : mData.filterEquals(other.mData);
111         return intentsEqual && Objects.equals(mResultWho, other.mResultWho)
112                 && mResultCode == other.mResultCode
113                 && mRequestCode == other.mRequestCode
114                 && mCallerToken == other.mCallerToken;
115     }
116 
117     @Override
hashCode()118     public int hashCode() {
119         int result = 17;
120         result = 31 * result + mRequestCode;
121         result = 31 * result + mResultCode;
122         result = 31 * result + Objects.hashCode(mResultWho);
123         if (mData != null) {
124             result = 31 * result + mData.filterHashCode();
125         }
126         result = 31 * result + Objects.hashCode(mCallerToken);
127         return result;
128     }
129 }
130