1 /*
2  * Copyright (C) 2018 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.statusbar.phone;
18 
19 import android.util.Log;
20 
21 import com.android.systemui.dagger.SysUISingleton;
22 import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
23 
24 import javax.inject.Inject;
25 
26 /**
27  * Executes actions that require the screen to be unlocked. Delegates the actual handling to an
28  * implementation passed via {@link #setDismissHandler}.
29  */
30 @SysUISingleton
31 public class KeyguardDismissUtil implements KeyguardDismissHandler {
32     private static final String TAG = "KeyguardDismissUtil";
33 
34     private volatile KeyguardDismissHandler mDismissHandler;
35 
36     @Inject
KeyguardDismissUtil()37     public KeyguardDismissUtil() {
38     }
39 
40     /** Sets the actual {@link KeyguardDismissHandler} implementation. */
setDismissHandler(KeyguardDismissHandler dismissHandler)41     public void setDismissHandler(KeyguardDismissHandler dismissHandler) {
42         mDismissHandler = dismissHandler;
43     }
44 
45     /**
46      * Executes an action that requires the screen to be unlocked.
47      *
48      * <p>Must be called after {@link #setDismissHandler}.
49      *
50      * @param requiresShadeOpen does the shade need to be forced open when hiding the keyguard?
51      */
52     @Override
executeWhenUnlocked(OnDismissAction action, boolean requiresShadeOpen, boolean afterKeyguardGone)53     public void executeWhenUnlocked(OnDismissAction action, boolean requiresShadeOpen,
54             boolean afterKeyguardGone) {
55         KeyguardDismissHandler dismissHandler = mDismissHandler;
56         if (dismissHandler == null) {
57             Log.wtf(TAG, "KeyguardDismissHandler not set.");
58             action.onDismiss();
59             return;
60         }
61         dismissHandler.executeWhenUnlocked(action, requiresShadeOpen, afterKeyguardGone);
62     }
63 }
64