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.ReportUsageRequest;
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 reports usage of a particular document.
32  *
33  * @hide
34  */
35 @SafeParcelable.Class(creator = "ReportUsageAidlRequestCreator")
36 public class ReportUsageAidlRequest extends AbstractSafeParcelable {
37     @NonNull
38     public static final Parcelable.Creator<ReportUsageAidlRequest> CREATOR =
39             new ReportUsageAidlRequestCreator();
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 = "getDatabaseName")
51     private final String mDatabaseName;
52 
53     @NonNull
54     @Field(id = 4, getter = "getReportUsageRequest")
55     private final ReportUsageRequest mReportUsageRequest;
56 
57     @Field(id = 5, getter = "isSystemUsage")
58     private final boolean mSystemUsage;
59 
60     @NonNull
61     @Field(id = 6, getter = "getUserHandle")
62     private final UserHandle mUserHandle;
63 
64     @Field(id = 7, getter = "getBinderCallStartTimeMillis")
65     @ElapsedRealtimeLong
66     private final long mBinderCallStartTimeMillis;
67 
68     /**
69      * Reports usage of a particular document by namespace and id.
70      *
71      * @param callerAttributionSource The permission identity of the package that owns this
72      *     document.
73      * @param targetPackageName The name of the package that owns this document.
74      * @param databaseName The name of the database to report usage against.
75      * @param reportUsageRequest The {@link ReportUsageRequest} to report usage for document.
76      * @param systemUsage Whether the usage was reported by a system app against another app's doc.
77      * @param userHandle Handle of the calling user
78      * @param binderCallStartTimeMillis start timestamp of binder call in Millis
79      */
80     @Constructor
ReportUsageAidlRequest( @aramid = 1) @onNull AppSearchAttributionSource callerAttributionSource, @Param(id = 2) @NonNull String targetPackageName, @Param(id = 3) @NonNull String databaseName, @Param(id = 4) @NonNull ReportUsageRequest reportUsageRequest, @Param(id = 5) boolean systemUsage, @Param(id = 6) @NonNull UserHandle userHandle, @Param(id = 7) @ElapsedRealtimeLong long binderCallStartTimeMillis)81     public ReportUsageAidlRequest(
82             @Param(id = 1) @NonNull AppSearchAttributionSource callerAttributionSource,
83             @Param(id = 2) @NonNull String targetPackageName,
84             @Param(id = 3) @NonNull String databaseName,
85             @Param(id = 4) @NonNull ReportUsageRequest reportUsageRequest,
86             @Param(id = 5) boolean systemUsage,
87             @Param(id = 6) @NonNull UserHandle userHandle,
88             @Param(id = 7) @ElapsedRealtimeLong long binderCallStartTimeMillis) {
89         mCallerAttributionSource = Objects.requireNonNull(callerAttributionSource);
90         mTargetPackageName = Objects.requireNonNull(targetPackageName);
91         mDatabaseName = Objects.requireNonNull(databaseName);
92         mReportUsageRequest = Objects.requireNonNull(reportUsageRequest);
93         mSystemUsage = systemUsage;
94         mUserHandle = Objects.requireNonNull(userHandle);
95         mBinderCallStartTimeMillis = binderCallStartTimeMillis;
96     }
97 
98     @NonNull
getCallerAttributionSource()99     public AppSearchAttributionSource getCallerAttributionSource() {
100         return mCallerAttributionSource;
101     }
102 
103     @NonNull
getTargetPackageName()104     public String getTargetPackageName() {
105         return mTargetPackageName;
106     }
107 
108     @NonNull
getDatabaseName()109     public String getDatabaseName() {
110         return mDatabaseName;
111     }
112 
113     @NonNull
getReportUsageRequest()114     public ReportUsageRequest getReportUsageRequest() {
115         return mReportUsageRequest;
116     }
117 
isSystemUsage()118     public boolean isSystemUsage() {
119         return mSystemUsage;
120     }
121 
122     @NonNull
getUserHandle()123     public UserHandle getUserHandle() {
124         return mUserHandle;
125     }
126 
127     @ElapsedRealtimeLong
getBinderCallStartTimeMillis()128     public long getBinderCallStartTimeMillis() {
129         return mBinderCallStartTimeMillis;
130     }
131 
132     @Override
writeToParcel(@onNull Parcel dest, int flags)133     public void writeToParcel(@NonNull Parcel dest, int flags) {
134         ReportUsageAidlRequestCreator.writeToParcel(this, dest, flags);
135     }
136 }
137