• 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.Handler;
28 import android.os.Parcelable;
29 import android.util.Log;
30 import android.view.View;
31 import android.view.ViewGroup;
32 
33 import androidx.annotation.Nullable;
34 
35 import com.android.systemui.plugins.annotations.ProvidesInterface;
36 
37 import java.util.List;
38 
39 /**
40  * Interface to provide SmartspaceTargets to BcSmartspace.
41  */
42 @ProvidesInterface(action = BcSmartspaceDataPlugin.ACTION, version = BcSmartspaceDataPlugin.VERSION)
43 public interface BcSmartspaceDataPlugin extends Plugin {
44     String UI_SURFACE_LOCK_SCREEN_AOD = "lockscreen";
45     String UI_SURFACE_HOME_SCREEN = "home";
46     String UI_SURFACE_MEDIA = "media_data_manager";
47     String UI_SURFACE_DREAM = "dream";
48     String UI_SURFACE_GLANCEABLE_HUB = "glanceable_hub";
49 
50     String ACTION = "com.android.systemui.action.PLUGIN_BC_SMARTSPACE_DATA";
51     int VERSION = 1;
52     String TAG = "BcSmartspaceDataPlugin";
53 
54     /** Register a listener to get Smartspace data. */
registerListener(SmartspaceTargetListener listener)55     default void registerListener(SmartspaceTargetListener listener) {
56         throw new UnsupportedOperationException("Not implemented by " + getClass());
57     }
58 
59     /** Unregister a listener. */
unregisterListener(SmartspaceTargetListener listener)60     default void unregisterListener(SmartspaceTargetListener listener) {
61         throw new UnsupportedOperationException("Not implemented by " + getClass());
62     }
63 
64     /** Register a SmartspaceEventNotifier. */
registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier)65     default void registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier) {
66         throw new UnsupportedOperationException("Not implemented by " + getClass());
67     }
68 
69     /** Push a SmartspaceTargetEvent to the SmartspaceEventNotifier. */
notifySmartspaceEvent(SmartspaceTargetEvent event)70     default void notifySmartspaceEvent(SmartspaceTargetEvent event) {
71         throw new UnsupportedOperationException("Not implemented by " + getClass());
72     }
73 
74     /** Allows for notifying the SmartspaceSession of SmartspaceTargetEvents. */
75     interface SmartspaceEventNotifier {
76         /** Pushes a given SmartspaceTargetEvent to the SmartspaceSession. */
notifySmartspaceEvent(SmartspaceTargetEvent event)77         void notifySmartspaceEvent(SmartspaceTargetEvent event);
78     }
79 
80     /**
81      * Create a view to be shown within the parent. Do not add the view, as the parent
82      * will be responsible for correctly setting the LayoutParams
83      */
getView(ViewGroup parent)84     default SmartspaceView getView(ViewGroup parent) {
85         throw new UnsupportedOperationException("Not implemented by " + getClass());
86     }
87 
getLargeClockView(ViewGroup parent)88     default SmartspaceView getLargeClockView(ViewGroup parent) {
89         throw new UnsupportedOperationException("Not implemented by " + getClass());
90     }
91 
92     /**
93      * As the smartspace view becomes available, allow listeners to receive an event.
94      */
addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)95     default void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) {
96         throw new UnsupportedOperationException("Not implemented by " + getClass());
97     }
98 
99     /** Updates Smartspace data and propagates it to any listeners. */
onTargetsAvailable(List<SmartspaceTarget> targets)100     default void onTargetsAvailable(List<SmartspaceTarget> targets) {
101         throw new UnsupportedOperationException("Not implemented by " + getClass());
102     }
103 
104     /** Provides Smartspace data to registered listeners. */
105     interface SmartspaceTargetListener {
106         /** Each Parcelable is a SmartspaceTarget that represents a card. */
onSmartspaceTargetsUpdated(List<? extends Parcelable> targets)107         void onSmartspaceTargetsUpdated(List<? extends Parcelable> targets);
108     }
109 
110     /**
111      * Sets {@link BcSmartspaceConfigPlugin}.
112      *
113      * TODO: b/259566300 - Remove once isViewPager2Enabled is fully rolled out
114      */
registerConfigProvider(BcSmartspaceConfigPlugin configProvider)115     default void registerConfigProvider(BcSmartspaceConfigPlugin configProvider) {
116         throw new UnsupportedOperationException("Not implemented by " + getClass());
117     }
118 
119     /** View to which this plugin can be registered, in order to get updates. */
120     interface SmartspaceView {
registerDataProvider(BcSmartspaceDataPlugin plugin)121         void registerDataProvider(BcSmartspaceDataPlugin plugin);
122 
123         /**
124          * Sets {@link BcSmartspaceConfigPlugin}.
125          */
registerConfigProvider(BcSmartspaceConfigPlugin configProvider)126         default void registerConfigProvider(BcSmartspaceConfigPlugin configProvider) {
127             throw new UnsupportedOperationException("Not implemented by " + getClass());
128         }
129 
130         /**
131          * Primary color for unprotected text
132          */
setPrimaryTextColor(int color)133         void setPrimaryTextColor(int color);
134 
135         /**
136          * Set the UI surface for the cards. Should be called immediately after the view is created.
137          */
setUiSurface(String uiSurface)138         void setUiSurface(String uiSurface);
139 
140         /** Set background handler to make binder calls. */
setBgHandler(Handler bgHandler)141         void setBgHandler(Handler bgHandler);
142 
143         /**
144          * Range [0.0 - 1.0] when transitioning from Lockscreen to/from AOD
145          */
setDozeAmount(float amount)146         void setDozeAmount(float amount);
147 
148         /**
149          * Set if the screen is on.
150          */
setScreenOn(boolean screenOn)151         default void setScreenOn(boolean screenOn) {}
152 
153         /**
154          * Sets a delegate to handle clock event registration. Should be called immediately after
155          * the view is created.
156          */
setTimeChangedDelegate(TimeChangedDelegate delegate)157         default void setTimeChangedDelegate(TimeChangedDelegate delegate) {}
158 
159         /**
160          * Set if dozing is true or false
161          */
setDozing(boolean dozing)162         default void setDozing(boolean dozing) {}
163 
164         /**
165          * Set if split shade enabled
166          */
setSplitShadeEnabled(boolean enabled)167         default void setSplitShadeEnabled(boolean enabled) {}
168 
169         /**
170          * Set the current keyguard bypass enabled status.
171          */
setKeyguardBypassEnabled(boolean enabled)172         default void setKeyguardBypassEnabled(boolean enabled) {}
173 
174         /**
175          * Overrides how Intents/PendingIntents gets launched. Mostly to support auth from
176          * the lockscreen.
177          */
setIntentStarter(IntentStarter intentStarter)178         void setIntentStarter(IntentStarter intentStarter);
179 
180         /**
181          * When on the lockscreen, use the FalsingManager to help detect errant touches
182          */
setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager)183         void setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager);
184 
185         /**
186          * Set or clear Do Not Disturb information.
187          */
setDnd(@ullable Drawable image, @Nullable String description)188         default void setDnd(@Nullable Drawable image, @Nullable String description) {
189             throw new UnsupportedOperationException("Not implemented by " + getClass());
190         }
191 
192         /**
193          * Set or clear next alarm information
194          */
setNextAlarm(@ullable Drawable image, @Nullable String description)195         default void setNextAlarm(@Nullable Drawable image, @Nullable String description) {
196             throw new UnsupportedOperationException("Not implemented by " + getClass());
197         }
198 
199         /**
200          * Set or clear device media playing
201          */
setMediaTarget(@ullable SmartspaceTarget target)202         default void setMediaTarget(@Nullable SmartspaceTarget target) {
203             throw new UnsupportedOperationException("Not implemented by " + getClass());
204         }
205 
206         /**
207          * Get the index of the currently selected page.
208          */
getSelectedPage()209         default int getSelectedPage() {
210             throw new UnsupportedOperationException("Not implemented by " + getClass());
211         }
212 
213         /**
214          * Return the top padding value from the currently visible card, or 0 if there is no current
215          * card.
216          */
getCurrentCardTopPadding()217         default int getCurrentCardTopPadding() {
218             throw new UnsupportedOperationException("Not implemented by " + getClass());
219         }
220 
221         /**
222          * Set the horizontal paddings for applicable children inside the SmartspaceView.
223          */
setHorizontalPaddings(int horizontalPadding)224         default void setHorizontalPaddings(int horizontalPadding) {
225             throw new UnsupportedOperationException("Not implemented by " + getClass());
226         }
227     }
228 
229     /** Interface for launching Intents, which can differ on the lockscreen */
230     interface IntentStarter {
startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen)231         default void startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen) {
232             try {
233                 if (action.getIntent() != null) {
234                     startIntent(v, action.getIntent(), showOnLockscreen);
235                 } else if (action.getPendingIntent() != null) {
236                     startPendingIntent(v, action.getPendingIntent(), showOnLockscreen);
237                 }
238             } catch (ActivityNotFoundException e) {
239                 Log.w(TAG, "Could not launch intent for action: " + action, e);
240             }
241         }
242 
startFromAction(TapAction action, View v, boolean showOnLockscreen)243         default void startFromAction(TapAction action, View v, boolean showOnLockscreen) {
244             try {
245                 if (action.getIntent() != null) {
246                     startIntent(v, action.getIntent(), showOnLockscreen);
247                 } else if (action.getPendingIntent() != null) {
248                     startPendingIntent(v, action.getPendingIntent(), showOnLockscreen);
249                 }
250             } catch (ActivityNotFoundException e) {
251                 Log.w(TAG, "Could not launch intent for action: " + action, e);
252             }
253         }
254 
255         /** Start the intent */
startIntent(View v, Intent i, boolean showOnLockscreen)256         void startIntent(View v, Intent i, boolean showOnLockscreen);
257 
258         /** Start the PendingIntent */
startPendingIntent(View v, PendingIntent pi, boolean showOnLockscreen)259         void startPendingIntent(View v, PendingIntent pi, boolean showOnLockscreen);
260     }
261 
262     /** Interface for delegating time updates */
263     interface TimeChangedDelegate {
264         /** Register the callback to be called when time is updated **/
register(Runnable callback)265         void register(Runnable callback);
266 
267         /** Unegister the callback **/
unregister()268         void unregister();
269     }
270 }
271