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.compat.annotation.UnsupportedAppUsage; 20 import android.content.Intent; 21 import android.os.Build; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.util.Objects; 26 27 /** 28 * {@hide} 29 */ 30 public class ResultInfo implements Parcelable { 31 @UnsupportedAppUsage 32 public final String mResultWho; 33 @UnsupportedAppUsage 34 public final int mRequestCode; 35 public final int mResultCode; 36 @UnsupportedAppUsage 37 public final Intent mData; 38 39 @UnsupportedAppUsage ResultInfo(String resultWho, int requestCode, int resultCode, Intent data)40 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 toString()48 public String toString() { 49 return "ResultInfo{who=" + mResultWho + ", request=" + mRequestCode 50 + ", result=" + mResultCode + ", data=" + mData + "}"; 51 } 52 describeContents()53 public int describeContents() { 54 return 0; 55 } 56 writeToParcel(Parcel out, int flags)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 69 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 70 public static final @android.annotation.NonNull Parcelable.Creator<ResultInfo> CREATOR 71 = 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 ResultInfo(Parcel in)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 } 91 92 @Override equals(Object obj)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 hashCode()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 } 116 } 117