| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.servertransaction; |
| 18 |
|
| 19 |
import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.app.ActivityThread.ActivityClientRecord; |
| 24 |
import android.app.ClientTransactionHandler; |
| 25 |
import android.content.res.Configuration; |
| 26 |
import android.os.IBinder; |
| 27 |
import android.os.Parcel; |
| 28 |
import android.os.Trace; |
| 29 |
|
| 30 |
import java.util.Objects; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class MoveToDisplayItem extends ActivityTransactionItem { |
| 37 |
|
| 38 |
private int mTargetDisplayId; |
| 39 |
private Configuration mConfiguration; |
| 40 |
|
| 41 |
@Override |
| 42 |
public void preExecute(ClientTransactionHandler client, IBinder token) { |
| 43 |
|
| 44 |
|
| 45 |
client.updatePendingActivityConfiguration(token, mConfiguration); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void execute(ClientTransactionHandler client, ActivityClientRecord r, |
| 50 |
PendingTransactionActions pendingActions) { |
| 51 |
Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityMovedToDisplay"); |
| 52 |
client.handleActivityConfigurationChanged(r, mConfiguration, mTargetDisplayId); |
| 53 |
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
private MoveToDisplayItem() {} |
| 60 |
|
| 61 |
|
| 62 |
public static MoveToDisplayItem obtain(int targetDisplayId, |
| 63 |
@NonNull Configuration configuration) { |
| 64 |
if (configuration == null) { |
| 65 |
throw new IllegalArgumentException("Configuration must not be null"); |
| 66 |
} |
| 67 |
|
| 68 |
MoveToDisplayItem instance = ObjectPool.obtain(MoveToDisplayItem.class); |
| 69 |
if (instance == null) { |
| 70 |
instance = new MoveToDisplayItem(); |
| 71 |
} |
| 72 |
instance.mTargetDisplayId = targetDisplayId; |
| 73 |
instance.mConfiguration = configuration; |
| 74 |
|
| 75 |
return instance; |
| 76 |
} |
| 77 |
|
| 78 |
@Override |
| 79 |
public void recycle() { |
| 80 |
mTargetDisplayId = 0; |
| 81 |
mConfiguration = Configuration.EMPTY; |
| 82 |
ObjectPool.recycle(this); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
@Override |
| 90 |
public void writeToParcel(Parcel dest, int flags) { |
| 91 |
dest.writeInt(mTargetDisplayId); |
| 92 |
dest.writeTypedObject(mConfiguration, flags); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
private MoveToDisplayItem(Parcel in) { |
| 97 |
mTargetDisplayId = in.readInt(); |
| 98 |
mConfiguration = in.readTypedObject(Configuration.CREATOR); |
| 99 |
} |
| 100 |
|
| 101 |
public static final @NonNull Creator<MoveToDisplayItem> CREATOR = |
| 102 |
new Creator<MoveToDisplayItem>() { |
| 103 |
public MoveToDisplayItem createFromParcel(Parcel in) { |
| 104 |
return new MoveToDisplayItem(in); |
| 105 |
} |
| 106 |
|
| 107 |
public MoveToDisplayItem[] newArray(int size) { |
| 108 |
return new MoveToDisplayItem[size]; |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
@Override |
| 113 |
public boolean equals(@Nullable Object o) { |
| 114 |
if (this == o) { |
| 115 |
return true; |
| 116 |
} |
| 117 |
if (o == null || getClass() != o.getClass()) { |
| 118 |
return false; |
| 119 |
} |
| 120 |
final MoveToDisplayItem other = (MoveToDisplayItem) o; |
| 121 |
return mTargetDisplayId == other.mTargetDisplayId |
| 122 |
&& Objects.equals(mConfiguration, other.mConfiguration); |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public int hashCode() { |
| 127 |
int result = 17; |
| 128 |
result = 31 * result + mTargetDisplayId; |
| 129 |
result = 31 * result + mConfiguration.hashCode(); |
| 130 |
return result; |
| 131 |
} |
| 132 |
|
| 133 |
@Override |
| 134 |
public String toString() { |
| 135 |
return "MoveToDisplayItem{targetDisplayId=" + mTargetDisplayId |
| 136 |
+ ",configuration=" + mConfiguration + "}"; |
| 137 |
} |
| 138 |
} |