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