1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.plugins; 16 17 import android.annotation.Nullable; 18 import android.app.PendingIntent; 19 import android.content.ComponentName; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.os.UserHandle; 23 import android.view.View; 24 25 import com.android.systemui.animation.ActivityTransitionAnimator; 26 import com.android.systemui.plugins.annotations.ProvidesInterface; 27 28 import kotlinx.coroutines.CoroutineScope; 29 30 /** 31 * An interface to start activities. This is used as a callback from the views to 32 * {@link PhoneStatusBar} to allow custom handling for starting the activity, i.e. dismissing the 33 * Keyguard. 34 */ 35 @ProvidesInterface(version = ActivityStarter.VERSION) 36 public interface ActivityStarter { 37 int VERSION = 2; 38 39 /** 40 * Registers the given {@link ActivityTransitionAnimator.ControllerFactory} for launching and 41 * closing transitions matching the {@link ActivityTransitionAnimator.TransitionCookie} and the 42 * {@link ComponentName} that it contains, within the given {@link CoroutineScope}. 43 */ registerTransition( ActivityTransitionAnimator.TransitionCookie cookie, ActivityTransitionAnimator.ControllerFactory controllerFactory, CoroutineScope scope)44 void registerTransition( 45 ActivityTransitionAnimator.TransitionCookie cookie, 46 ActivityTransitionAnimator.ControllerFactory controllerFactory, 47 CoroutineScope scope); 48 49 /** 50 * Unregisters the {@link ActivityTransitionAnimator.ControllerFactory} previously registered 51 * containing the given {@link ActivityTransitionAnimator.TransitionCookie}. If no such 52 * registration exists, this is a no-op. 53 */ unregisterTransition(ActivityTransitionAnimator.TransitionCookie cookie)54 void unregisterTransition(ActivityTransitionAnimator.TransitionCookie cookie); 55 startPendingIntentDismissingKeyguard(PendingIntent intent)56 void startPendingIntentDismissingKeyguard(PendingIntent intent); 57 58 /** 59 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent)}, but allows 60 * you to specify the callback that is executed on the UI thread after the intent is sent. 61 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback)62 void startPendingIntentDismissingKeyguard(PendingIntent intent, 63 Runnable intentSentUiThreadCallback); 64 65 /** 66 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also 67 * specifies an associated view that should be used for the activity launch animation. 68 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable View associatedView)69 void startPendingIntentDismissingKeyguard(PendingIntent intent, 70 Runnable intentSentUiThreadCallback, @Nullable View associatedView); 71 72 /** 73 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also 74 * specifies an animation controller that should be used for the activity launch animation. 75 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController)76 void startPendingIntentDismissingKeyguard(PendingIntent intent, 77 Runnable intentSentUiThreadCallback, 78 @Nullable ActivityTransitionAnimator.Controller animationController); 79 80 /** 81 * Similar to {@link #startPendingIntentMaybeDismissingKeyguard(PendingIntent, Runnable, 82 * ActivityTransitionAnimator.Controller)} but will always not dismiss the keyguard when 83 * launching activities. This should be avoided and other alternatives should be used. 84 */ startPendingIntentWithoutDismissing( PendingIntent intent, boolean dismissShade, Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable Intent fillInIntent, @Nullable Bundle extraOptions)85 void startPendingIntentWithoutDismissing( 86 PendingIntent intent, 87 boolean dismissShade, 88 Runnable intentSentUiThreadCallback, 89 @Nullable ActivityTransitionAnimator.Controller animationController, 90 @Nullable Intent fillInIntent, 91 @Nullable Bundle extraOptions); 92 93 /** 94 * Similar to {@link #startPendingIntentDismissingKeyguard}, except that it supports launching 95 * activities on top of the keyguard. If the activity supports {@code showOverLockscreen}, it 96 * will show over keyguard without first dimissing it. If it doesn't support it, calling this 97 * method is exactly the same as calling {@link #startPendingIntentDismissingKeyguard}. 98 */ startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, @Nullable Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController)99 void startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, 100 @Nullable Runnable intentSentUiThreadCallback, 101 @Nullable ActivityTransitionAnimator.Controller animationController); 102 103 /** 104 * Similar to {@link #startPendingIntentMaybeDismissingKeyguard(PendingIntent, Runnable, 105 * ActivityTransitionAnimator.Controller)}, but also specifies a fill-in intent and extra 106 * option that could be used to populate the pending intent and launch the activity. This also 107 * allows the caller to avoid dismissing the shade. An optional custom message can be set as 108 * the unlock reason in the alternate bouncer. 109 */ startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, boolean dismissShade, @Nullable Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable Intent fillInIntent, @Nullable Bundle extraOptions, @Nullable String customMessage )110 void startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, 111 boolean dismissShade, 112 @Nullable Runnable intentSentUiThreadCallback, 113 @Nullable ActivityTransitionAnimator.Controller animationController, 114 @Nullable Intent fillInIntent, 115 @Nullable Bundle extraOptions, 116 @Nullable String customMessage 117 ); 118 119 /** 120 * The intent flag can be specified in startActivity(). 121 */ startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags)122 void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags); startActivity(Intent intent, boolean dismissShade)123 void startActivity(Intent intent, boolean dismissShade); startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController)124 default void startActivity(Intent intent, boolean dismissShade, 125 @Nullable ActivityTransitionAnimator.Controller animationController) { 126 startActivity(intent, dismissShade, animationController, 127 false /* showOverLockscreenWhenLocked */); 128 } 129 startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController, boolean showOverLockscreenWhenLocked)130 void startActivity(Intent intent, boolean dismissShade, 131 @Nullable ActivityTransitionAnimator.Controller animationController, 132 boolean showOverLockscreenWhenLocked); startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController, boolean showOverLockscreenWhenLocked, UserHandle userHandle)133 void startActivity(Intent intent, boolean dismissShade, 134 @Nullable ActivityTransitionAnimator.Controller animationController, 135 boolean showOverLockscreenWhenLocked, UserHandle userHandle); startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade)136 void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade); startActivity(Intent intent, boolean dismissShade, Callback callback)137 void startActivity(Intent intent, boolean dismissShade, Callback callback); postStartActivityDismissingKeyguard(Intent intent, int delay)138 void postStartActivityDismissingKeyguard(Intent intent, int delay); postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityTransitionAnimator.Controller animationController)139 void postStartActivityDismissingKeyguard(Intent intent, int delay, 140 @Nullable ActivityTransitionAnimator.Controller animationController); 141 142 /** Posts a start activity intent that dismisses keyguard. */ postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable String customMessage)143 void postStartActivityDismissingKeyguard(Intent intent, int delay, 144 @Nullable ActivityTransitionAnimator.Controller animationController, 145 @Nullable String customMessage); 146 /** Posts a start activity intent that dismisses keyguard. */ postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable String customMessage, @Nullable UserHandle userHandle)147 void postStartActivityDismissingKeyguard(Intent intent, int delay, 148 @Nullable ActivityTransitionAnimator.Controller animationController, 149 @Nullable String customMessage, 150 @Nullable UserHandle userHandle); postStartActivityDismissingKeyguard(PendingIntent intent)151 void postStartActivityDismissingKeyguard(PendingIntent intent); 152 153 /** 154 * Similar to {@link #postStartActivityDismissingKeyguard(PendingIntent)}, but also specifies an 155 * animation controller that should be used for the activity launch animation. 156 */ postStartActivityDismissingKeyguard(PendingIntent intent, @Nullable ActivityTransitionAnimator.Controller animationController)157 void postStartActivityDismissingKeyguard(PendingIntent intent, 158 @Nullable ActivityTransitionAnimator.Controller animationController); 159 postQSRunnableDismissingKeyguard(Runnable runnable)160 void postQSRunnableDismissingKeyguard(Runnable runnable); 161 dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, boolean afterKeyguardGone)162 void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, 163 boolean afterKeyguardGone); 164 165 /** 166 * Authenticates if needed and dismisses keyguard to execute an action. 167 * 168 * TODO(b/348431835) Display the custom message in the new alternate bouncer, when the 169 * device_entry_udfps_refactor flag is enabled. 170 */ dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, boolean afterKeyguardGone, @Nullable String customMessage)171 void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, 172 boolean afterKeyguardGone, @Nullable String customMessage); 173 174 /** Starts an activity and dismisses keyguard. */ startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned, boolean dismissShade, @Nullable String customMessage)175 void startActivityDismissingKeyguard(Intent intent, 176 boolean onlyProvisioned, 177 boolean dismissShade, 178 @Nullable String customMessage); 179 180 /** Starts an activity and dismisses keyguard. */ startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned, boolean dismissShade, boolean disallowEnterPictureInPictureWhileLaunching, Callback callback, int flags, @Nullable ActivityTransitionAnimator.Controller animationController, UserHandle userHandle)181 void startActivityDismissingKeyguard(Intent intent, 182 boolean onlyProvisioned, 183 boolean dismissShade, 184 boolean disallowEnterPictureInPictureWhileLaunching, 185 Callback callback, 186 int flags, 187 @Nullable ActivityTransitionAnimator.Controller animationController, 188 UserHandle userHandle); 189 190 /** Execute a runnable after dismissing keyguard. */ executeRunnableDismissingKeyguard(Runnable runnable, Runnable cancelAction, boolean dismissShade, boolean afterKeyguardGone, boolean deferred)191 void executeRunnableDismissingKeyguard(Runnable runnable, 192 Runnable cancelAction, 193 boolean dismissShade, 194 boolean afterKeyguardGone, 195 boolean deferred); 196 197 /** Whether we should animate an activity launch. */ shouldAnimateLaunch(boolean isActivityIntent)198 boolean shouldAnimateLaunch(boolean isActivityIntent); 199 200 interface Callback { onActivityStarted(int resultCode)201 void onActivityStarted(int resultCode); 202 } 203 204 interface OnDismissAction { 205 /** 206 * @return {@code true} if the dismiss should be deferred. When returning true, make sure to 207 * call {@link com.android.keyguard.ViewMediatorCallback#readyForKeyguardDone()} 208 * *after* returning to start hiding the keyguard. 209 */ onDismiss()210 boolean onDismiss(); 211 212 /** 213 * Whether running this action when we are locked will start an animation on the keyguard. 214 */ willRunAnimationOnKeyguard()215 default boolean willRunAnimationOnKeyguard() { 216 return false; 217 } 218 } 219 } 220