blob: 834d2a5ae4a04dc6cd06c778927415055df809b8 [file] [log] [blame]
Milo Sredkovb0f55e92018-04-04 16:13:28 +01001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.util.Log;
20
Jason Monk297c04e2018-08-23 17:16:59 -040021import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
Milo Sredkovb0f55e92018-04-04 16:13:28 +010022
Jason Monk27d01a622018-12-10 15:57:09 -050023import javax.inject.Inject;
24import javax.inject.Singleton;
25
Milo Sredkovb0f55e92018-04-04 16:13:28 +010026/**
27 * Executes actions that require the screen to be unlocked. Delegates the actual handling to an
28 * implementation passed via {@link #setDismissHandler}.
29 */
Jason Monk27d01a622018-12-10 15:57:09 -050030@Singleton
Milo Sredkovb0f55e92018-04-04 16:13:28 +010031public class KeyguardDismissUtil implements KeyguardDismissHandler {
32 private static final String TAG = "KeyguardDismissUtil";
33
34 private volatile KeyguardDismissHandler mDismissHandler;
35
Jason Monk27d01a622018-12-10 15:57:09 -050036 @Inject
37 public KeyguardDismissUtil() {
38 }
39
Selim Cinekd17b3502019-07-02 20:38:32 -070040 /** Sets the actual {@link KeyguardDismissHandler} implementation. */
Milo Sredkovb0f55e92018-04-04 16:13:28 +010041 public void setDismissHandler(KeyguardDismissHandler dismissHandler) {
42 mDismissHandler = dismissHandler;
43 }
44
45 /**
Dave Mankoffc88d6222018-10-25 15:31:20 -040046 * Executes an action that requires the screen to be unlocked.
Milo Sredkovb0f55e92018-04-04 16:13:28 +010047 *
48 * <p>Must be called after {@link #setDismissHandler}.
Selim Cinekd17b3502019-07-02 20:38:32 -070049 *
50 * @param requiresShadeOpen does the shade need to be forced open when hiding the keyguard?
Milo Sredkovb0f55e92018-04-04 16:13:28 +010051 */
52 @Override
Selim Cinekd17b3502019-07-02 20:38:32 -070053 public void executeWhenUnlocked(OnDismissAction action, boolean requiresShadeOpen) {
Milo Sredkovb0f55e92018-04-04 16:13:28 +010054 KeyguardDismissHandler dismissHandler = mDismissHandler;
55 if (dismissHandler == null) {
56 Log.wtf(TAG, "KeyguardDismissHandler not set.");
57 action.onDismiss();
58 return;
59 }
Selim Cinekd17b3502019-07-02 20:38:32 -070060 dismissHandler.executeWhenUnlocked(action, requiresShadeOpen);
Milo Sredkovb0f55e92018-04-04 16:13:28 +010061 }
62}