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.observer.ObserverSpec;
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 add an observer monitor changes in the database.
32  *
33  * @hide
34  */
35 @SafeParcelable.Class(creator = "RegisterObserverCallbackAidlRequestCreator")
36 public class RegisterObserverCallbackAidlRequest extends AbstractSafeParcelable {
37     @NonNull
38     public static final Parcelable.Creator<RegisterObserverCallbackAidlRequest> CREATOR =
39             new RegisterObserverCallbackAidlRequestCreator();
40 
41     @NonNull
42     @Field(id = 1, getter = "getCallerAttributionSource")
43     private final AppSearchAttributionSource mCallerAttributionSource;
44 
45     @NonNull
46     @Field(id = 2, getter = "getTargetPackageName")
47     private final String mTargetPackageName;
48 
49     @NonNull
50     @Field(id = 3, getter = "getObserverSpec")
51     private final ObserverSpec mObserverSpec;
52 
53     @NonNull
54     @Field(id = 4, getter = "getUserHandle")
55     private final UserHandle mUserHandle;
56 
57     @Field(id = 5, getter = "getBinderCallStartTimeMillis")
58     @ElapsedRealtimeLong
59     private final long mBinderCallStartTimeMillis;
60 
61     /**
62      * Creates and initializes AppSearchImpl for the calling app.
63      *
64      * @param callerAttributionSource The permission identity of the package which is registering an
65      *     observer.
66      * @param targetPackageName Package whose changes to monitor
67      * @param observerSpec ObserverSpec showing what types of changes to listen for
68      * @param userHandle Handle of the calling user
69      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
70      */
71     @Constructor
RegisterObserverCallbackAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String targetPackageName, @Param(id = 3) @NonNull ObserverSpec observerSpec, @Param(id = 4) @NonNull UserHandle userHandle, @Param(id = 5) @ElapsedRealtimeLong long binderCallStartTimeMillis)72     public RegisterObserverCallbackAidlRequest(
73             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
74             @Param(id = 2) @NonNull String targetPackageName,
75             @Param(id = 3) @NonNull ObserverSpec observerSpec,
76             @Param(id = 4) @NonNull UserHandle userHandle,
77             @Param(id = 5) @ElapsedRealtimeLong long binderCallStartTimeMillis) {
78         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
79         mTargetPackageName = Objects.requireNonNull(targetPackageName);
80         mObserverSpec = Objects.requireNonNull(observerSpec);
81         mUserHandle = Objects.requireNonNull(userHandle);
82         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
83     }
84 
85     @NonNull
getCallerAttributionSource()86     public AppSearchAttributionSource getCallerAttributionSource() {
87         return mCallerAttributionSource;
88     }
89 
90     @NonNull
getTargetPackageName()91     public String getTargetPackageName() {
92         return mTargetPackageName;
93     }
94 
95     @NonNull
getObserverSpec()96     public ObserverSpec getObserverSpec() {
97         return mObserverSpec;
98     }
99 
100     @NonNull
getUserHandle()101     public UserHandle getUserHandle() {
102         return mUserHandle;
103     }
104 
105     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()106     public long getBinderCallStartTimeMillis() {
107         return mBinderCallStartTimeMillis;
108     }
109 
110     @Override
writeToParcel(@onNull Parcel dest, int flags)111     public void writeToParcel(@NonNull Parcel dest, int flags) {
112         RegisterObserverCallbackAidlRequestCreator.writeToParcel(this, dest, flags);
113     }
114 }
115