1/*
2 * Copyright (C) 2008 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.internal.policy.impl.keyguard_obsolete;
18
19import com.android.internal.widget.LockPatternUtils;
20
21import android.content.Context;
22import com.android.internal.telephony.IccCardConstants;
23
24/**
25 * Knows how to create a lock pattern keyguard view, and answer questions about
26 * it (even if it hasn't been created, per the interface specs).
27 */
28public class LockPatternKeyguardViewProperties implements KeyguardViewProperties {
29
30    private final LockPatternUtils mLockPatternUtils;
31    private final KeyguardUpdateMonitor mUpdateMonitor;
32
33    /**
34     * @param lockPatternUtils Used to know whether the pattern enabled, and passed
35     *   onto the keygaurd view when it is created.
36     * @param updateMonitor Used to know whether the sim pin is enabled, and passed
37     *   onto the keyguard view when it is created.
38     */
39    public LockPatternKeyguardViewProperties(LockPatternUtils lockPatternUtils,
40            KeyguardUpdateMonitor updateMonitor) {
41        mLockPatternUtils = lockPatternUtils;
42        mUpdateMonitor = updateMonitor;
43    }
44
45    public KeyguardViewBase createKeyguardView(Context context,
46            KeyguardViewCallback callback,
47            KeyguardUpdateMonitor updateMonitor,
48            KeyguardWindowController controller) {
49        return new LockPatternKeyguardView(context, callback, updateMonitor,
50                mLockPatternUtils, controller);
51    }
52
53    public boolean isSecure() {
54        return mLockPatternUtils.isSecure() || isSimPinSecure();
55    }
56
57    private boolean isSimPinSecure() {
58        final IccCardConstants.State simState = mUpdateMonitor.getSimState();
59        return (simState == IccCardConstants.State.PIN_REQUIRED
60                || simState == IccCardConstants.State.PUK_REQUIRED
61                || simState == IccCardConstants.State.PERM_DISABLED);
62    }
63
64}
65