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.app.servertransaction.ActivityLifecycleItem.LifecycleState;
20 import static android.app.servertransaction.ActivityLifecycleItem.UNDEFINED;
21 
22 import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;
23 
24 import android.annotation.NonNull;
25 import android.annotation.Nullable;
26 import android.app.ClientTransactionHandler;
27 import android.os.IBinder;
28 import android.os.Parcelable;
29 
30 import com.android.internal.annotations.VisibleForTesting;
31 
32 import java.io.PrintWriter;
33 
34 /**
35  * A callback message to a client that can be scheduled and executed.
36  * Examples of these might be activity configuration change, multi-window mode change, activity
37  * result delivery etc.
38  *
39  * @see ClientTransaction
40  * @see com.android.server.wm.ClientLifecycleManager
41  * @hide
42  */
43 public abstract class ClientTransactionItem implements BaseClientRequest, Parcelable {
44 
45     /** Get the state that must follow this callback. */
46     @LifecycleState
getPostExecutionState()47     public int getPostExecutionState() {
48         return UNDEFINED;
49     }
50 
shouldHaveDefinedPreExecutionState()51     boolean shouldHaveDefinedPreExecutionState() {
52         return true;
53     }
54 
55     /**
56      * Returns the activity token if this transaction item is activity-targeting. Otherwise,
57      * returns {@code null}.
58      */
59     @VisibleForTesting(visibility = PACKAGE)
60     @Nullable
getActivityToken()61     public IBinder getActivityToken() {
62         return null;
63     }
64 
65     /**
66      * Whether this is a {@link ActivityLifecycleItem}.
67      */
isActivityLifecycleItem()68     public boolean isActivityLifecycleItem() {
69         return false;
70     }
71 
72     /** Dumps this transaction item. */
dump(@onNull String prefix, @NonNull PrintWriter pw, @NonNull ClientTransactionHandler transactionHandler)73     void dump(@NonNull String prefix, @NonNull PrintWriter pw,
74             @NonNull ClientTransactionHandler transactionHandler) {
75         pw.append(prefix).println(this);
76     }
77 
78     // Parcelable
79 
80     @Override
describeContents()81     public int describeContents() {
82         return 0;
83     }
84 }
85