Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 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 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 21 | import com.android.systemui.plugins.ActivityStarter.OnDismissAction; |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 22 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Singleton; |
| 25 | |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 26 | /** |
| 27 | * Executes actions that require the screen to be unlocked. Delegates the actual handling to an |
| 28 | * implementation passed via {@link #setDismissHandler}. |
| 29 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 30 | @Singleton |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 31 | public class KeyguardDismissUtil implements KeyguardDismissHandler { |
| 32 | private static final String TAG = "KeyguardDismissUtil"; |
| 33 | |
| 34 | private volatile KeyguardDismissHandler mDismissHandler; |
| 35 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 36 | @Inject |
| 37 | public KeyguardDismissUtil() { |
| 38 | } |
| 39 | |
Selim Cinek | d17b350 | 2019-07-02 20:38:32 -0700 | [diff] [blame] | 40 | /** Sets the actual {@link KeyguardDismissHandler} implementation. */ |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 41 | public void setDismissHandler(KeyguardDismissHandler dismissHandler) { |
| 42 | mDismissHandler = dismissHandler; |
| 43 | } |
| 44 | |
| 45 | /** |
Dave Mankoff | c88d622 | 2018-10-25 15:31:20 -0400 | [diff] [blame] | 46 | * Executes an action that requires the screen to be unlocked. |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 47 | * |
| 48 | * <p>Must be called after {@link #setDismissHandler}. |
Selim Cinek | d17b350 | 2019-07-02 20:38:32 -0700 | [diff] [blame] | 49 | * |
| 50 | * @param requiresShadeOpen does the shade need to be forced open when hiding the keyguard? |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 51 | */ |
| 52 | @Override |
Selim Cinek | d17b350 | 2019-07-02 20:38:32 -0700 | [diff] [blame] | 53 | public void executeWhenUnlocked(OnDismissAction action, boolean requiresShadeOpen) { |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 54 | KeyguardDismissHandler dismissHandler = mDismissHandler; |
| 55 | if (dismissHandler == null) { |
| 56 | Log.wtf(TAG, "KeyguardDismissHandler not set."); |
| 57 | action.onDismiss(); |
| 58 | return; |
| 59 | } |
Selim Cinek | d17b350 | 2019-07-02 20:38:32 -0700 | [diff] [blame] | 60 | dismissHandler.executeWhenUnlocked(action, requiresShadeOpen); |
Milo Sredkov | b0f55e9 | 2018-04-04 16:13:28 +0100 | [diff] [blame] | 61 | } |
| 62 | } |