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.content.Intent; 24 import android.graphics.drawable.Drawable; 25 import android.os.Parcelable; 26 import android.view.View; 27 import android.view.ViewGroup; 28 29 import androidx.annotation.Nullable; 30 31 import com.android.systemui.plugins.annotations.ProvidesInterface; 32 33 import java.util.List; 34 35 /** 36 * Interface to provide SmartspaceTargets to BcSmartspace. 37 */ 38 @ProvidesInterface(action = BcSmartspaceDataPlugin.ACTION, version = BcSmartspaceDataPlugin.VERSION) 39 public interface BcSmartspaceDataPlugin extends Plugin { 40 String ACTION = "com.android.systemui.action.PLUGIN_BC_SMARTSPACE_DATA"; 41 int VERSION = 1; 42 43 /** Register a listener to get Smartspace data. */ registerListener(SmartspaceTargetListener listener)44 void registerListener(SmartspaceTargetListener listener); 45 46 /** Unregister a listener. */ unregisterListener(SmartspaceTargetListener listener)47 void unregisterListener(SmartspaceTargetListener listener); 48 49 /** Register a SmartspaceEventNotifier. */ registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier)50 default void registerSmartspaceEventNotifier(SmartspaceEventNotifier notifier) {} 51 52 /** Push a SmartspaceTargetEvent to the SmartspaceEventNotifier. */ notifySmartspaceEvent(SmartspaceTargetEvent event)53 default void notifySmartspaceEvent(SmartspaceTargetEvent event) {} 54 55 /** Allows for notifying the SmartspaceSession of SmartspaceTargetEvents. */ 56 interface SmartspaceEventNotifier { 57 /** Pushes a given SmartspaceTargetEvent to the SmartspaceSession. */ notifySmartspaceEvent(SmartspaceTargetEvent event)58 void notifySmartspaceEvent(SmartspaceTargetEvent event); 59 } 60 61 /** 62 * Create a view to be shown within the parent. Do not add the view, as the parent 63 * will be responsible for correctly setting the LayoutParams 64 */ getView(ViewGroup parent)65 default SmartspaceView getView(ViewGroup parent) { 66 return null; 67 } 68 69 /** 70 * As the smartspace view becomes available, allow listeners to receive an event. 71 */ addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)72 default void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener) { } 73 74 /** Updates Smartspace data and propagates it to any listeners. */ onTargetsAvailable(List<SmartspaceTarget> targets)75 void onTargetsAvailable(List<SmartspaceTarget> targets); 76 77 /** Provides Smartspace data to registered listeners. */ 78 interface SmartspaceTargetListener { 79 /** Each Parcelable is a SmartspaceTarget that represents a card. */ onSmartspaceTargetsUpdated(List<? extends Parcelable> targets)80 void onSmartspaceTargetsUpdated(List<? extends Parcelable> targets); 81 } 82 83 /** View to which this plugin can be registered, in order to get updates. */ 84 interface SmartspaceView { registerDataProvider(BcSmartspaceDataPlugin plugin)85 void registerDataProvider(BcSmartspaceDataPlugin plugin); 86 87 /** 88 * Primary color for unprotected text 89 */ setPrimaryTextColor(int color)90 void setPrimaryTextColor(int color); 91 92 /** 93 * Range [0.0 - 1.0] when transitioning from Lockscreen to/from AOD 94 */ setDozeAmount(float amount)95 void setDozeAmount(float amount); 96 97 /** 98 * Overrides how Intents/PendingIntents gets launched. Mostly to support auth from 99 * the lockscreen. 100 */ setIntentStarter(IntentStarter intentStarter)101 void setIntentStarter(IntentStarter intentStarter); 102 103 /** 104 * When on the lockscreen, use the FalsingManager to help detect errant touches 105 */ setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager)106 void setFalsingManager(com.android.systemui.plugins.FalsingManager falsingManager); 107 108 /** 109 * Set or clear Do Not Disturb information. 110 */ setDnd(@ullable Drawable image, @Nullable String description)111 void setDnd(@Nullable Drawable image, @Nullable String description); 112 113 /** 114 * Set or clear next alarm information 115 */ setNextAlarm(@ullable Drawable image, @Nullable String description)116 void setNextAlarm(@Nullable Drawable image, @Nullable String description); 117 118 /** 119 * Set or clear device media playing 120 */ setMediaTarget(@ullable SmartspaceTarget target)121 void setMediaTarget(@Nullable SmartspaceTarget target); 122 } 123 124 /** Interface for launching Intents, which can differ on the lockscreen */ 125 interface IntentStarter { startFromAction(SmartspaceAction action, View v)126 default void startFromAction(SmartspaceAction action, View v) { 127 if (action.getIntent() != null) { 128 startIntent(v, action.getIntent()); 129 } else if (action.getPendingIntent() != null) { 130 startPendingIntent(action.getPendingIntent()); 131 } 132 } 133 134 /** Start the intent */ startIntent(View v, Intent i)135 void startIntent(View v, Intent i); 136 137 /** Start the PendingIntent */ startPendingIntent(PendingIntent pi)138 void startPendingIntent(PendingIntent pi); 139 } 140 } 141