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.annotation.Nullable;
22 import android.app.appsearch.AppSearchSchema;
23 import android.app.appsearch.safeparcel.AbstractSafeParcelable;
24 import android.app.appsearch.safeparcel.SafeParcelable;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 import android.os.UserHandle;
28 
29 import java.util.Objects;
30 
31 /**
32  * Encapsulates a request to make a binder call to fetch the next page of results of a previously
33  * executed search.
34  *
35  * @hide
36  */
37 @SafeParcelable.Class(creator = "GetNextPageAidlRequestCreator")
38 public class GetNextPageAidlRequest extends AbstractSafeParcelable {
39     @NonNull
40     public static final Parcelable.Creator<GetNextPageAidlRequest> CREATOR =
41             new GetNextPageAidlRequestCreator();
42 
43     @NonNull
44     @Field(id = 1, getter = "getCallerAttributionSource")
45     private final AppSearchAttributionSource mCallerAttributionSource;
46 
47     @Nullable
48     @Field(id = 2, getter = "getDatabaseName")
49     private final String mDatabaseName;
50 
51     @Field(id = 3, getter = "getNextPageToken")
52     private final long mNextPageToken;
53 
54     @Field(id = 4, getter = "getJoinType")
55     @AppSearchSchema.StringPropertyConfig.JoinableValueType
56     private final int mJoinType;
57 
58     @NonNull
59     @Field(id = 5, getter = "getUserHandle")
60     private final UserHandle mUserHandle;
61 
62     @Field(id = 6, getter = "getBinderCallStartTimeMillis")
63     @ElapsedRealtimeLong
64     private final long mBinderCallStartTimeMillis;
65 
66     @Field(id = 7, getter = "isForEnterprise")
67     private final boolean mIsForEnterprise;
68 
69     /**
70      * Fetches the next page of results of a previously executed search. Results can be empty if
71      * next-page token is invalid or all pages have been returned.
72      *
73      * @param callerAttributionSource The permission identity of the package to persist to disk for.
74      * @param databaseName The nullable databaseName this search for. The databaseName will be null
75      *     if the search is a global search.
76      * @param nextPageToken The token of pre-loaded results of previously executed search.
77      * @param joinType the type of join performed. 0 if no join is performed
78      * @param userHandle Handle of the calling user
79      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
80      * @param isForEnterprise Whether to use the user's enterprise profile AppSearch instance
81      */
82     @Constructor
GetNextPageAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @Nullable String databaseName, @Param(id = 3) long nextPageToken, @Param(id = 4) @AppSearchSchema.StringPropertyConfig.JoinableValueType int joinType, @Param(id = 5) @NonNull UserHandle userHandle, @Param(id = 6) @ElapsedRealtimeLong long binderCallStartTimeMillis, @Param(id = 7) boolean isForEnterprise)83     public GetNextPageAidlRequest(
84             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
85             @Param(id = 2) @Nullable String databaseName,
86             @Param(id = 3) long nextPageToken,
87             @Param(id = 4) @AppSearchSchema.StringPropertyConfig.JoinableValueType int joinType,
88             @Param(id = 5) @NonNull UserHandle userHandle,
89             @Param(id = 6) @ElapsedRealtimeLong long binderCallStartTimeMillis,
90             @Param(id = 7) boolean isForEnterprise) {
91         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
92         mDatabaseName = databaseName;
93         mNextPageToken = nextPageToken;
94         mJoinType = joinType;
95         mUserHandle = Objects.requireNonNull(userHandle);
96         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
97         mIsForEnterprise = isForEnterprise;
98     }
99 
100     @NonNull
getCallerAttributionSource()101     public AppSearchAttributionSource getCallerAttributionSource() {
102         return mCallerAttributionSource;
103     }
104 
105     @Nullable
getDatabaseName()106     public String getDatabaseName() {
107         return mDatabaseName;
108     }
109 
getNextPageToken()110     public long getNextPageToken() {
111         return mNextPageToken;
112     }
113 
114     @AppSearchSchema.StringPropertyConfig.JoinableValueType
getJoinType()115     public int getJoinType() {
116         return mJoinType;
117     }
118 
119     @NonNull
getUserHandle()120     public UserHandle getUserHandle() {
121         return mUserHandle;
122     }
123 
124     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()125     public long getBinderCallStartTimeMillis() {
126         return mBinderCallStartTimeMillis;
127     }
128 
isForEnterprise()129     public boolean isForEnterprise() {
130         return mIsForEnterprise;
131     }
132 
133     @Override
writeToParcel(@onNull Parcel dest, int flags)134     public void writeToParcel(@NonNull Parcel dest, int flags) {
135         GetNextPageAidlRequestCreator.writeToParcel(this, dest, flags);
136     }
137 }
138