• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.app.cts;
17 
18 import android.app.Activity;
19 import android.app.KeyguardManager;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.util.Log;
23 import android.view.KeyEvent;
24 
25 public class KeyguardManagerActivity extends Activity {
26     private static final String TAG = "KeyguardManagerActivity";
27     public static final boolean DEBUG = false;
28     private KeyguardManager mKeyguardManager;
29     private KeyguardManager.KeyguardLock mKeyLock;
30     public int keyCode;
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34         mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
35         mKeyLock = null;
36     }
37 
38     @Override
onResume()39     protected void onResume() {
40         super.onResume();
41         if (DEBUG) {
42             Log.d(TAG, "onResume");
43         }
44         if (mKeyLock == null) {
45             mKeyLock = mKeyguardManager.newKeyguardLock(TAG);
46             mKeyLock.disableKeyguard();
47             if (DEBUG) {
48                 Log.d(TAG, "disableKeyguard");
49             }
50         }
51     }
52 
53     @Override
onKeyDown(int keyCode, KeyEvent event)54     public boolean onKeyDown(int keyCode, KeyEvent event) {
55         this.keyCode = keyCode;
56         if (keyCode == KeyEvent.KEYCODE_0 && mKeyLock != null) {
57             mKeyLock.reenableKeyguard();
58             mKeyLock = null;
59             if (DEBUG) {
60                 Log.d(TAG, "reenableKeyguard");
61             }
62         }
63         if (DEBUG) {
64             Log.d(TAG, "onKeyDown");
65         }
66         return super.onKeyDown(keyCode, event);
67     }
68 }
69