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