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 | |
| 19 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 20 | import static android.view.Display.INVALID_DISPLAY; |
| 21 | |
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.content.res.Configuration; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.Parcel; |
| 26 | import android.os.Trace; |
| 27 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 28 | import java.util.Objects; |
| 29 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Activity configuration changed callback. |
| 32 | * @hide |
| 33 | */ |
| 34 | public class ActivityConfigurationChangeItem extends ClientTransactionItem { |
| 35 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 36 | private Configuration mConfiguration; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 37 | |
| 38 | @Override |
Garfield Tan | 0443b37 | 2019-01-04 15:00:13 -0800 | [diff] [blame] | 39 | public void preExecute(android.app.ClientTransactionHandler client, IBinder token) { |
| 40 | client.updatePendingActivityConfiguration(token, mConfiguration); |
| 41 | } |
| 42 | |
| 43 | @Override |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 44 | public void execute(ClientTransactionHandler client, IBinder token, |
| 45 | PendingTransactionActions pendingActions) { |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 46 | // TODO(lifecycler): detect if PIP or multi-window mode changed and report it here. |
| 47 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged"); |
| 48 | client.handleActivityConfigurationChanged(token, mConfiguration, INVALID_DISPLAY); |
| 49 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 50 | } |
| 51 | |
| 52 | |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 53 | // ObjectPoolItem implementation |
| 54 | |
| 55 | private ActivityConfigurationChangeItem() {} |
| 56 | |
| 57 | /** Obtain an instance initialized with provided params. */ |
| 58 | public static ActivityConfigurationChangeItem obtain(Configuration config) { |
| 59 | ActivityConfigurationChangeItem instance = |
| 60 | ObjectPool.obtain(ActivityConfigurationChangeItem.class); |
| 61 | if (instance == null) { |
| 62 | instance = new ActivityConfigurationChangeItem(); |
| 63 | } |
| 64 | instance.mConfiguration = config; |
| 65 | |
| 66 | return instance; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void recycle() { |
| 71 | mConfiguration = null; |
| 72 | ObjectPool.recycle(this); |
| 73 | } |
| 74 | |
| 75 | |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 76 | // Parcelable implementation |
| 77 | |
| 78 | /** Write to Parcel. */ |
| 79 | @Override |
| 80 | public void writeToParcel(Parcel dest, int flags) { |
| 81 | dest.writeTypedObject(mConfiguration, flags); |
| 82 | } |
| 83 | |
| 84 | /** Read from Parcel. */ |
| 85 | private ActivityConfigurationChangeItem(Parcel in) { |
| 86 | mConfiguration = in.readTypedObject(Configuration.CREATOR); |
| 87 | } |
| 88 | |
| 89 | public static final Creator<ActivityConfigurationChangeItem> CREATOR = |
| 90 | new Creator<ActivityConfigurationChangeItem>() { |
| 91 | public ActivityConfigurationChangeItem createFromParcel(Parcel in) { |
| 92 | return new ActivityConfigurationChangeItem(in); |
| 93 | } |
| 94 | |
| 95 | public ActivityConfigurationChangeItem[] newArray(int size) { |
| 96 | return new ActivityConfigurationChangeItem[size]; |
| 97 | } |
| 98 | }; |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 99 | |
| 100 | @Override |
| 101 | public boolean equals(Object o) { |
| 102 | if (this == o) { |
| 103 | return true; |
| 104 | } |
| 105 | if (o == null || getClass() != o.getClass()) { |
| 106 | return false; |
| 107 | } |
| 108 | final ActivityConfigurationChangeItem other = (ActivityConfigurationChangeItem) o; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 109 | return Objects.equals(mConfiguration, other.mConfiguration); |
Andrii Kulian | 6b9d3a1 | 2017-11-16 14:36:36 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public int hashCode() { |
| 114 | return mConfiguration.hashCode(); |
| 115 | } |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 116 | |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | return "ActivityConfigurationChange{config=" + mConfiguration + "}"; |
| 120 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 121 | } |