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 com.google.common.collect.ImmutableSet; 22 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** 26 * Interface that provides {@link PluginContext} to {@link Plugin} implementation. Typically 27 * implemented by the Sandbox Developer. 28 */ 29 public interface PluginHost { 30 /** 31 * Create Bundle of initialization data used to create the PluginContext. 32 * 33 * <p>This method is called outside the sandbox process. The Bundle is passed over AIDL to the 34 * sandbox service. 35 */ createPluginContextInitData(String pluginId)36 default @Nullable Bundle createPluginContextInitData(String pluginId) { 37 return null; 38 } 39 40 /** 41 * Create {@link PluginContext} data to be used by the {@link Plugin} implementation. 42 * 43 * <p>This method is called inside the sandbox process. The {@link Bundle} returned from 44 * createPluginContextInitData() is passed as the initData argument. The PluginContext is passed 45 * to onExecute(). 46 */ createPluginContext( String pluginId, @Nullable Bundle initData)47 default @Nullable PluginContext createPluginContext( 48 String pluginId, @Nullable Bundle initData) { 49 return null; 50 } 51 52 /** Get set of classes that the sandbox class loader is allowed to load. */ getClassLoaderAllowedClasses(String pluginId)53 default ImmutableSet<String> getClassLoaderAllowedClasses(String pluginId) { 54 return ImmutableSet.of(); 55 } 56 57 /** Get set of packages that the sandbox class loader is allowed to load classes from. */ getClassLoaderAllowedPackages(String pluginId)58 default ImmutableSet<String> getClassLoaderAllowedPackages(String pluginId) { 59 return ImmutableSet.of(); 60 } 61 } 62