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 if dozing is true or false 132 */ setDozing(boolean dozing)133 default void setDozing(boolean dozing) {} 134 135 /** 136 * Set if split shade enabled 137 */ setSplitShadeEnabled(boolean enabled)138 default void setSplitShadeEnabled(boolean enabled) {} 139 140 /** 141 * Set the current keyguard bypass enabled status. 142 */ setKeyguardBypassEnabled(boolean enabled)143 default void setKeyguardBypassEnabled(boolean enabled) {} 144 145 /** 146 * Overrides how Intents/PendingIntents gets launched. Mostly to support auth from 147 * the lockscreen. 148 */ setIntentStarter(IntentStarter intentStarter)149 void setIntentStarter(IntentStarter intentStarter); 150 151 /** 152 * When on the lockscreen, use the FalsingManager to help detect errant touches 153 */ setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager)154 void setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager); 155 156 /** 157 * Set or clear Do Not Disturb information. 158 */ setDnd(@ullable Drawable image, @Nullable String description)159 default void setDnd(@Nullable Drawable image, @Nullable String description) { 160 throw new UnsupportedOperationException("Not implemented by " + getClass()); 161 } 162 163 /** 164 * Set or clear next alarm information 165 */ setNextAlarm(@ullable Drawable image, @Nullable String description)166 default void setNextAlarm(@Nullable Drawable image, @Nullable String description) { 167 throw new UnsupportedOperationException("Not implemented by " + getClass()); 168 } 169 170 /** 171 * Set or clear device media playing 172 */ setMediaTarget(@ullable SmartspaceTarget target)173 default void setMediaTarget(@Nullable SmartspaceTarget target) { 174 throw new UnsupportedOperationException("Not implemented by " + getClass()); 175 } 176 177 /** 178 * Get the index of the currently selected page. 179 */ getSelectedPage()180 default int getSelectedPage() { 181 throw new UnsupportedOperationException("Not implemented by " + getClass()); 182 } 183 184 /** 185 * Return the top padding value from the currently visible card, or 0 if there is no current 186 * card. 187 */ getCurrentCardTopPadding()188 default int getCurrentCardTopPadding() { 189 throw new UnsupportedOperationException("Not implemented by " + getClass()); 190 } 191 } 192 193 /** Interface for launching Intents, which can differ on the lockscreen */ 194 interface IntentStarter { startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen)195 default void startFromAction(SmartspaceAction action, View v, boolean showOnLockscreen) { 196 try { 197 if (action.getIntent() != null) { 198 startIntent(v, action.getIntent(), showOnLockscreen); 199 } else if (action.getPendingIntent() != null) { 200 startPendingIntent(v, action.getPendingIntent(), showOnLockscreen); 201 } 202 } catch (ActivityNotFoundException e) { 203 Log.w(TAG, "Could not launch intent for action: " + action, e); 204 } 205 } 206 startFromAction(TapAction action, View v, boolean showOnLockscreen)207 default void startFromAction(TapAction 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 219 /** Start the intent */ startIntent(View v, Intent i, boolean showOnLockscreen)220 void startIntent(View v, Intent i, boolean showOnLockscreen); 221 222 /** Start the PendingIntent */ startPendingIntent(View v, PendingIntent pi, boolean showOnLockscreen)223 void startPendingIntent(View v, PendingIntent pi, boolean showOnLockscreen); 224 } 225 } 226