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