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