• 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.ondevicepersonalization;
18 
19 import android.annotation.NonNull;
20 
21 import java.util.function.Consumer;
22 
23 /**
24  * Interface for services that perform personalized computation using user data.
25  * @hide
26  */
27 public interface IsolatedComputationHandler {
28 
29     /**
30      * Handle a request from an app. A {@link IsolatedComputationService} that
31      * processes requests from apps must override this method.
32      *
33      * @param input App Request Parameters.
34      * @param odpContext The per-request state for this request.
35      * @param consumer Callback to be invoked on completion.
36      */
onExecute( @onNull ExecuteInput input, @NonNull OnDevicePersonalizationContext odpContext, @NonNull Consumer<ExecuteOutput> consumer )37     default void onExecute(
38             @NonNull ExecuteInput input,
39             @NonNull OnDevicePersonalizationContext odpContext,
40             @NonNull Consumer<ExecuteOutput> consumer
41     ) {
42         consumer.accept(null);
43     }
44 
45     /**
46      * Handle a completed download. The platform downloads content using the
47      * parameters defined in the package manifest of the {@link IsolatedComputationService}
48      * and calls this function after the download is complete.
49      *
50      * @param input Download handler parameters.
51      * @param odpContext The per-request state for this request.
52      * @param consumer Callback to be invoked on completion.
53      */
onDownload( @onNull DownloadInput input, @NonNull OnDevicePersonalizationContext odpContext, @NonNull Consumer<DownloadOutput> consumer )54     default void onDownload(
55             @NonNull DownloadInput input,
56             @NonNull OnDevicePersonalizationContext odpContext,
57             @NonNull Consumer<DownloadOutput> consumer
58     ) {
59         consumer.accept(null);
60     }
61 
62     /**
63      * Generate HTML for the winning bids that returned as a result of {@link execute}.
64      * The platform will render this HTML in a WebView inside a fenced frame.
65      *
66      * @param input Parameters for the renderContent request.
67      * @param odpContext The per-request state for this request.
68      * @param consumer Callback to be invoked on completion.
69      */
onRender( @onNull RenderInput input, @NonNull OnDevicePersonalizationContext odpContext, @NonNull Consumer<RenderOutput> consumer )70     default void onRender(
71             @NonNull RenderInput input,
72             @NonNull OnDevicePersonalizationContext odpContext,
73             @NonNull Consumer<RenderOutput> consumer
74     ) {
75         consumer.accept(null);
76     }
77 
78     /**
79      * Compute a list of metrics to be logged in the events table with this event.
80      *
81      * @param input The query-time data required to compute the event metrics.
82      * @param odpContext The per-request state for this request.
83      * @param consumer Callback to be invoked on completion.
84      */
85     // TODO(b/259950177): Also provide the Query event from the Query table.
onEvent( @onNull EventInput input, @NonNull OnDevicePersonalizationContext odpContext, @NonNull Consumer<EventOutput> consumer )86     default void onEvent(
87             @NonNull EventInput input,
88             @NonNull OnDevicePersonalizationContext odpContext,
89             @NonNull Consumer<EventOutput> consumer
90     ) {
91         consumer.accept(null);
92     }
93 }
94