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.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.app.ActivityThread; 23 import android.app.ClientTransactionHandler; 24 import android.os.Parcel; 25 import android.window.SplashScreenView.SplashScreenViewParcelable; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * Transfer a splash screen view to an Activity. 32 * @hide 33 */ 34 public class TransferSplashScreenViewStateItem extends ActivityTransactionItem { 35 36 private SplashScreenViewParcelable mSplashScreenViewParcelable; 37 private @TransferRequest int mRequest; 38 39 @IntDef(value = { 40 ATTACH_TO, 41 HANDOVER_TO 42 }) 43 @Retention(RetentionPolicy.SOURCE) 44 public @interface TransferRequest {} 45 // request client to attach the view on it. 46 public static final int ATTACH_TO = 0; 47 // tell client that you can handle the splash screen view. 48 public static final int HANDOVER_TO = 1; 49 50 @Override execute(@onNull ClientTransactionHandler client, @NonNull ActivityThread.ActivityClientRecord r, PendingTransactionActions pendingActions)51 public void execute(@NonNull ClientTransactionHandler client, 52 @NonNull ActivityThread.ActivityClientRecord r, 53 PendingTransactionActions pendingActions) { 54 switch (mRequest) { 55 case ATTACH_TO: 56 client.handleAttachSplashScreenView(r, mSplashScreenViewParcelable); 57 break; 58 case HANDOVER_TO: 59 client.handOverSplashScreenView(r); 60 break; 61 } 62 } 63 64 @Override recycle()65 public void recycle() { 66 ObjectPool.recycle(this); 67 } 68 69 @Override writeToParcel(Parcel dest, int flags)70 public void writeToParcel(Parcel dest, int flags) { 71 dest.writeInt(mRequest); 72 dest.writeTypedObject(mSplashScreenViewParcelable, flags); 73 } 74 TransferSplashScreenViewStateItem()75 private TransferSplashScreenViewStateItem() {} TransferSplashScreenViewStateItem(Parcel in)76 private TransferSplashScreenViewStateItem(Parcel in) { 77 mRequest = in.readInt(); 78 mSplashScreenViewParcelable = in.readTypedObject(SplashScreenViewParcelable.CREATOR); 79 } 80 81 /** Obtain an instance initialized with provided params. */ obtain(@ransferRequest int state, @Nullable SplashScreenViewParcelable parcelable)82 public static TransferSplashScreenViewStateItem obtain(@TransferRequest int state, 83 @Nullable SplashScreenViewParcelable parcelable) { 84 TransferSplashScreenViewStateItem instance = 85 ObjectPool.obtain(TransferSplashScreenViewStateItem.class); 86 if (instance == null) { 87 instance = new TransferSplashScreenViewStateItem(); 88 } 89 instance.mRequest = state; 90 instance.mSplashScreenViewParcelable = parcelable; 91 92 return instance; 93 } 94 95 public static final @NonNull Creator<TransferSplashScreenViewStateItem> CREATOR = 96 new Creator<TransferSplashScreenViewStateItem>() { 97 public TransferSplashScreenViewStateItem createFromParcel(Parcel in) { 98 return new TransferSplashScreenViewStateItem(in); 99 } 100 101 public TransferSplashScreenViewStateItem[] newArray(int size) { 102 return new TransferSplashScreenViewStateItem[size]; 103 } 104 }; 105 } 106