1a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su/*
2a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * Copyright (C) 2008 The Android Open Source Project
3a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su *
4a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * Licensed under the Apache License, Version 2.0 (the "License");
5a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * you may not use this file except in compliance with the License.
6a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * You may obtain a copy of the License at
7a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su *
8a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su *      http://www.apache.org/licenses/LICENSE-2.0
9a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su *
10a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * Unless required by applicable law or agreed to in writing, software
11a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * distributed under the License is distributed on an "AS IS" BASIS,
12a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * See the License for the specific language governing permissions and
14a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su * limitations under the License.
15a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su */
16a9e8720929c3d7978b2768319a9a6eea53233b4fScott Supackage android.app.cts;
17a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su
18a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.app.Activity;
19a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.app.KeyguardManager;
20a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.content.Context;
21a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.os.Bundle;
22a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.util.Log;
23a9e8720929c3d7978b2768319a9a6eea53233b4fScott Suimport android.view.KeyEvent;
24a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su
25a9e8720929c3d7978b2768319a9a6eea53233b4fScott Supublic class KeyguardManagerActivity extends Activity {
26a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    private static final String TAG = "KeyguardManagerActivity";
27a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    public static final boolean DEBUG = false;
28a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    private KeyguardManager mKeyguardManager;
29a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    private KeyguardManager.KeyguardLock mKeyLock;
30a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    public int keyCode;
31a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    @Override
32a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    protected void onCreate(Bundle savedInstanceState) {
33a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        super.onCreate(savedInstanceState);
34a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
35a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        mKeyLock = null;
36a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    }
37a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su
38a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    @Override
39a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    protected void onResume() {
40a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        super.onResume();
41a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        if (DEBUG) {
42a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            Log.d(TAG, "onResume");
43a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        }
44a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        if (mKeyLock == null) {
45a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            mKeyLock = mKeyguardManager.newKeyguardLock(TAG);
46a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            mKeyLock.disableKeyguard();
47a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            if (DEBUG) {
48a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su                Log.d(TAG, "disableKeyguard");
49a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            }
50a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        }
51a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    }
52a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su
53a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    @Override
54a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    public boolean onKeyDown(int keyCode, KeyEvent event) {
55a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        this.keyCode = keyCode;
56a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        if (keyCode == KeyEvent.KEYCODE_0 && mKeyLock != null) {
57a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            mKeyLock.reenableKeyguard();
58a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            mKeyLock = null;
59a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            if (DEBUG) {
60a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su                Log.d(TAG, "reenableKeyguard");
61a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            }
62a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        }
63a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        if (DEBUG) {
64a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su            Log.d(TAG, "onKeyDown");
65a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        }
66a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su        return super.onKeyDown(keyCode, event);
67a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su    }
68a9e8720929c3d7978b2768319a9a6eea53233b4fScott Su}
69