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.AppSearchSchema; 22 import android.app.appsearch.AppSearchSession; 23 import android.app.appsearch.InternalVisibilityConfig; 24 import android.app.appsearch.safeparcel.AbstractSafeParcelable; 25 import android.app.appsearch.safeparcel.SafeParcelable; 26 import android.os.Parcel; 27 import android.os.Parcelable; 28 import android.os.UserHandle; 29 30 import java.util.List; 31 import java.util.Objects; 32 33 /** 34 * Encapsulates a request to make a binder call to update the schema of an {@link AppSearchSession} 35 * database. 36 * 37 * @hide 38 */ 39 @SafeParcelable.Class(creator = "SetSchemaAidlRequestCreator") 40 public final class SetSchemaAidlRequest extends AbstractSafeParcelable { 41 @NonNull 42 public static final Parcelable.Creator<SetSchemaAidlRequest> CREATOR = 43 new SetSchemaAidlRequestCreator(); 44 45 @NonNull 46 @Field(id = 1, getter = "getCallerAttributionSource") 47 private final AppSearchAttributionSource mCallerAttributionSource; 48 49 @NonNull 50 @Field(id = 2, getter = "getDatabaseName") 51 private final String mDatabaseName; 52 53 @NonNull 54 @Field(id = 3, getter = "getSchemas") 55 private final List<AppSearchSchema> mSchemas; 56 57 @NonNull 58 @Field(id = 4, getter = "getVisibilityConfigs") 59 private final List<InternalVisibilityConfig> mVisibilityConfigs; 60 61 @Field(id = 5, getter = "isForceOverride") 62 private final boolean mForceOverride; 63 64 @Field(id = 6, getter = "getSchemaVersion") 65 private final int mSchemaVersion; 66 67 @NonNull 68 @Field(id = 7, getter = "getUserHandle") 69 private final UserHandle mUserHandle; 70 71 @Field(id = 8, getter = "getBinderCallStartTimeMillis") 72 @ElapsedRealtimeLong 73 private final long mBinderCallStartTimeMillis; 74 75 @Field(id = 9, getter = "getSchemaMigrationCallType") 76 private final int mSchemaMigrationCallType; 77 78 /** 79 * Updates the AppSearch schema for this database. 80 * 81 * @param callerAttributionSource The permission identity of the package that owns this schema. 82 * @param databaseName The name of the database where this schema lives. 83 * @param schemas List of {@link AppSearchSchema} objects. 84 * @param visibilityConfigs List of {@link InternalVisibilityConfig} objects defining the 85 * visibility for the schema types. 86 * @param forceOverride Whether to apply the new schema even if it is incompatible. All 87 * incompatible documents will be deleted. 88 * @param schemaVersion The overall schema version number of the request. 89 * @param userHandle Handle of the calling user 90 * @param binderCallStartTimeMillis start timestamp of binder call in Millis 91 * @param schemaMigrationCallType Indicates how a SetSchema call relative to SchemaMigration 92 * case. 93 */ 94 @Constructor SetSchemaAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String databaseName, @Param(id = 3) @NonNull List<AppSearchSchema> schemas, @Param(id = 4) @NonNull List<InternalVisibilityConfig> visibilityConfigs, @Param(id = 5) boolean forceOverride, @Param(id = 6) int schemaVersion, @Param(id = 7) @NonNull UserHandle userHandle, @Param(id = 8) @ElapsedRealtimeLong long binderCallStartTimeMillis, @Param(id = 9) int schemaMigrationCallType)95 public SetSchemaAidlRequest( 96 @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource, 97 @Param(id = 2) @NonNull String databaseName, 98 @Param(id = 3) @NonNull List<AppSearchSchema> schemas, 99 @Param(id = 4) @NonNull List<InternalVisibilityConfig> visibilityConfigs, 100 @Param(id = 5) boolean forceOverride, 101 @Param(id = 6) int schemaVersion, 102 @Param(id = 7) @NonNull UserHandle userHandle, 103 @Param(id = 8) @ElapsedRealtimeLong long binderCallStartTimeMillis, 104 @Param(id = 9) int schemaMigrationCallType) { 105 mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource); 106 mDatabaseName = Objects.requireNonNull(databaseName); 107 mSchemas = Objects.requireNonNull(schemas); 108 mVisibilityConfigs = Objects.requireNonNull(visibilityConfigs); 109 mForceOverride = forceOverride; 110 mSchemaVersion = schemaVersion; 111 mUserHandle = Objects.requireNonNull(userHandle); 112 mBinderCallStartTimeMillis = binderCallStartTimeMillis; 113 mSchemaMigrationCallType = schemaMigrationCallType; 114 } 115 116 @NonNull getCallerAttributionSource()117 public AppSearchAttributionSource getCallerAttributionSource() { 118 return mCallerAttributionSource; 119 } 120 121 @NonNull getDatabaseName()122 public String getDatabaseName() { 123 return mDatabaseName; 124 } 125 126 @NonNull getSchemas()127 public List<AppSearchSchema> getSchemas() { 128 return mSchemas; 129 } 130 131 @NonNull getVisibilityConfigs()132 public List<InternalVisibilityConfig> getVisibilityConfigs() { 133 return mVisibilityConfigs; 134 } 135 isForceOverride()136 public boolean isForceOverride() { 137 return mForceOverride; 138 } 139 getSchemaVersion()140 public int getSchemaVersion() { 141 return mSchemaVersion; 142 } 143 144 @NonNull getUserHandle()145 public UserHandle getUserHandle() { 146 return mUserHandle; 147 } 148 149 @ElapsedRealtimeLong getBinderCallStartTimeMillis()150 public long getBinderCallStartTimeMillis() { 151 return mBinderCallStartTimeMillis; 152 } 153 getSchemaMigrationCallType()154 public int getSchemaMigrationCallType() { 155 return mSchemaMigrationCallType; 156 } 157 158 @Override writeToParcel(@onNull Parcel dest, int flags)159 public void writeToParcel(@NonNull Parcel dest, int flags) { 160 SetSchemaAidlRequestCreator.writeToParcel(this, dest, flags); 161 } 162 } 163