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.ondeviceintelligence; 18 19 import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE; 20 21 import android.annotation.FlaggedApi; 22 import android.annotation.NonNull; 23 import android.annotation.SystemApi; 24 import android.os.Bundle; 25 import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams; 26 import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.ResponseParams; 27 28 import java.util.function.Consumer; 29 30 /** 31 * Callback to populate the processed response or any error that occurred during the 32 * request processing. This callback also provides a method to request additional data to be 33 * augmented to the request-processing, using the partial response that was already 34 * processed in the remote implementation. 35 * 36 * @hide 37 */ 38 @SystemApi 39 @FlaggedApi(FLAG_ENABLE_ON_DEVICE_INTELLIGENCE) 40 public interface ProcessingCallback { 41 /** 42 * Invoked when request has been processed and result is ready to be propagated to the 43 * caller. 44 * 45 * @param result Response to be passed as a result. 46 */ onResult(@onNull @esponseParams Bundle result)47 void onResult(@NonNull @ResponseParams Bundle result); 48 49 /** 50 * Called when the request processing fails. The failure details are indicated by the 51 * {@link OnDeviceIntelligenceException} passed as an argument to this method. 52 * 53 * @param error An exception with more details about the error that occurred. 54 */ onError(@onNull OnDeviceIntelligenceException error)55 void onError(@NonNull OnDeviceIntelligenceException error); 56 57 /** 58 * Callback to be invoked in cases where the remote service needs to perform retrieval or 59 * transformation operations based on a partially processed request, in order to augment the 60 * final response, by using the additional context sent via this callback. 61 * 62 * @param processedContent The content payload that should be used to augment ongoing request. 63 * @param contentConsumer The augmentation data that should be sent to remote 64 * service for further processing a request. Bundle passed in here is 65 * expected to be non-null or EMPTY when there is no response. 66 */ onDataAugmentRequest( @onNull @esponseParams Bundle processedContent, @NonNull Consumer<@InferenceParams Bundle> contentConsumer)67 default void onDataAugmentRequest( 68 @NonNull @ResponseParams Bundle processedContent, 69 @NonNull Consumer<@InferenceParams Bundle> contentConsumer) { 70 contentConsumer.accept(Bundle.EMPTY); 71 } 72 } 73