• 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 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 
OnBackInvokedCallbackInfo(@onNull IOnBackInvokedCallback callback, int priority)32     public OnBackInvokedCallbackInfo(@NonNull IOnBackInvokedCallback callback, int priority) {
33         mCallback = callback;
34         mPriority = priority;
35     }
36 
OnBackInvokedCallbackInfo(@onNull Parcel in)37     private OnBackInvokedCallbackInfo(@NonNull Parcel in) {
38         mCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder());
39         mPriority = in.readInt();
40     }
41 
42     @Override
describeContents()43     public int describeContents() {
44         return 0;
45     }
46 
47     @Override
writeToParcel(@onNull Parcel dest, int flags)48     public void writeToParcel(@NonNull Parcel dest, int flags) {
49         dest.writeStrongInterface(mCallback);
50         dest.writeInt(mPriority);
51     }
52 
53     public static final Creator<OnBackInvokedCallbackInfo> CREATOR =
54             new Creator<OnBackInvokedCallbackInfo>() {
55                 @Override
56                 public OnBackInvokedCallbackInfo createFromParcel(Parcel in) {
57                     return new OnBackInvokedCallbackInfo(in);
58                 }
59 
60                 @Override
61                 public OnBackInvokedCallbackInfo[] newArray(int size) {
62                     return new OnBackInvokedCallbackInfo[size];
63                 }
64             };
65 
isSystemCallback()66     public boolean isSystemCallback() {
67         return mPriority == OnBackInvokedDispatcher.PRIORITY_SYSTEM;
68     }
69 
70     @NonNull
getCallback()71     public IOnBackInvokedCallback getCallback() {
72         return mCallback;
73     }
74 
75     @OnBackInvokedDispatcher.Priority
getPriority()76     public int getPriority() {
77         return mPriority;
78     }
79 
80     @Override
toString()81     public String toString() {
82         return "OnBackInvokedCallbackInfo{"
83                 + "mCallback=" + mCallback + ", mPriority=" + mPriority + '}';
84     }
85 }
86