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.cobalt; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SdkConstant; 22 import android.annotation.SystemApi; 23 import android.app.Service; 24 import android.content.Intent; 25 import android.os.IBinder; 26 27 /** 28 * Abstract Base class for provider service to implement uploading of data to Cobalt's backend. 29 * 30 * <p>The implementor of this service needs to override the onUploadEncryptedCobaltEnvelope method. 31 * 32 * <p>Cobalt is a telemetry system with built-in support for differential privacy. See 33 * https://fuchsia.googlesource.com/cobalt for a comprehensive overview of the project and the 34 * Fuchsia client implementation. 35 * 36 * @hide 37 */ 38 @SystemApi 39 public abstract class AdServicesCobaltUploadService extends Service { 40 /** The intent that the service must respond to. Add it to the intent filter of the service. */ 41 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) 42 public static final String SERVICE_INTERFACE = 43 "android.adservices.cobalt.AdServicesCobaltUploadService"; 44 45 /** Abstract method which will be overridden by the sender to upload the data */ onUploadEncryptedCobaltEnvelope( @onNull EncryptedCobaltEnvelopeParams params)46 public abstract void onUploadEncryptedCobaltEnvelope( 47 @NonNull EncryptedCobaltEnvelopeParams params); 48 49 private final IAdServicesCobaltUploadService mInterface = 50 new IAdServicesCobaltUploadService.Stub() { 51 /** 52 * Send an encrypted envelope to Cobalt's backend. 53 * 54 * <p>Errors in this method execution, both because of problems within the binder 55 * call and in the service execution, will cause a RuntimeException to be thrown. 56 */ 57 @Override 58 public void uploadEncryptedCobaltEnvelope(EncryptedCobaltEnvelopeParams params) { 59 onUploadEncryptedCobaltEnvelope(params); 60 } 61 }; 62 63 @Nullable 64 @Override onBind(@ullable Intent intent)65 public final IBinder onBind(@Nullable Intent intent) { 66 return mInterface.asBinder(); 67 } 68 } 69