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