• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.plugins;
18 
19 import android.app.PendingIntent;
20 import android.app.smartspace.SmartspaceAction;
21 import android.app.smartspace.SmartspaceTarget;
22 import android.app.smartspace.SmartspaceTargetEvent;
23 import android.app.smartspace.uitemplatedata.TapAction;
24 import android.content.ActivityNotFoundException;
25 import android.content.Intent;
26 import android.graphics.drawable.Drawable;
27 import android.os.Parcelable;
28 import android.util.Log;
29 import android.view.View;
30 import android.view.ViewGroup;
31 
32 import androidx.annotation.Nullable;
33 
34 import com.android.systemui.plugins.annotations.ProvidesInterface;
35 
36 import java.util.List;
37 
38 /**
39  * Interface to provide SmartspaceTargets to BcSmartspace.
40  */
41 @ProvidesInterface(action = BcSmartspaceDataPlugin.ACTION, version = BcSmartspaceDataPlugin.VERSION)
42 public interface BcSmartspaceDataPlugin extends Plugin {
43     String UI_SURFACE_LOCK_SCREEN_AOD = "lockscreen";
44     String UI_SURFACE_HOME_SCREEN = "home";
45     String UI_SURFACE_MEDIA = "media_data_manager";
46     String UI_SURFACE_DREAM = "dream";
47 
48     String ACTION = "com.android.systemui.action.PLUGIN_BC_SMARTSPACE_DATA";
49     int VERSION = 1;
50     String TAG = "BcSmartspaceDataPlugin";
51 
52     /** Register a listener to get Smartspace data. */
registerListener(SmartspaceTargetListener listener)53     default void registerListener(SmartspaceTargetListener listener) {
54         throw new UnsupportedOperationException("Not implemented by " + getClass());
55     }
56 
57     /** Unregister a listener. */
unregisterListener(SmartspaceTargetListener listener)58     default void unregisterListener(SmartspaceTargetListener listener) {
59         throw new UnsupportedOperationException("Not implemented by " + getClass());
60     }
61 
62     /** Register a SmartspaceEventNotifier. */
registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier)63     default void registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier) {
64         throw new UnsupportedOperationException("Not implemented by " + getClass());
65     }
66 
67     /** Push a SmartspaceTargetEvent to the SmartspaceEventNotifier. */
notifySmartspaceEvent(SmartspaceTargetEvent event)68     default void notifySmartspaceEvent(SmartspaceTargetEvent event) {
69         throw new UnsupportedOperationException("Not implemented by " + getClass());
70     }
71 
72     /** Allows for notifying the SmartspaceSession of SmartspaceTargetEvents. */
73     interface SmartspaceEventNotifier {
74         /** Pushes a given SmartspaceTargetEvent to the SmartspaceSession. */
notifySmartspaceEvent(SmartspaceTargetEvent event)75         void notifySmartspaceEvent(SmartspaceTargetEvent event);
76     }
77 
78     /**
79      * Create a view to be shown within the parent. Do not add the view, as the parent
80      * will be responsible for correctly setting the LayoutParams
81      */
getView(ViewGroup parent)82     default SmartspaceView getView(ViewGroup parent) {
83         throw new UnsupportedOperationException("Not implemented by " + getClass());
84     }
85 
86     /**
87      * As the smartspace view becomes available, allow listeners to receive an event.
88      */
addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)89     default void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) {
90         throw new UnsupportedOperationException("Not implemented by " + getClass());
91     }
92 
93     /** Updates Smartspace data and propagates it to any listeners. */
onTargetsAvailable(List<SmartspaceTarget> targets)94     default void onTargetsAvailable(List<SmartspaceTarget> targets) {
95         throw new UnsupportedOperationException("Not implemented by " + getClass());
96     }
97 
98     /** Provides Smartspace data to registered listeners. */
99     interface SmartspaceTargetListener {
100         /** Each Parcelable is a SmartspaceTarget that represents a card. */
onSmartspaceTargetsUpdated(List<? extends Parcelable> targets)101         void onSmartspaceTargetsUpdated(List<? extends Parcelable> targets);
102     }
103 
104     /** View to which this plugin can be registered, in order to get updates. */
105     interface SmartspaceView {
registerDataProvider(BcSmartspaceDataPlugin plugin)106         void registerDataProvider(BcSmartspaceDataPlugin plugin);
107 
108         /**
109          * Sets {@link BcSmartspaceConfigPlugin}.
110          */
registerConfigProvider(BcSmartspaceConfigPlugin configProvider)111         default void registerConfigProvider(BcSmartspaceConfigPlugin configProvider) {
112             throw new UnsupportedOperationException("Not implemented by " + getClass());
113         }
114 
115         /**
116          * Primary color for unprotected text
117          */
setPrimaryTextColor(int color)118         void setPrimaryTextColor(int color);
119 
120         /**
121          * Set the UI surface for the cards. Should be called immediately after the view is created.
122          */
setUiSurface(String uiSurface)123         void setUiSurface(String uiSurface);
124 
125         /**
126          * Range [0.0 - 1.0] when transitioning from Lockscreen to/from AOD
127          */
setDozeAmount(float amount)128         void setDozeAmount(float amount);
129 
130         /**
131          * Set the current keyguard bypass enabled status.
132          */
setKeyguardBypassEnabled(boolean enabled)133         default void setKeyguardBypassEnabled(boolean enabled) {}
134 
135         /**
136          * Overrides how Intents/PendingIntents gets launched. Mostly to support auth from
137          * the lockscreen.
138          */
setIntentStarter(IntentStarter intentStarter)139         void setIntentStarter(IntentStarter intentStarter);
140 
141         /**
142          * When on the lockscreen, use the FalsingManager to help detect errant touches
143          */
setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager)144         void setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager);
145 
146         /**
147          * Set or clear Do Not Disturb information.
148          */
setDnd(@ullable Drawable image, @Nullable String description)149         default void setDnd(@Nullable Drawable image, @Nullable String description) {
150             throw new UnsupportedOperationException("Not implemented by " + getClass());
151         }
152 
153         /**
154          * Set or clear next alarm information
155          */
setNextAlarm(@ullable Drawable image, @Nullable String description)156         default void setNextAlarm(@Nullable Drawable image, @Nullable String description) {
157             throw new UnsupportedOperationException("Not implemented by " + getClass());
158         }
159 
160         /**
161          * Set or clear device media playing
162          */
setMediaTarget(@ullable SmartspaceTarget target)163         default void setMediaTarget(@Nullable SmartspaceTarget target) {
164             throw new UnsupportedOperationException("Not implemented by " + getClass());
165         }
166 
167         /**
168          * Get the index of the currently selected page.
169          */
getSelectedPage()170         default int getSelectedPage() {
171             throw new UnsupportedOperationException("Not implemented by " + getClass());
172         }
173 
174         /**
175          * Return the top padding value from the currently visible card, or 0 if there is no current
176          * card.
177          */
getCurrentCardTopPadding()178         default int getCurrentCardTopPadding() {
179             throw new UnsupportedOperationException("Not implemented by " + getClass());
180         }
181     }
182 
183     /** Interface for launching Intents, which can differ on the lockscreen */
184     interface IntentStarter {
startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen)185         default void startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen) {
186             try {
187                 if (action.getIntent() != null) {
188                     startIntent(v, action.getIntent(), showOnLockscreen);
189                 } else if (action.getPendingIntent() != null) {
190                     startPendingIntent(action.getPendingIntent(), showOnLockscreen);
191                 }
192             } catch (ActivityNotFoundException e) {
193                 Log.w(TAG, "Could not launch intent for action: " + action, e);
194             }
195         }
196 
startFromAction(TapAction action, View v, boolean showOnLockscreen)197         default void startFromAction(TapAction action, View v, boolean showOnLockscreen) {
198             try {
199                 if (action.getIntent() != null) {
200                     startIntent(v, action.getIntent(), showOnLockscreen);
201                 } else if (action.getPendingIntent() != null) {
202                     startPendingIntent(action.getPendingIntent(), showOnLockscreen);
203                 }
204             } catch (ActivityNotFoundException e) {
205                 Log.w(TAG, "Could not launch intent for action: " + action, e);
206             }
207         }
208 
209         /** Start the intent */
startIntent(View v, Intent i, boolean showOnLockscreen)210         void startIntent(View v, Intent i, boolean showOnLockscreen);
211 
212         /** Start the PendingIntent */
startPendingIntent(PendingIntent pi, boolean showOnLockscreen)213         void startPendingIntent(PendingIntent pi, boolean showOnLockscreen);
214     }
215 }
216