1 /*
2  * Copyright (C) 2020 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 android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.app.ActivityThread;
22 import android.app.ClientTransactionHandler;
23 import android.os.Parcel;
24 import android.view.SurfaceControl;
25 import android.window.SplashScreenView.SplashScreenViewParcelable;
26 
27 /**
28  * Transfer a splash screen view to an Activity.
29  * @hide
30  */
31 public class TransferSplashScreenViewStateItem extends ActivityTransactionItem {
32 
33     private SplashScreenViewParcelable mSplashScreenViewParcelable;
34     private SurfaceControl mStartingWindowLeash;
35 
36     @Override
execute(@onNull ClientTransactionHandler client, @NonNull ActivityThread.ActivityClientRecord r, PendingTransactionActions pendingActions)37     public void execute(@NonNull ClientTransactionHandler client,
38             @NonNull ActivityThread.ActivityClientRecord r,
39             PendingTransactionActions pendingActions) {
40         client.handleAttachSplashScreenView(r, mSplashScreenViewParcelable, mStartingWindowLeash);
41     }
42 
43     @Override
recycle()44     public void recycle() {
45         ObjectPool.recycle(this);
46     }
47 
48     @Override
writeToParcel(Parcel dest, int flags)49     public void writeToParcel(Parcel dest, int flags) {
50         dest.writeTypedObject(mSplashScreenViewParcelable, flags);
51         dest.writeTypedObject(mStartingWindowLeash, flags);
52     }
53 
TransferSplashScreenViewStateItem()54     private TransferSplashScreenViewStateItem() {}
TransferSplashScreenViewStateItem(Parcel in)55     private TransferSplashScreenViewStateItem(Parcel in) {
56         mSplashScreenViewParcelable = in.readTypedObject(SplashScreenViewParcelable.CREATOR);
57         mStartingWindowLeash = in.readTypedObject(SurfaceControl.CREATOR);
58     }
59 
60     /** Obtain an instance initialized with provided params. */
obtain( @ullable SplashScreenViewParcelable parcelable, @Nullable SurfaceControl startingWindowLeash)61     public static TransferSplashScreenViewStateItem obtain(
62             @Nullable SplashScreenViewParcelable parcelable,
63             @Nullable SurfaceControl startingWindowLeash) {
64         TransferSplashScreenViewStateItem instance =
65                 ObjectPool.obtain(TransferSplashScreenViewStateItem.class);
66         if (instance == null) {
67             instance = new TransferSplashScreenViewStateItem();
68         }
69         instance.mSplashScreenViewParcelable = parcelable;
70         instance.mStartingWindowLeash = startingWindowLeash;
71 
72         return instance;
73     }
74 
75     public static final @NonNull Creator<TransferSplashScreenViewStateItem> CREATOR =
76             new Creator<TransferSplashScreenViewStateItem>() {
77                 public TransferSplashScreenViewStateItem createFromParcel(Parcel in) {
78                     return new TransferSplashScreenViewStateItem(in);
79                 }
80 
81                 public TransferSplashScreenViewStateItem[] newArray(int size) {
82                     return new TransferSplashScreenViewStateItem[size];
83                 }
84             };
85 }
86