| 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.app.servertransaction.ActivityLifecycleItem.LifecycleState; |
| 20 |
import static android.app.servertransaction.ActivityLifecycleItem.ON_PAUSE; |
| 21 |
import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP; |
| 22 |
|
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.Nullable; |
| 25 |
import android.app.ActivityThread.ActivityClientRecord; |
| 26 |
import android.app.ClientTransactionHandler; |
| 27 |
import android.os.IBinder; |
| 28 |
import android.os.Parcel; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class RefreshCallbackItem extends ActivityTransactionItem { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
@LifecycleState |
| 47 |
private int mPostExecutionState; |
| 48 |
|
| 49 |
@Override |
| 50 |
public void execute(@NonNull ClientTransactionHandler client, |
| 51 |
@NonNull ActivityClientRecord r, PendingTransactionActions pendingActions) {} |
| 52 |
|
| 53 |
@Override |
| 54 |
public void postExecute(ClientTransactionHandler client, IBinder token, |
| 55 |
PendingTransactionActions pendingActions) { |
| 56 |
final ActivityClientRecord r = getActivityClientRecord(client, token); |
| 57 |
client.reportRefresh(r); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public int getPostExecutionState() { |
| 62 |
return mPostExecutionState; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
boolean shouldHaveDefinedPreExecutionState() { |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@Override |
| 73 |
public void recycle() { |
| 74 |
ObjectPool.recycle(this); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public static RefreshCallbackItem obtain(@LifecycleState int postExecutionState) { |
| 83 |
if (postExecutionState != ON_STOP && postExecutionState != ON_PAUSE) { |
| 84 |
throw new IllegalArgumentException( |
| 85 |
"Only ON_STOP or ON_PAUSE are allowed as a post execution state for " |
| 86 |
+ "RefreshCallbackItem but got " + postExecutionState); |
| 87 |
} |
| 88 |
RefreshCallbackItem instance = |
| 89 |
ObjectPool.obtain(RefreshCallbackItem.class); |
| 90 |
if (instance == null) { |
| 91 |
instance = new RefreshCallbackItem(); |
| 92 |
} |
| 93 |
instance.mPostExecutionState = postExecutionState; |
| 94 |
return instance; |
| 95 |
} |
| 96 |
|
| 97 |
private RefreshCallbackItem() {} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
@Override |
| 102 |
public void writeToParcel(Parcel dest, int flags) { |
| 103 |
dest.writeInt(mPostExecutionState); |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public boolean equals(@Nullable Object o) { |
| 108 |
if (this == o) { |
| 109 |
return true; |
| 110 |
} |
| 111 |
if (o == null || getClass() != o.getClass()) { |
| 112 |
return false; |
| 113 |
} |
| 114 |
final RefreshCallbackItem other = (RefreshCallbackItem) o; |
| 115 |
return mPostExecutionState == other.mPostExecutionState; |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public int hashCode() { |
| 120 |
int result = 17; |
| 121 |
result = 31 * result + mPostExecutionState; |
| 122 |
return result; |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public String toString() { |
| 127 |
return "RefreshCallbackItem{mPostExecutionState=" + mPostExecutionState + "}"; |
| 128 |
} |
| 129 |
|
| 130 |
private RefreshCallbackItem(Parcel in) { |
| 131 |
mPostExecutionState = in.readInt(); |
| 132 |
} |
| 133 |
|
| 134 |
public static final @NonNull Creator<RefreshCallbackItem> CREATOR = |
| 135 |
new Creator<RefreshCallbackItem>() { |
| 136 |
|
| 137 |
public RefreshCallbackItem createFromParcel(Parcel in) { |
| 138 |
return new RefreshCallbackItem(in); |
| 139 |
} |
| 140 |
|
| 141 |
public RefreshCallbackItem[] newArray(int size) { |
| 142 |
return new RefreshCallbackItem[size]; |
| 143 |
} |
| 144 |
}; |
| 145 |
} |