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.Intent; 20 import android.os.Bundle; 21 import android.os.UserHandle; 22 import android.view.View; 23 24 import com.android.systemui.animation.ActivityTransitionAnimator; 25 import com.android.systemui.plugins.annotations.ProvidesInterface; 26 27 /** 28 * An interface to start activities. This is used as a callback from the views to 29 * {@link PhoneStatusBar} to allow custom handling for starting the activity, i.e. dismissing the 30 * Keyguard. 31 */ 32 @ProvidesInterface(version = ActivityStarter.VERSION) 33 public interface ActivityStarter { 34 int VERSION = 2; 35 startPendingIntentDismissingKeyguard(PendingIntent intent)36 void startPendingIntentDismissingKeyguard(PendingIntent intent); 37 38 /** 39 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent)}, but allows 40 * you to specify the callback that is executed on the UI thread after the intent is sent. 41 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback)42 void startPendingIntentDismissingKeyguard(PendingIntent intent, 43 Runnable intentSentUiThreadCallback); 44 45 /** 46 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also 47 * specifies an associated view that should be used for the activity launch animation. 48 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable View associatedView)49 void startPendingIntentDismissingKeyguard(PendingIntent intent, 50 Runnable intentSentUiThreadCallback, @Nullable View associatedView); 51 52 /** 53 * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also 54 * specifies an animation controller that should be used for the activity launch animation. 55 */ startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController)56 void startPendingIntentDismissingKeyguard(PendingIntent intent, 57 Runnable intentSentUiThreadCallback, 58 @Nullable ActivityTransitionAnimator.Controller animationController); 59 60 /** 61 * Similar to {@link #startPendingIntentMaybeDismissingKeyguard(PendingIntent, Runnable, 62 * ActivityTransitionAnimator.Controller)} but will always not dismiss the keyguard when 63 * launching activities. This should be avoided and other alternatives should be used. 64 */ startPendingIntentWithoutDismissing( PendingIntent intent, boolean dismissShade, Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable Intent fillInIntent, @Nullable Bundle extraOptions)65 void startPendingIntentWithoutDismissing( 66 PendingIntent intent, 67 boolean dismissShade, 68 Runnable intentSentUiThreadCallback, 69 @Nullable ActivityTransitionAnimator.Controller animationController, 70 @Nullable Intent fillInIntent, 71 @Nullable Bundle extraOptions); 72 73 /** 74 * Similar to {@link #startPendingIntentDismissingKeyguard}, except that it supports launching 75 * activities on top of the keyguard. If the activity supports {@code showOverLockscreen}, it 76 * will show over keyguard without first dimissing it. If it doesn't support it, calling this 77 * method is exactly the same as calling {@link #startPendingIntentDismissingKeyguard}. 78 */ startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, @Nullable Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController)79 void startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, 80 @Nullable Runnable intentSentUiThreadCallback, 81 @Nullable ActivityTransitionAnimator.Controller animationController); 82 83 /** 84 * Similar to {@link #startPendingIntentMaybeDismissingKeyguard(PendingIntent, Runnable, 85 * ActivityTransitionAnimator.Controller)}, but also specifies a fill-in intent and extra 86 * option that could be used to populate the pending intent and launch the activity. This also 87 * allows the caller to avoid dismissing the shade. 88 */ startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, boolean dismissShade, @Nullable Runnable intentSentUiThreadCallback, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable Intent fillInIntent, @Nullable Bundle extraOptions)89 void startPendingIntentMaybeDismissingKeyguard(PendingIntent intent, 90 boolean dismissShade, 91 @Nullable Runnable intentSentUiThreadCallback, 92 @Nullable ActivityTransitionAnimator.Controller animationController, 93 @Nullable Intent fillInIntent, 94 @Nullable Bundle extraOptions); 95 96 /** 97 * The intent flag can be specified in startActivity(). 98 */ startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags)99 void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags); startActivity(Intent intent, boolean dismissShade)100 void startActivity(Intent intent, boolean dismissShade); startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController)101 default void startActivity(Intent intent, boolean dismissShade, 102 @Nullable ActivityTransitionAnimator.Controller animationController) { 103 startActivity(intent, dismissShade, animationController, 104 false /* showOverLockscreenWhenLocked */); 105 } 106 startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController, boolean showOverLockscreenWhenLocked)107 void startActivity(Intent intent, boolean dismissShade, 108 @Nullable ActivityTransitionAnimator.Controller animationController, 109 boolean showOverLockscreenWhenLocked); startActivity(Intent intent, boolean dismissShade, @Nullable ActivityTransitionAnimator.Controller animationController, boolean showOverLockscreenWhenLocked, UserHandle userHandle)110 void startActivity(Intent intent, boolean dismissShade, 111 @Nullable ActivityTransitionAnimator.Controller animationController, 112 boolean showOverLockscreenWhenLocked, UserHandle userHandle); startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade)113 void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade); startActivity(Intent intent, boolean dismissShade, Callback callback)114 void startActivity(Intent intent, boolean dismissShade, Callback callback); postStartActivityDismissingKeyguard(Intent intent, int delay)115 void postStartActivityDismissingKeyguard(Intent intent, int delay); postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityTransitionAnimator.Controller animationController)116 void postStartActivityDismissingKeyguard(Intent intent, int delay, 117 @Nullable ActivityTransitionAnimator.Controller animationController); 118 119 /** Posts a start activity intent that dismisses keyguard. */ postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityTransitionAnimator.Controller animationController, @Nullable String customMessage)120 void postStartActivityDismissingKeyguard(Intent intent, int delay, 121 @Nullable ActivityTransitionAnimator.Controller animationController, 122 @Nullable String customMessage); postStartActivityDismissingKeyguard(PendingIntent intent)123 void postStartActivityDismissingKeyguard(PendingIntent intent); 124 125 /** 126 * Similar to {@link #postStartActivityDismissingKeyguard(PendingIntent)}, but also specifies an 127 * animation controller that should be used for the activity launch animation. 128 */ postStartActivityDismissingKeyguard(PendingIntent intent, @Nullable ActivityTransitionAnimator.Controller animationController)129 void postStartActivityDismissingKeyguard(PendingIntent intent, 130 @Nullable ActivityTransitionAnimator.Controller animationController); 131 postQSRunnableDismissingKeyguard(Runnable runnable)132 void postQSRunnableDismissingKeyguard(Runnable runnable); 133 dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, boolean afterKeyguardGone)134 void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, 135 boolean afterKeyguardGone); 136 137 /** Authenticates if needed and dismisses keyguard to execute an action. */ dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, boolean afterKeyguardGone, @Nullable String customMessage)138 void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, 139 boolean afterKeyguardGone, @Nullable String customMessage); 140 141 /** Starts an activity and dismisses keyguard. */ startActivityDismissingKeyguard(Intent intent, boolean onlyProvisioned, boolean dismissShade)142 void startActivityDismissingKeyguard(Intent intent, 143 boolean onlyProvisioned, 144 boolean dismissShade); 145 146 /** 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)147 void startActivityDismissingKeyguard(Intent intent, 148 boolean onlyProvisioned, 149 boolean dismissShade, 150 boolean disallowEnterPictureInPictureWhileLaunching, 151 Callback callback, 152 int flags, 153 @Nullable ActivityTransitionAnimator.Controller animationController, 154 UserHandle userHandle); 155 156 /** Execute a runnable after dismissing keyguard. */ executeRunnableDismissingKeyguard(Runnable runnable, Runnable cancelAction, boolean dismissShade, boolean afterKeyguardGone, boolean deferred)157 void executeRunnableDismissingKeyguard(Runnable runnable, 158 Runnable cancelAction, 159 boolean dismissShade, 160 boolean afterKeyguardGone, 161 boolean deferred); 162 163 /** Whether we should animate an activity launch. */ shouldAnimateLaunch(boolean isActivityIntent)164 boolean shouldAnimateLaunch(boolean isActivityIntent); 165 166 interface Callback { onActivityStarted(int resultCode)167 void onActivityStarted(int resultCode); 168 } 169 170 interface OnDismissAction { 171 /** 172 * @return {@code true} if the dismiss should be deferred. When returning true, make sure to 173 * call {@link com.android.keyguard.ViewMediatorCallback#readyForKeyguardDone()} 174 * *after* returning to start hiding the keyguard. 175 */ onDismiss()176 boolean onDismiss(); 177 178 /** 179 * Whether running this action when we are locked will start an animation on the keyguard. 180 */ willRunAnimationOnKeyguard()181 default boolean willRunAnimationOnKeyguard() { 182 return false; 183 } 184 } 185 } 186