Home | History | Annotate | Download | only in plugins
      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     <T extends Plugin> T getOneShotPlugin(Class<T> cls);
     29     <T extends Plugin> T getOneShotPlugin(String action, Class<?> cls);
     30 
     31     <T extends Plugin> void addPluginListener(PluginListener<T> listener, Class<?> cls);
     32     <T extends Plugin> void addPluginListener(PluginListener<T> listener, Class<?> cls,
     33             boolean allowMultiple);
     34     <T extends Plugin> void addPluginListener(String action, PluginListener<T> listener,
     35             Class<?> cls);
     36     <T extends Plugin> void addPluginListener(String action, PluginListener<T> listener,
     37             Class cls, boolean allowMultiple);
     38 
     39     void removePluginListener(PluginListener<?> listener);
     40 
     41     <T> boolean dependsOn(Plugin p, Class<T> cls);
     42 
     43     static <P> String getAction(Class<P> cls) {
     44         ProvidesInterface info = cls.getDeclaredAnnotation(ProvidesInterface.class);
     45         if (info == null) {
     46             throw new RuntimeException(cls + " doesn't provide an interface");
     47         }
     48         if (TextUtils.isEmpty(info.action())) {
     49             throw new RuntimeException(cls + " doesn't provide an action");
     50         }
     51         return info.action();
     52     }
     53 }
     54