ExtensionController.java revision 0b80c4e518110ba385a1b83d1e29325f164dc90d
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 android.content.Context;
18
19import java.util.Map;
20import java.util.function.Consumer;
21import java.util.function.Supplier;
22
23/**
24 * Utility class used to select between a plugin, tuner settings, and a default implementation
25 * of an interface.
26 */
27public interface ExtensionController {
28
29    <T> ExtensionBuilder<T> newExtension(Class<T> cls);
30
31    interface Extension<T> {
32        T get();
33        Context getContext();
34        void destroy();
35        void addCallback(Consumer<T> callback);
36    }
37
38    interface ExtensionBuilder<T> {
39        ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory);
40        <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls);
41        <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action);
42        <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action,
43                PluginConverter<T, P> converter);
44        ExtensionBuilder<T> withDefault(Supplier<T> def);
45        ExtensionBuilder<T> withCallback(Consumer<T> callback);
46        ExtensionBuilder<T> withUiMode(int mode, Supplier<T> def);
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