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.view.View;
21 
22 import com.android.systemui.animation.ActivityLaunchAnimator;
23 import com.android.systemui.plugins.annotations.ProvidesInterface;
24 
25 /**
26  * An interface to start activities. This is used as a callback from the views to
27  * {@link PhoneStatusBar} to allow custom handling for starting the activity, i.e. dismissing the
28  * Keyguard.
29  */
30 @ProvidesInterface(version = ActivityStarter.VERSION)
31 public interface ActivityStarter {
32     int VERSION = 2;
33 
startPendingIntentDismissingKeyguard(PendingIntent intent)34     void startPendingIntentDismissingKeyguard(PendingIntent intent);
35 
36     /**
37      * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent)}, but allows
38      * you to specify the callback that is executed on the UI thread after the intent is sent.
39      */
startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback)40     void startPendingIntentDismissingKeyguard(PendingIntent intent,
41             Runnable intentSentUiThreadCallback);
42 
43     /**
44      * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also
45      * specifies an associated view that should be used for the activity launch animation.
46      */
startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable View associatedView)47     void startPendingIntentDismissingKeyguard(PendingIntent intent,
48             Runnable intentSentUiThreadCallback, @Nullable View associatedView);
49 
50     /**
51      * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but also
52      * specifies an animation controller that should be used for the activity launch animation.
53      */
startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentUiThreadCallback, @Nullable ActivityLaunchAnimator.Controller animationController)54     void startPendingIntentDismissingKeyguard(PendingIntent intent,
55             Runnable intentSentUiThreadCallback,
56             @Nullable ActivityLaunchAnimator.Controller animationController);
57 
58     /**
59      * The intent flag can be specified in startActivity().
60      */
startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags)61     void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade, int flags);
startActivity(Intent intent, boolean dismissShade)62     void startActivity(Intent intent, boolean dismissShade);
63 
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 onlyProvisioned, boolean dismissShade)73     void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade);
startActivity(Intent intent, boolean dismissShade, Callback callback)74     void startActivity(Intent intent, boolean dismissShade, Callback callback);
postStartActivityDismissingKeyguard(Intent intent, int delay)75     void postStartActivityDismissingKeyguard(Intent intent, int delay);
postStartActivityDismissingKeyguard(Intent intent, int delay, @Nullable ActivityLaunchAnimator.Controller animationController)76     void postStartActivityDismissingKeyguard(Intent intent, int delay,
77             @Nullable ActivityLaunchAnimator.Controller animationController);
postStartActivityDismissingKeyguard(PendingIntent intent)78     void postStartActivityDismissingKeyguard(PendingIntent intent);
79 
80     /**
81      * Similar to {@link #postStartActivityDismissingKeyguard(PendingIntent)}, but also specifies an
82      * animation controller that should be used for the activity launch animation.
83      */
postStartActivityDismissingKeyguard(PendingIntent intent, @Nullable ActivityLaunchAnimator.Controller animationController)84     void postStartActivityDismissingKeyguard(PendingIntent intent,
85             @Nullable ActivityLaunchAnimator.Controller animationController);
86 
postQSRunnableDismissingKeyguard(Runnable runnable)87     void postQSRunnableDismissingKeyguard(Runnable runnable);
88 
dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel, boolean afterKeyguardGone)89     void dismissKeyguardThenExecute(OnDismissAction action, @Nullable Runnable cancel,
90             boolean afterKeyguardGone);
91 
92     interface Callback {
onActivityStarted(int resultCode)93         void onActivityStarted(int resultCode);
94     }
95 
96     interface OnDismissAction {
97         /**
98          * @return {@code true} if the dismiss should be deferred. When returning true, make sure to
99          *         call {@link com.android.keyguard.ViewMediatorCallback#readyForKeyguardDone()}
100          *         *after* returning to start hiding the keyguard.
101          */
onDismiss()102         boolean onDismiss();
103 
104         /**
105          * Whether running this action when we are locked will start an animation on the keyguard.
106          */
willRunAnimationOnKeyguard()107         default boolean willRunAnimationOnKeyguard() {
108             return false;
109         }
110     }
111 }
112