Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 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 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 19 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 20 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 22 | import android.app.ClientTransactionHandler; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 23 | import android.app.ResultInfo; |
| 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; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 30 | import java.util.Objects; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Activity result delivery callback. |
| 34 | * @hide |
| 35 | */ |
| 36 | public class ActivityResultItem extends ClientTransactionItem { |
| 37 | |
Mathew Inwood | 98e9ad1 | 2018-08-30 13:11:50 +0100 | [diff] [blame] | 38 | @UnsupportedAppUsage |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 39 | private List<ResultInfo> mResultInfoList; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 40 | |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 41 | /* TODO(b/78294732) |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 42 | @Override |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 43 | public int getPostExecutionState() { |
| 44 | return ON_RESUME; |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 45 | }*/ |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 46 | |
| 47 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 48 | public void execute(ClientTransactionHandler client, IBinder token, |
| 49 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 50 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityDeliverResult"); |
Andrii Kulian | e55b009 | 2018-04-19 15:29:22 -0700 | [diff] [blame] | 51 | client.handleSendResult(token, mResultInfoList, "ACTIVITY_RESULT"); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 52 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 53 | } |
| 54 | |
| 55 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 56 | // ObjectPoolItem implementation |
| 57 | |
| 58 | private ActivityResultItem() {} |
| 59 | |
| 60 | /** Obtain an instance initialized with provided params. */ |
| 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 |
| 72 | public void recycle() { |
| 73 | mResultInfoList = null; |
| 74 | ObjectPool.recycle(this); |
| 75 | } |
| 76 | |
| 77 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 78 | // Parcelable implementation |
| 79 | |
| 80 | /** Write to Parcel. */ |
| 81 | @Override |
| 82 | public void writeToParcel(Parcel dest, int flags) { |
| 83 | dest.writeTypedList(mResultInfoList, flags); |
| 84 | } |
| 85 | |
| 86 | /** Read from Parcel. */ |
| 87 | private ActivityResultItem(Parcel in) { |
| 88 | mResultInfoList = in.createTypedArrayList(ResultInfo.CREATOR); |
| 89 | } |
| 90 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 91 | public static final @android.annotation.NonNull Parcelable.Creator<ActivityResultItem> CREATOR = |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 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 | }; |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 101 | |
| 102 | @Override |
| 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; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 111 | return Objects.equals(mResultInfoList, other.mResultInfoList); |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public int hashCode() { |
| 116 | return mResultInfoList.hashCode(); |
| 117 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 118 | |
| 119 | @Override |
| 120 | public String toString() { |
| 121 | return "ActivityResultItem{resultInfoList=" + mResultInfoList + "}"; |
| 122 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 123 | } |