1 /*
2  * Copyright (C) 2022 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.window;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * Data object to hold an {@link IOnBackInvokedCallback} and its priority.
25  * @hide
26  */
27 public final class OnBackInvokedCallbackInfo implements Parcelable {
28     @NonNull
29     private final IOnBackInvokedCallback mCallback;
30     private @OnBackInvokedDispatcher.Priority int mPriority;
31     private final boolean mIsAnimationCallback;
32 
OnBackInvokedCallbackInfo(@onNull IOnBackInvokedCallback callback, int priority, boolean isAnimationCallback)33     public OnBackInvokedCallbackInfo(@NonNull IOnBackInvokedCallback callback,
34             int priority,
35             boolean isAnimationCallback) {
36         mCallback = callback;
37         mPriority = priority;
38         mIsAnimationCallback = isAnimationCallback;
39     }
40 
OnBackInvokedCallbackInfo(@onNull Parcel in)41     private OnBackInvokedCallbackInfo(@NonNull Parcel in) {
42         mCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder());
43         mPriority = in.readInt();
44         mIsAnimationCallback = in.readBoolean();
45     }
46 
47     @Override
describeContents()48     public int describeContents() {
49         return 0;
50     }
51 
52     @Override
writeToParcel(@onNull Parcel dest, int flags)53     public void writeToParcel(@NonNull Parcel dest, int flags) {
54         dest.writeStrongInterface(mCallback);
55         dest.writeInt(mPriority);
56         dest.writeBoolean(mIsAnimationCallback);
57     }
58 
59     public static final Creator<OnBackInvokedCallbackInfo> CREATOR =
60             new Creator<OnBackInvokedCallbackInfo>() {
61                 @Override
62                 public OnBackInvokedCallbackInfo createFromParcel(Parcel in) {
63                     return new OnBackInvokedCallbackInfo(in);
64                 }
65 
66                 @Override
67                 public OnBackInvokedCallbackInfo[] newArray(int size) {
68                     return new OnBackInvokedCallbackInfo[size];
69                 }
70             };
71 
isSystemCallback()72     public boolean isSystemCallback() {
73         return mPriority == OnBackInvokedDispatcher.PRIORITY_SYSTEM;
74     }
75 
76     @NonNull
getCallback()77     public IOnBackInvokedCallback getCallback() {
78         return mCallback;
79     }
80 
81     @OnBackInvokedDispatcher.Priority
getPriority()82     public int getPriority() {
83         return mPriority;
84     }
85 
isAnimationCallback()86     public boolean isAnimationCallback() {
87         return mIsAnimationCallback;
88     }
89 
90     @Override
toString()91     public String toString() {
92         return "OnBackInvokedCallbackInfo{"
93                 + "mCallback=" + mCallback
94                 + ", mPriority=" + mPriority
95                 + ", mIsAnimationCallback=" + mIsAnimationCallback
96                 + '}';
97     }
98 }
99