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.shared.plugins; 16 17 import android.text.TextUtils; 18 19 import com.android.systemui.plugins.Plugin; 20 import com.android.systemui.plugins.PluginListener; 21 import com.android.systemui.plugins.annotations.ProvidesInterface; 22 23 public interface PluginManager { 24 25 String PLUGIN_CHANGED = "com.android.systemui.action.PLUGIN_CHANGED"; 26 27 // must be one of the channels created in NotificationChannels.java 28 String NOTIFICATION_CHANNEL_ID = "ALR"; 29 getWhitelistedPlugins()30 String[] getWhitelistedPlugins(); 31 getOneShotPlugin(Class<T> cls)32 <T extends Plugin> T getOneShotPlugin(Class<T> cls); getOneShotPlugin(String action, Class<?> cls)33 <T extends Plugin> T getOneShotPlugin(String action, Class<?> cls); 34 addPluginListener(PluginListener<T> listener, Class<?> cls)35 <T extends Plugin> void addPluginListener(PluginListener<T> listener, Class<?> cls); addPluginListener(PluginListener<T> listener, Class<?> cls, boolean allowMultiple)36 <T extends Plugin> void addPluginListener(PluginListener<T> listener, Class<?> cls, 37 boolean allowMultiple); addPluginListener(String action, PluginListener<T> listener, Class<?> cls)38 <T extends Plugin> void addPluginListener(String action, PluginListener<T> listener, 39 Class<?> cls); addPluginListener(String action, PluginListener<T> listener, Class cls, boolean allowMultiple)40 <T extends Plugin> void addPluginListener(String action, PluginListener<T> listener, 41 Class cls, boolean allowMultiple); 42 removePluginListener(PluginListener<?> listener)43 void removePluginListener(PluginListener<?> listener); 44 dependsOn(Plugin p, Class<T> cls)45 <T> boolean dependsOn(Plugin p, Class<T> cls); 46 47 class Helper { getAction(Class<P> cls)48 public static <P> String getAction(Class<P> cls) { 49 ProvidesInterface info = cls.getDeclaredAnnotation(ProvidesInterface.class); 50 if (info == null) { 51 throw new RuntimeException(cls + " doesn't provide an interface"); 52 } 53 if (TextUtils.isEmpty(info.action())) { 54 throw new RuntimeException(cls + " doesn't provide an action"); 55 } 56 return info.action(); 57 } 58 } 59 60 } 61