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
15package com.android.systemui.statusbar.policy;
16
17import java.util.Map;
18import java.util.function.Consumer;
19import 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 */
25public interface ExtensionController {
26
27    <T> ExtensionBuilder<T> newExtension(Class<T> cls);
28
29    interface Extension<T> {
30        T get();
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         */
36        T reload();
37    }
38
39    interface ExtensionBuilder<T> {
40        ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory);
41        <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls);
42        <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action);
43        <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action,
44                PluginConverter<T, P> converter);
45        ExtensionBuilder<T> withDefault(Supplier<T> def);
46        ExtensionBuilder<T> withCallback(Consumer<T> callback);
47        Extension build();
48    }
49
50    public interface PluginConverter<T, P> {
51        T getInterfaceFromPlugin(P plugin);
52    }
53
54    public interface TunerFactory<T> {
55        String[] keys();
56        T create(Map<String, String> settings);
57    }
58}
59