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
17package com.android.systemui.statusbar.phone;
18
19import android.util.Log;
20
21import com.android.keyguard.KeyguardHostView.OnDismissAction;
22
23/**
24 * Executes actions that require the screen to be unlocked. Delegates the actual handling to an
25 * implementation passed via {@link #setDismissHandler}.
26 */
27public class KeyguardDismissUtil implements KeyguardDismissHandler {
28    private static final String TAG = "KeyguardDismissUtil";
29
30    private volatile KeyguardDismissHandler mDismissHandler;
31
32    /** Sets the actual {@link DismissHandler} implementation. */
33    public void setDismissHandler(KeyguardDismissHandler dismissHandler) {
34        mDismissHandler = dismissHandler;
35    }
36
37    /**
38     * Executes an action that requres the screen to be unlocked.
39     *
40     * <p>Must be called after {@link #setDismissHandler}.
41     */
42    @Override
43    public void executeWhenUnlocked(OnDismissAction action) {
44        KeyguardDismissHandler dismissHandler = mDismissHandler;
45        if (dismissHandler == null) {
46            Log.wtf(TAG, "KeyguardDismissHandler not set.");
47            action.onDismiss();
48            return;
49        }
50        dismissHandler.executeWhenUnlocked(action);
51    }
52}
53