• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.appsetid;
18 
19 import static android.adservices.common.AdServicesStatusUtils.STATUS_SUCCESS;
20 
21 import android.adservices.AdServicesFrameworkHelper;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.SdkConstant;
25 import android.annotation.SystemApi;
26 import android.app.Service;
27 import android.content.Intent;
28 import android.os.IBinder;
29 import android.os.RemoteException;
30 
31 import java.io.IOException;
32 
33 /**
34  * Abstract Base class for provider service to implement generation of AppSetId with appropriate
35  * appSetId scope value.
36  *
37  * <p>The implementor of this service needs to override the onGetAppSetIdProvider method and provide
38  * an app-scoped or developer-account scoped unique appSetId.
39  *
40  * @hide
41  */
42 @SystemApi
43 public abstract class AppSetIdProviderService extends Service {
44 
45     /** The intent that the service must respond to. Add it to the intent filter of the service. */
46     @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
47     public static final String SERVICE_INTERFACE =
48             "android.adservices.appsetid.AppSetIdProviderService";
49 
50     /** Abstract method which will be overridden by provider to provide the appsetid. */
51     @NonNull
onGetAppSetId(int clientUid, @NonNull String clientPackageName)52     public abstract AppSetId onGetAppSetId(int clientUid, @NonNull String clientPackageName)
53             throws IOException;
54 
55     private final android.adservices.appsetid.IAppSetIdProviderService mInterface =
56             new android.adservices.appsetid.IAppSetIdProviderService.Stub() {
57                 @Override
58                 public void getAppSetId(
59                         int appUID,
60                         @NonNull String packageName,
61                         @NonNull IGetAppSetIdProviderCallback resultCallback)
62                         throws RemoteException {
63                     try {
64                         AppSetId appsetId = onGetAppSetId(appUID, packageName);
65                         GetAppSetIdResult appsetIdInternal =
66                                 new GetAppSetIdResult.Builder()
67                                         .setStatusCode(STATUS_SUCCESS)
68                                         .setErrorMessage("")
69                                         .setAppSetId(appsetId.getId())
70                                         .setAppSetIdScope(appsetId.getScope())
71                                         .build();
72 
73                         resultCallback.onResult(appsetIdInternal);
74                     } catch (Throwable e) {
75                         resultCallback.onError(
76                                 AdServicesFrameworkHelper.getExceptionStackTraceString(e));
77                     }
78                 }
79             };
80 
81     @Nullable
82     @Override
onBind(@ullable Intent intent)83     public final IBinder onBind(@Nullable Intent intent) {
84         return mInterface.asBinder();
85     }
86 }
87