1 /* 2 * Copyright (C) 2016 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 android.trustedvoice.app; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.util.Log; 22 import android.app.KeyguardManager; 23 import android.content.Context; 24 import android.view.WindowManager.LayoutParams; 25 import java.lang.Override; 26 27 /** 28 * This activity when in foreground sets the FLAG_DISMISS_KEYGUARD. 29 * It then confirms that the keyguard was successfully dismissed 30 * and logs a string to logcat on success. 31 */ 32 public class TrustedVoiceActivity extends Activity { 33 34 private static final String TAG = TrustedVoiceActivity.class.getSimpleName(); 35 /** 36 * The test string to log. 37 */ 38 private static final String TEST_STRING = "TrustedVoiceTestString"; 39 40 @Override onCreate(Bundle icicle)41 public void onCreate(Bundle icicle) { 42 super.onCreate(icicle); 43 44 // Unlock the keyguard. 45 getWindow().addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD 46 | LayoutParams.FLAG_TURN_SCREEN_ON 47 | LayoutParams.FLAG_KEEP_SCREEN_ON); 48 } 49 50 @Override onWindowFocusChanged(boolean hasFocus)51 public void onWindowFocusChanged(boolean hasFocus) { 52 super.onWindowFocusChanged(hasFocus); 53 if (hasFocus) { 54 // Confirm that the keyguard was successfully unlocked. 55 KeyguardManager kM = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 56 if (!kM.isKeyguardLocked()) { 57 // Log the test string. 58 Log.i(TAG, TEST_STRING); 59 } 60 } 61 } 62 } 63 64