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.GetByDocumentIdRequest; 22 import android.app.appsearch.safeparcel.AbstractSafeParcelable; 23 import android.app.appsearch.safeparcel.SafeParcelable; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 import android.os.UserHandle; 27 28 import java.util.Objects; 29 30 /** 31 * Encapsulates a request to make a binder call to retrieve documents from the index. 32 * 33 * @hide 34 */ 35 @SafeParcelable.Class(creator = "GetDocumentsAidlRequestCreator") 36 public class GetDocumentsAidlRequest extends AbstractSafeParcelable { 37 @NonNull 38 public static final Parcelable.Creator<GetDocumentsAidlRequest> CREATOR = 39 new GetDocumentsAidlRequestCreator(); 40 41 // The permission identity of the package that is getting this document. 42 @NonNull 43 @Field(id = 1, getter = "getCallerAttributionSource") 44 private final AppSearchAttributionSource mCallerAttributionSource; 45 46 // The name of the package that owns this document. 47 @NonNull 48 @Field(id = 2, getter = "getTargetPackageName") 49 private final String mTargetPackageName; 50 51 // The name of the package that owns this document. 52 @NonNull 53 @Field(id = 3, getter = "getDatabaseName") 54 private final String mDatabaseName; 55 56 // The request to retrieve by namespace and IDs from the {@link 57 // AppSearchSession} database for this document. 58 @NonNull 59 @Field(id = 4, getter = "getGetByDocumentIdRequest") 60 private final GetByDocumentIdRequest mGetByDocumentIdRequest; 61 62 // The Handle of the calling user. 63 @NonNull 64 @Field(id = 5, getter = "getUserHandle") 65 private final UserHandle mUserHandle; 66 67 // The start timestamp of binder call in Millis. 68 @Field(id = 6, getter = "getBinderCallStartTimeMillis") 69 @ElapsedRealtimeLong 70 private final long mBinderCallStartTimeMillis; 71 72 // Whether to query the user's enterprise profile AppSearch instance 73 @Field(id = 7, getter = "isForEnterprise") 74 private final boolean mIsForEnterprise; 75 76 /** 77 * Retrieves documents from the index. 78 * 79 * @param callerAttributionSource The permission identity of the package that is getting this 80 * document. 81 * @param targetPackageName The name of the package that owns this document. 82 * @param databaseName The databaseName this document resides in. 83 * @param getByDocumentIdRequest The {@link GetByDocumentIdRequest} to retrieve document. 84 * @param userHandle Handle of the calling user. 85 * @param binderCallStartTimeMillis start timestamp of binder call in Millis. 86 * @param isForEnterprise Whether to query the user's enterprise profile AppSearch instance 87 */ 88 @Constructor GetDocumentsAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String targetPackageName, @Param(id = 3) @NonNull String databaseName, @Param(id = 4) @NonNull GetByDocumentIdRequest getByDocumentIdRequest, @Param(id = 5) @NonNull UserHandle userHandle, @Param(id = 6) long binderCallStartTimeMillis, @Param(id = 7) boolean isForEnterprise)89 public GetDocumentsAidlRequest( 90 @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource, 91 @Param(id = 2) @NonNull String targetPackageName, 92 @Param(id = 3) @NonNull String databaseName, 93 @Param(id = 4) @NonNull GetByDocumentIdRequest getByDocumentIdRequest, 94 @Param(id = 5) @NonNull UserHandle userHandle, 95 @Param(id = 6) long binderCallStartTimeMillis, 96 @Param(id = 7) boolean isForEnterprise) { 97 mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource); 98 mTargetPackageName = Objects.requireNonNull(targetPackageName); 99 mDatabaseName = Objects.requireNonNull(databaseName); 100 mGetByDocumentIdRequest = Objects.requireNonNull(getByDocumentIdRequest); 101 mUserHandle = Objects.requireNonNull(userHandle); 102 mBinderCallStartTimeMillis = binderCallStartTimeMillis; 103 mIsForEnterprise = isForEnterprise; 104 } 105 106 @NonNull getCallerAttributionSource()107 public AppSearchAttributionSource getCallerAttributionSource() { 108 return mCallerAttributionSource; 109 } 110 111 @NonNull getTargetPackageName()112 public String getTargetPackageName() { 113 return mTargetPackageName; 114 } 115 116 @NonNull getDatabaseName()117 public String getDatabaseName() { 118 return mDatabaseName; 119 } 120 121 @NonNull getGetByDocumentIdRequest()122 public GetByDocumentIdRequest getGetByDocumentIdRequest() { 123 return mGetByDocumentIdRequest; 124 } 125 126 @NonNull getUserHandle()127 public UserHandle getUserHandle() { 128 return mUserHandle; 129 } 130 131 @ElapsedRealtimeLong getBinderCallStartTimeMillis()132 public long getBinderCallStartTimeMillis() { 133 return mBinderCallStartTimeMillis; 134 } 135 isForEnterprise()136 public boolean isForEnterprise() { 137 return mIsForEnterprise; 138 } 139 140 @Override writeToParcel(@onNull Parcel dest, int flags)141 public void writeToParcel(@NonNull Parcel dest, int flags) { 142 GetDocumentsAidlRequestCreator.writeToParcel(this, dest, flags); 143 } 144 } 145