1 /* 2 * Copyright 2021 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.Nullable; 20 import android.app.ActivityThread.ActivityClientRecord; 21 import android.app.ClientTransactionHandler; 22 import android.app.PictureInPictureUiState; 23 import android.os.Parcel; 24 25 /** 26 * Request an activity to enter picture-in-picture mode. 27 * @hide 28 */ 29 public final class PipStateTransactionItem extends ActivityTransactionItem { 30 31 private PictureInPictureUiState mPipState; 32 33 @Override execute(ClientTransactionHandler client, ActivityClientRecord r, PendingTransactionActions pendingActions)34 public void execute(ClientTransactionHandler client, ActivityClientRecord r, 35 PendingTransactionActions pendingActions) { 36 client.handlePictureInPictureStateChanged(r, mPipState); 37 } 38 39 // ObjectPoolItem implementation 40 PipStateTransactionItem()41 private PipStateTransactionItem() {} 42 43 /** Obtain an instance initialized with provided params. */ obtain(PictureInPictureUiState pipState)44 public static PipStateTransactionItem obtain(PictureInPictureUiState pipState) { 45 PipStateTransactionItem instance = ObjectPool.obtain(PipStateTransactionItem.class); 46 if (instance == null) { 47 instance = new PipStateTransactionItem(); 48 } 49 instance.mPipState = pipState; 50 51 return instance; 52 } 53 54 @Override recycle()55 public void recycle() { 56 mPipState = null; 57 ObjectPool.recycle(this); 58 } 59 60 // Parcelable implementation 61 62 /** Write to Parcel. */ 63 @Override writeToParcel(Parcel dest, int flags)64 public void writeToParcel(Parcel dest, int flags) { 65 mPipState.writeToParcel(dest, flags); 66 } 67 68 /** Read from Parcel. */ PipStateTransactionItem(Parcel in)69 private PipStateTransactionItem(Parcel in) { 70 mPipState = PictureInPictureUiState.CREATOR.createFromParcel(in); 71 } 72 73 public static final @android.annotation.NonNull Creator<PipStateTransactionItem> CREATOR = 74 new Creator<PipStateTransactionItem>() { 75 public PipStateTransactionItem createFromParcel(Parcel in) { 76 return new PipStateTransactionItem(in); 77 } 78 79 public PipStateTransactionItem[] newArray(int size) { 80 return new PipStateTransactionItem[size]; 81 } 82 }; 83 84 @Override equals(@ullable Object o)85 public boolean equals(@Nullable Object o) { 86 return this == o; 87 } 88 89 @Override toString()90 public String toString() { 91 return "PipStateTransactionItem{}"; 92 } 93 } 94