1 /*
2  * Copyright (C) 2022 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.adservices.ondevicepersonalization;
18 
19 import android.adservices.ondevicepersonalization.aidl.IDataAccessService;
20 import android.adservices.ondevicepersonalization.aidl.IFederatedComputeService;
21 import android.adservices.ondevicepersonalization.aidl.IIsolatedModelService;
22 import android.annotation.FlaggedApi;
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.os.SystemClock;
26 
27 import com.android.adservices.ondevicepersonalization.flags.Flags;
28 
29 import java.util.Objects;
30 
31 /**
32  * An opaque token that identifies the current request to an {@link IsolatedService}. This token
33  * must be passed as a parameter to all service methods that depend on per-request state.
34  */
35 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
36 public class RequestToken {
37     @NonNull
38     private final IDataAccessService mDataAccessService;
39 
40     @Nullable
41     private final IFederatedComputeService mFcService;
42 
43     @Nullable private final IIsolatedModelService mModelService;
44 
45     @Nullable
46     private final UserData mUserData;
47 
48     private final long mStartTimeMillis;
49 
50     /** @hide */
RequestToken( @onNull IDataAccessService binder, @Nullable IFederatedComputeService fcServiceBinder, @Nullable IIsolatedModelService modelServiceBinder, @Nullable UserData userData)51     RequestToken(
52             @NonNull IDataAccessService binder,
53             @Nullable IFederatedComputeService fcServiceBinder,
54             @Nullable IIsolatedModelService modelServiceBinder,
55             @Nullable UserData userData) {
56         mDataAccessService = Objects.requireNonNull(binder);
57         mFcService = fcServiceBinder;
58         mModelService = modelServiceBinder;
59         mUserData = userData;
60         mStartTimeMillis = SystemClock.elapsedRealtime();
61     }
62 
63     /** @hide */
64     @NonNull
getDataAccessService()65     IDataAccessService getDataAccessService() {
66         return mDataAccessService;
67     }
68 
69     /** @hide */
70     @Nullable
getFederatedComputeService()71     IFederatedComputeService getFederatedComputeService() {
72         return mFcService;
73     }
74 
75     /** @hide */
76     @Nullable
getModelService()77     IIsolatedModelService getModelService() {
78         return mModelService;
79     }
80 
81     /** @hide */
82     @Nullable
getUserData()83     UserData getUserData() {
84         return mUserData;
85     }
86 
87     /** @hide */
getStartTimeMillis()88     long getStartTimeMillis() {
89         return mStartTimeMillis;
90     }
91 }
92