• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Context;
18 
19 import java.util.Map;
20 import java.util.function.Consumer;
21 import 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  */
27 public interface ExtensionController {
28 
newExtension(Class<T> cls)29     <T> ExtensionBuilder<T> newExtension(Class<T> cls);
30 
31     interface Extension<T> {
get()32         T get();
getContext()33         Context getContext();
destroy()34         void destroy();
addCallback(Consumer<T> callback)35         void addCallback(Consumer<T> callback);
36         /**
37          * Triggers the extension to cycle through each of the sources again because something
38          * (like configuration) may have changed.
39          */
reload()40         T reload();
41 
42         /**
43          * Null out the cached item for the purpose of memory saving, should only be done
44          * when any other references are already gotten.
45          * @param isDestroyed
46          */
clearItem(boolean isDestroyed)47         void clearItem(boolean isDestroyed);
48     }
49 
50     interface ExtensionBuilder<T> {
withTunerFactory(TunerFactory<T> factory)51         ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory);
withPlugin(Class<P> cls)52         <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls);
withPlugin(Class<P> cls, String action)53         <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action);
withPlugin(Class<P> cls, String action, PluginConverter<T, P> converter)54         <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action,
55                 PluginConverter<T, P> converter);
withDefault(Supplier<T> def)56         ExtensionBuilder<T> withDefault(Supplier<T> def);
withCallback(Consumer<T> callback)57         ExtensionBuilder<T> withCallback(Consumer<T> callback);
withUiMode(int mode, Supplier<T> def)58         ExtensionBuilder<T> withUiMode(int mode, Supplier<T> def);
withFeature(String feature, Supplier<T> def)59         ExtensionBuilder<T> withFeature(String feature, Supplier<T> def);
build()60         Extension build();
61     }
62 
63     public interface PluginConverter<T, P> {
getInterfaceFromPlugin(P plugin)64         T getInterfaceFromPlugin(P plugin);
65     }
66 
67     public interface TunerFactory<T> {
keys()68         String[] keys();
create(Map<String, String> settings)69         T create(Map<String, String> settings);
70     }
71 }
72