1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.systemui.statusbar.policy;
16 
17 import java.util.Map;
18 import java.util.function.Consumer;
19 import java.util.function.Supplier;
20 
21 /**
22  * Utility class used to select between a plugin, tuner settings, and a default implementation
23  * of an interface.
24  */
25 public interface ExtensionController {
26 
newExtension(Class<T> cls)27     <T> ExtensionBuilder<T> newExtension(Class<T> cls);
28 
29     interface Extension<T> {
get()30         T get();
destroy()31         void destroy();
32         /**
33          * Triggers the extension to cycle through each of the sources again because something
34          * (like configuration) may have changed.
35          */
reload()36         T reload();
37     }
38 
39     interface ExtensionBuilder<T> {
withTunerFactory(TunerFactory<T> factory)40         ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory);
withPlugin(Class<P> cls)41         <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls);
withPlugin(Class<P> cls, String action)42         <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action);
withPlugin(Class<P> cls, String action, PluginConverter<T, P> converter)43         <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action,
44                 PluginConverter<T, P> converter);
withDefault(Supplier<T> def)45         ExtensionBuilder<T> withDefault(Supplier<T> def);
withCallback(Consumer<T> callback)46         ExtensionBuilder<T> withCallback(Consumer<T> callback);
build()47         Extension build();
48     }
49 
50     public interface PluginConverter<T, P> {
getInterfaceFromPlugin(P plugin)51         T getInterfaceFromPlugin(P plugin);
52     }
53 
54     public interface TunerFactory<T> {
keys()55         String[] keys();
create(Map<String, String> settings)56         T create(Map<String, String> settings);
57     }
58 }
59