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
17package android.app;
18
19import android.content.Intent;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Objects;
24
25/**
26 * {@hide}
27 */
28public class ResultInfo implements Parcelable {
29    public final String mResultWho;
30    public final int mRequestCode;
31    public final int mResultCode;
32    public final Intent mData;
33
34    public ResultInfo(String resultWho, int requestCode, int resultCode,
35            Intent data) {
36        mResultWho = resultWho;
37        mRequestCode = requestCode;
38        mResultCode = resultCode;
39        mData = data;
40    }
41
42    public String toString() {
43        return "ResultInfo{who=" + mResultWho + ", request=" + mRequestCode
44            + ", result=" + mResultCode + ", data=" + mData + "}";
45    }
46
47    public int describeContents() {
48        return 0;
49    }
50
51    public void writeToParcel(Parcel out, int flags) {
52        out.writeString(mResultWho);
53        out.writeInt(mRequestCode);
54        out.writeInt(mResultCode);
55        if (mData != null) {
56            out.writeInt(1);
57            mData.writeToParcel(out, 0);
58        } else {
59            out.writeInt(0);
60        }
61    }
62
63    public static final Parcelable.Creator<ResultInfo> CREATOR
64            = new Parcelable.Creator<ResultInfo>() {
65        public ResultInfo createFromParcel(Parcel in) {
66            return new ResultInfo(in);
67        }
68
69        public ResultInfo[] newArray(int size) {
70            return new ResultInfo[size];
71        }
72    };
73
74    public ResultInfo(Parcel in) {
75        mResultWho = in.readString();
76        mRequestCode = in.readInt();
77        mResultCode = in.readInt();
78        if (in.readInt() != 0) {
79            mData = Intent.CREATOR.createFromParcel(in);
80        } else {
81            mData = null;
82        }
83    }
84
85    @Override
86    public boolean equals(Object obj) {
87        if (obj == null || !(obj instanceof ResultInfo)) {
88            return false;
89        }
90        final ResultInfo other = (ResultInfo) obj;
91        final boolean intentsEqual = mData == null ? (other.mData == null)
92                : mData.filterEquals(other.mData);
93        return intentsEqual && Objects.equals(mResultWho, other.mResultWho)
94                && mResultCode == other.mResultCode
95                && mRequestCode == other.mRequestCode;
96    }
97
98    @Override
99    public int hashCode() {
100        int result = 17;
101        result = 31 * result + mRequestCode;
102        result = 31 * result + mResultCode;
103        result = 31 * result + Objects.hashCode(mResultWho);
104        if (mData != null) {
105            result = 31 * result + mData.filterHashCode();
106        }
107        return result;
108    }
109}
110