ExtensionController.java revision 769139da0397c5b2abf0f6d5fbcf3e2bd33276db
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 * Triggers the extension to cycle through each of the sources again because something 38 * (like configuration) may have changed. 39 */ 40 T reload(); 41 } 42 43 interface ExtensionBuilder<T> { 44 ExtensionBuilder<T> withTunerFactory(TunerFactory<T> factory); 45 <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls); 46 <P extends T> ExtensionBuilder<T> withPlugin(Class<P> cls, String action); 47 <P> ExtensionBuilder<T> withPlugin(Class<P> cls, String action, 48 PluginConverter<T, P> converter); 49 ExtensionBuilder<T> withDefault(Supplier<T> def); 50 ExtensionBuilder<T> withCallback(Consumer<T> callback); 51 ExtensionBuilder<T> withUiMode(int mode, Supplier<T> def); 52 Extension build(); 53 } 54 55 public interface PluginConverter<T, P> { 56 T getInterfaceFromPlugin(P plugin); 57 } 58 59 public interface TunerFactory<T> { 60 String[] keys(); 61 T create(Map<String, String> settings); 62 } 63} 64