1 /*
2  * Copyright (C) 2024 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.appsearch.aidl;
18 
19 import android.annotation.ElapsedRealtimeLong;
20 import android.annotation.NonNull;
21 import android.app.appsearch.safeparcel.AbstractSafeParcelable;
22 import android.app.appsearch.safeparcel.SafeParcelable;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.os.UserHandle;
26 
27 import java.util.Objects;
28 
29 /**
30  * Encapsulates a request to make a binder call to invalidate the next-page token so that no more
31  * results of the related search can be returned.
32  *
33  * @hide
34  */
35 @SafeParcelable.Class(creator = "InvalidateNextPageTokenAidlRequestCreator")
36 public class InvalidateNextPageTokenAidlRequest extends AbstractSafeParcelable {
37     @NonNull
38     public static final Parcelable.Creator<InvalidateNextPageTokenAidlRequest> CREATOR =
39             new InvalidateNextPageTokenAidlRequestCreator();
40 
41     @NonNull
42     @Field(id = 1, getter = "getCallerAttributionSource")
43     private final AppSearchAttributionSource mCallerAttributionSource;
44 
45     @Field(id = 2, getter = "getNextPageToken")
46     private final long mNextPageToken;
47 
48     @NonNull
49     @Field(id = 3, getter = "getUserHandle")
50     private final UserHandle mUserHandle;
51 
52     @Field(id = 4, getter = "getBinderCallStartTimeMillis")
53     @ElapsedRealtimeLong
54     private final long mBinderCallStartTimeMillis;
55 
56     @Field(id = 5, getter = "isForEnterprise")
57     private final boolean mIsForEnterprise;
58 
59     /**
60      * Invalidates the next-page token so that no more results of the related search can be
61      * returned.
62      *
63      * @param callerAttributionSource The permission identity of the package to persist to disk for.
64      * @param nextPageToken The token of pre-loaded results of previously executed search to be
65      *     invalidated.
66      * @param userHandle Handle of the calling user
67      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
68      * @param isForEnterprise Whether to user the user's enterprise profile AppSearch instance
69      */
70     @Constructor
InvalidateNextPageTokenAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) long nextPageToken, @Param(id = 3) @NonNull UserHandle userHandle, @Param(id = 4) @ElapsedRealtimeLong long binderCallStartTimeMillis, @Param(id = 5) boolean isForEnterprise)71     public InvalidateNextPageTokenAidlRequest(
72             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
73             @Param(id = 2) long nextPageToken,
74             @Param(id = 3) @NonNull UserHandle userHandle,
75             @Param(id = 4) @ElapsedRealtimeLong long binderCallStartTimeMillis,
76             @Param(id = 5) boolean isForEnterprise) {
77         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
78         mNextPageToken = nextPageToken;
79         mUserHandle = Objects.requireNonNull(userHandle);
80         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
81         mIsForEnterprise = isForEnterprise;
82     }
83 
84     @NonNull
getCallerAttributionSource()85     public AppSearchAttributionSource getCallerAttributionSource() {
86         return mCallerAttributionSource;
87     }
88 
getNextPageToken()89     public long getNextPageToken() {
90         return mNextPageToken;
91     }
92 
93     @NonNull
getUserHandle()94     public UserHandle getUserHandle() {
95         return mUserHandle;
96     }
97 
98     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()99     public long getBinderCallStartTimeMillis() {
100         return mBinderCallStartTimeMillis;
101     }
102 
isForEnterprise()103     public boolean isForEnterprise() {
104         return mIsForEnterprise;
105     }
106 
107     @Override
writeToParcel(@onNull Parcel dest, int flags)108     public void writeToParcel(@NonNull Parcel dest, int flags) {
109         InvalidateNextPageTokenAidlRequestCreator.writeToParcel(this, dest, flags);
110     }
111 }
112