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