• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.extdata;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.SdkConstant;
24 import android.annotation.SystemApi;
25 import android.app.Service;
26 import android.content.Intent;
27 import android.os.IBinder;
28 import android.os.RemoteException;
29 
30 import com.android.adservices.flags.Flags;
31 
32 import java.lang.annotation.Retention;
33 import java.lang.annotation.RetentionPolicy;
34 import java.util.Objects;
35 
36 /**
37  * Abstract base class to implement AdServicesExtDataStorageService.
38  *
39  * <p>The implementor of this service needs to override the onGetAdServicesExtData and
40  * onPutAdServicesExtData methods
41  *
42  * @hide
43  */
44 @SystemApi
45 @FlaggedApi(Flags.FLAG_ADEXT_DATA_SERVICE_APIS_ENABLED)
46 public abstract class AdServicesExtDataStorageService extends Service {
47     /**
48      * Supported data field IDs.
49      *
50      * @hide
51      */
52     @Retention(RetentionPolicy.SOURCE)
53     @IntDef(
54             prefix = "FIELD_",
55             value = {
56                 FIELD_IS_NOTIFICATION_DISPLAYED,
57                 FIELD_IS_MEASUREMENT_CONSENTED,
58                 FIELD_IS_U18_ACCOUNT,
59                 FIELD_IS_ADULT_ACCOUNT,
60                 FIELD_MANUAL_INTERACTION_WITH_CONSENT_STATUS,
61                 FIELD_MEASUREMENT_ROLLBACK_APEX_VERSION,
62             })
63     public @interface AdServicesExtDataFieldId {}
64 
65     /** Field to represent whether AdServices consent notification has been shown on Android R. */
66     public static final int FIELD_IS_NOTIFICATION_DISPLAYED = 0;
67 
68     /** Field to represent whether user provided consent for Measurement API. */
69     public static final int FIELD_IS_MEASUREMENT_CONSENTED = 1;
70 
71     /** Field to represent whether account is U18. */
72     public static final int FIELD_IS_U18_ACCOUNT = 2;
73 
74     /** Field to represent whether it's an adult account. */
75     public static final int FIELD_IS_ADULT_ACCOUNT = 3;
76 
77     /** Field to represent whether user manually interacted with consent */
78     public static final int FIELD_MANUAL_INTERACTION_WITH_CONSENT_STATUS = 4;
79 
80     /** Field to represent ExtServices apex version for measurement rollback handling. */
81     public static final int FIELD_MEASUREMENT_ROLLBACK_APEX_VERSION = 5;
82 
83     /** The intent that the service must respond to. Add it to the intent filter of the service. */
84     @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
85     public static final String SERVICE_INTERFACE =
86             "android.adservices.extdata.AdServicesExtDataStorageService";
87 
AdServicesExtDataStorageService()88     public AdServicesExtDataStorageService() {}
89 
90     @Nullable
91     @Override
onBind(@ullable Intent intent)92     public final IBinder onBind(@Nullable Intent intent) {
93         return mInterface.asBinder();
94     }
95 
96     /** Abstract onGetAdServicesExtData method to get all stored ext data values from data store. */
97     @NonNull
onGetAdServicesExtData()98     public abstract AdServicesExtDataParams onGetAdServicesExtData();
99 
100     /**
101      * Abstract onPutAdServicesExtData method to update values of fields in data store.
102      *
103      * @param adServicesExtDataParams data object that stores fields to be updated.
104      * @param adServicesExtDataFields explicit list of fields that need to be updated in data store.
105      */
onPutAdServicesExtData( @onNull AdServicesExtDataParams adServicesExtDataParams, @NonNull @AdServicesExtDataFieldId int[] adServicesExtDataFields)106     public abstract void onPutAdServicesExtData(
107             @NonNull AdServicesExtDataParams adServicesExtDataParams,
108             @NonNull @AdServicesExtDataFieldId int[] adServicesExtDataFields);
109 
110     private final IAdServicesExtDataStorageService mInterface =
111             new IAdServicesExtDataStorageService.Stub() {
112 
113                 @Override
114                 public void getAdServicesExtData(@NonNull IGetAdServicesExtDataCallback callback)
115                         throws RemoteException {
116                     Objects.requireNonNull(callback);
117                     callback.onError("AdServicesExtDataStorageService is not implemented.");
118                 }
119 
120                 @Override
121                 public void putAdServicesExtData(
122                         @NonNull AdServicesExtDataParams params,
123                         @NonNull @AdServicesExtDataFieldId int[] adServicesExtDataFields,
124                         @NonNull IGetAdServicesExtDataCallback callback)
125                         throws RemoteException {
126                     Objects.requireNonNull(params);
127                     Objects.requireNonNull(adServicesExtDataFields);
128                     Objects.requireNonNull(callback);
129 
130                     callback.onError("AdServicesExtDataStorageService is not implemented.");
131                 }
132             };
133 }
134