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 com.android.systemui.plugins; 18 19 import android.content.ComponentName; 20 21 import java.util.function.BiConsumer; 22 23 /** 24 * Provides the ability for consumers to control plugin lifecycle. 25 * 26 * @param <T> is the target plugin type 27 */ 28 public interface PluginLifecycleManager<T extends Plugin> { 29 /** Returns the ComponentName of the target plugin. Maybe be called when not loaded. */ getComponentName()30 ComponentName getComponentName(); 31 32 /** Returns the package name of the target plugin. May be called when not loaded. */ getPackage()33 String getPackage(); 34 35 /** Returns the currently loaded plugin instance (if plugin is loaded) */ getPlugin()36 T getPlugin(); 37 38 /** Log tag and messages will be sent to the provided Consumer */ setLogFunc(BiConsumer<String, String> logConsumer)39 void setLogFunc(BiConsumer<String, String> logConsumer); 40 41 /** returns true if the plugin is currently loaded */ isLoaded()42 default boolean isLoaded() { 43 return getPlugin() != null; 44 } 45 46 /** 47 * Loads and creates the plugin instance if it does not exist. 48 * 49 * This will trigger {@link PluginListener#onPluginLoaded} with the new instance if it did not 50 * already exist. 51 */ loadPlugin()52 void loadPlugin(); 53 54 /** 55 * Unloads and destroys the plugin instance if it exists. 56 * 57 * This will trigger {@link PluginListener#onPluginUnloaded} if a concrete plugin instance 58 * existed when this call was made. 59 */ unloadPlugin()60 void unloadPlugin(); 61 } 62