1 /*
2  * Copyright 2017 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.servertransaction;
18 
19 import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
20 
21 import android.app.ClientTransactionHandler;
22 import android.app.ResultInfo;
23 import android.compat.annotation.UnsupportedAppUsage;
24 import android.os.IBinder;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 import android.os.Trace;
28 
29 import java.util.List;
30 import java.util.Objects;
31 
32 /**
33  * Activity result delivery callback.
34  * @hide
35  */
36 public class ActivityResultItem extends ClientTransactionItem {
37 
38     @UnsupportedAppUsage
39     private List<ResultInfo> mResultInfoList;
40 
41     /* TODO(b/78294732)
42     @Override
43     public int getPostExecutionState() {
44         return ON_RESUME;
45     }*/
46 
47     @Override
execute(ClientTransactionHandler client, IBinder token, PendingTransactionActions pendingActions)48     public void execute(ClientTransactionHandler client, IBinder token,
49             PendingTransactionActions pendingActions) {
50         Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult");
51         client.handleSendResult(token, mResultInfoList, "ACTIVITY_RESULT");
52         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
53     }
54 
55 
56     // ObjectPoolItem implementation
57 
ActivityResultItem()58     private ActivityResultItem() {}
59 
60     /** Obtain an instance initialized with provided params. */
obtain(List<ResultInfo> resultInfoList)61     public static ActivityResultItem obtain(List<ResultInfo> resultInfoList) {
62         ActivityResultItem instance = ObjectPool.obtain(ActivityResultItem.class);
63         if (instance == null) {
64             instance = new ActivityResultItem();
65         }
66         instance.mResultInfoList = resultInfoList;
67 
68         return instance;
69     }
70 
71     @Override
recycle()72     public void recycle() {
73         mResultInfoList = null;
74         ObjectPool.recycle(this);
75     }
76 
77 
78     // Parcelable implementation
79 
80     /** Write to Parcel. */
81     @Override
writeToParcel(Parcel dest, int flags)82     public void writeToParcel(Parcel dest, int flags) {
83         dest.writeTypedList(mResultInfoList, flags);
84     }
85 
86     /** Read from Parcel. */
ActivityResultItem(Parcel in)87     private ActivityResultItem(Parcel in) {
88         mResultInfoList = in.createTypedArrayList(ResultInfo.CREATOR);
89     }
90 
91     public static final @android.annotation.NonNull Parcelable.Creator<ActivityResultItem> CREATOR =
92             new Parcelable.Creator<ActivityResultItem>() {
93         public ActivityResultItem createFromParcel(Parcel in) {
94             return new ActivityResultItem(in);
95         }
96 
97         public ActivityResultItem[] newArray(int size) {
98             return new ActivityResultItem[size];
99         }
100     };
101 
102     @Override
equals(Object o)103     public boolean equals(Object o) {
104         if (this == o) {
105             return true;
106         }
107         if (o == null || getClass() != o.getClass()) {
108             return false;
109         }
110         final ActivityResultItem other = (ActivityResultItem) o;
111         return Objects.equals(mResultInfoList, other.mResultInfoList);
112     }
113 
114     @Override
hashCode()115     public int hashCode() {
116         return mResultInfoList.hashCode();
117     }
118 
119     @Override
toString()120     public String toString() {
121         return "ActivityResultItem{resultInfoList=" + mResultInfoList + "}";
122     }
123 }
124