blob: 9ee0f3126432d48aec77d22e3d297cffa56c7d67 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.app;
18
Mathew Inwood61e8ae62018-08-14 14:17:44 +010019import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Intent;
Mathew Inwood31755f92018-12-20 13:53:36 +000021import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.Parcel;
23import android.os.Parcelable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080025import java.util.Objects;
26
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027/**
28 * {@hide}
29 */
30public class ResultInfo implements Parcelable {
Mathew Inwood61e8ae62018-08-14 14:17:44 +010031 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 public final String mResultWho;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010033 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 public final int mRequestCode;
35 public final int mResultCode;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010036 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 public final Intent mData;
38
Mathew Inwood61e8ae62018-08-14 14:17:44 +010039 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 public ResultInfo(String resultWho, int requestCode, int resultCode,
41 Intent data) {
42 mResultWho = resultWho;
43 mRequestCode = requestCode;
44 mResultCode = resultCode;
45 mData = data;
46 }
47
48 public String toString() {
49 return "ResultInfo{who=" + mResultWho + ", request=" + mRequestCode
50 + ", result=" + mResultCode + ", data=" + mData + "}";
51 }
52
53 public int describeContents() {
54 return 0;
55 }
56
57 public void writeToParcel(Parcel out, int flags) {
58 out.writeString(mResultWho);
59 out.writeInt(mRequestCode);
60 out.writeInt(mResultCode);
61 if (mData != null) {
62 out.writeInt(1);
63 mData.writeToParcel(out, 0);
64 } else {
65 out.writeInt(0);
66 }
67 }
68
Mathew Inwood31755f92018-12-20 13:53:36 +000069 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070070 public static final @android.annotation.NonNull Parcelable.Creator<ResultInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 = new Parcelable.Creator<ResultInfo>() {
72 public ResultInfo createFromParcel(Parcel in) {
73 return new ResultInfo(in);
74 }
75
76 public ResultInfo[] newArray(int size) {
77 return new ResultInfo[size];
78 }
79 };
80
81 public ResultInfo(Parcel in) {
82 mResultWho = in.readString();
83 mRequestCode = in.readInt();
84 mResultCode = in.readInt();
85 if (in.readInt() != 0) {
86 mData = Intent.CREATOR.createFromParcel(in);
87 } else {
88 mData = null;
89 }
90 }
Andrii Kulian6b9d3a12017-11-16 14:36:36 -080091
92 @Override
93 public boolean equals(Object obj) {
94 if (obj == null || !(obj instanceof ResultInfo)) {
95 return false;
96 }
97 final ResultInfo other = (ResultInfo) obj;
98 final boolean intentsEqual = mData == null ? (other.mData == null)
99 : mData.filterEquals(other.mData);
100 return intentsEqual && Objects.equals(mResultWho, other.mResultWho)
101 && mResultCode == other.mResultCode
102 && mRequestCode == other.mRequestCode;
103 }
104
105 @Override
106 public int hashCode() {
107 int result = 17;
108 result = 31 * result + mRequestCode;
109 result = 31 * result + mResultCode;
110 result = 31 * result + Objects.hashCode(mResultWho);
111 if (mData != null) {
112 result = 31 * result + mData.filterHashCode();
113 }
114 return result;
115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116}