StopActivityItem.java revision 1d0d514dac43857f4475648a331eeccd481aa4db
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
17package android.app.servertransaction;
18
19import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
20
21import android.app.ClientTransactionHandler;
22import android.os.IBinder;
23import android.os.Parcel;
24import android.os.Trace;
25
26/**
27 * Request to move an activity to stopped state.
28 * @hide
29 */
30public class StopActivityItem extends ActivityLifecycleItem {
31
32    private static final String TAG = "StopActivityItem";
33
34    private boolean mShowWindow;
35    private int mConfigChanges;
36
37    @Override
38    public void execute(ClientTransactionHandler client, IBinder token,
39            PendingTransactionActions pendingActions) {
40        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
41        client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions,
42                true /* finalStateRequest */, "STOP_ACTIVITY_ITEM");
43        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
44    }
45
46    @Override
47    public void postExecute(ClientTransactionHandler client, IBinder token,
48            PendingTransactionActions pendingActions) {
49        client.reportStop(pendingActions);
50    }
51
52    @Override
53    public int getTargetState() {
54        return ON_STOP;
55    }
56
57
58    // ObjectPoolItem implementation
59
60    private StopActivityItem() {}
61
62    /** Obtain an instance initialized with provided params. */
63    public static StopActivityItem obtain(boolean showWindow, int configChanges) {
64        StopActivityItem instance = ObjectPool.obtain(StopActivityItem.class);
65        if (instance == null) {
66            instance = new StopActivityItem();
67        }
68        instance.mShowWindow = showWindow;
69        instance.mConfigChanges = configChanges;
70
71        return instance;
72    }
73
74    @Override
75    public void recycle() {
76        super.recycle();
77        mShowWindow = false;
78        mConfigChanges = 0;
79        ObjectPool.recycle(this);
80    }
81
82
83    // Parcelable implementation
84
85    /** Write to Parcel. */
86    @Override
87    public void writeToParcel(Parcel dest, int flags) {
88        dest.writeBoolean(mShowWindow);
89        dest.writeInt(mConfigChanges);
90    }
91
92    /** Read from Parcel. */
93    private StopActivityItem(Parcel in) {
94        mShowWindow = in.readBoolean();
95        mConfigChanges = in.readInt();
96    }
97
98    public static final Creator<StopActivityItem> CREATOR =
99            new Creator<StopActivityItem>() {
100        public StopActivityItem createFromParcel(Parcel in) {
101            return new StopActivityItem(in);
102        }
103
104        public StopActivityItem[] newArray(int size) {
105            return new StopActivityItem[size];
106        }
107    };
108
109    @Override
110    public boolean equals(Object o) {
111        if (this == o) {
112            return true;
113        }
114        if (o == null || getClass() != o.getClass()) {
115            return false;
116        }
117        final StopActivityItem other = (StopActivityItem) o;
118        return mShowWindow == other.mShowWindow && mConfigChanges == other.mConfigChanges;
119    }
120
121    @Override
122    public int hashCode() {
123        int result = 17;
124        result = 31 * result + (mShowWindow ? 1 : 0);
125        result = 31 * result + mConfigChanges;
126        return result;
127    }
128
129    @Override
130    public String toString() {
131        return "StopActivityItem{showWindow=" + mShowWindow + ",configChanges=" + mConfigChanges
132                + "}";
133    }
134}
135