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 com.android.ondevicepersonalization.libraries.plugin;
18 
19 import android.os.Bundle;
20 
21 import org.checkerframework.checker.nullness.qual.Nullable;
22 
23 /** Interface of a Plugin to be executed in an {@link ExecutionEnvironment} */
24 public interface Plugin {
25     /**
26      * Process a request in an {@link ExecutionEnvironment} (for example a sandbox process) and
27      * reply via callback.
28      *
29      * @param input A {@link Bundle} containing data from external apps as the input to
30      *     the plugin code
31      * @param callback to reply with resulting data in {@link Bundle} or an error in
32      *     {@link PluginCallback.FailureType} back, see also
33      *     the contract {@link PluginCallback}
34      * @param context data a plugin needs in order to run
35      */
onExecute( Bundle input, PluginCallback callback, @Nullable PluginContext context)36     void onExecute(
37             Bundle input, PluginCallback callback, @Nullable PluginContext context);
38 
39     /**
40      * Set the class loader that that plugin would use to load child classes.
41      *
42      * @param classLoader A {@link ClassLoader} to be used to load child classes.
43      */
setClassLoader(ClassLoader classLoader)44     default void setClassLoader(ClassLoader classLoader) {}
45 }
46