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.ObserverCallback;
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 remove a previously registered observer.
32  *
33  * @hide
34  */
35 @SafeParcelable.Class(creator = "UnregisterObserverCallbackAidlRequestCreator")
36 public class UnregisterObserverCallbackAidlRequest extends AbstractSafeParcelable {
37     @NonNull
38     public static final Parcelable.Creator<UnregisterObserverCallbackAidlRequest> CREATOR =
39             new UnregisterObserverCallbackAidlRequestCreator();
40 
41     @NonNull
42     @Field(id = 1, getter = "getCallerAttributionSource")
43     private final AppSearchAttributionSource mCallerAttributionSource;
44 
45     @NonNull
46     @Field(id = 2, getter = "getObservedPackage")
47     private final String mObservedPackage;
48 
49     @NonNull
50     @Field(id = 3, getter = "getUserHandle")
51     private final UserHandle mUserHandle;
52 
53     @Field(id = 4, getter = "getBinderCallStartTimeMillis")
54     @ElapsedRealtimeLong
55     private final long mBinderCallStartTimeMillis;
56 
57     /**
58      * Removes previously registered {@link ObserverCallback} instances from the system.
59      *
60      * @param callerAttributionSource The permission identity of the package that owns the observer
61      * @param observedPackage Package whose changes are being monitored
62      * @param userHandle Handle of the calling user
63      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
64      */
65     @Constructor
UnregisterObserverCallbackAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String observedPackage, @Param(id = 3) @NonNull UserHandle userHandle, @Param(id = 4) @ElapsedRealtimeLong long binderCallStartTimeMillis)66     public UnregisterObserverCallbackAidlRequest(
67             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
68             @Param(id = 2) @NonNull String observedPackage,
69             @Param(id = 3) @NonNull UserHandle userHandle,
70             @Param(id = 4) @ElapsedRealtimeLong long binderCallStartTimeMillis) {
71         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
72         mObservedPackage = Objects.requireNonNull(observedPackage);
73         mUserHandle = Objects.requireNonNull(userHandle);
74         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
75     }
76 
77     @NonNull
getCallerAttributionSource()78     public AppSearchAttributionSource getCallerAttributionSource() {
79         return mCallerAttributionSource;
80     }
81 
82     @NonNull
getObservedPackage()83     public String getObservedPackage() {
84         return mObservedPackage;
85     }
86 
87     @NonNull
getUserHandle()88     public UserHandle getUserHandle() {
89         return mUserHandle;
90     }
91 
92     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()93     public long getBinderCallStartTimeMillis() {
94         return mBinderCallStartTimeMillis;
95     }
96 
97     @Override
writeToParcel(@onNull Parcel dest, int flags)98     public void writeToParcel(@NonNull Parcel dest, int flags) {
99         UnregisterObserverCallbackAidlRequestCreator.writeToParcel(this, dest, flags);
100     }
101 }
102