Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 com.android.tradefed.suite.checker; |
| 17 | |
| 18 | import com.android.ddmlib.Log.LogLevel; |
| 19 | import com.android.tradefed.device.DeviceNotAvailableException; |
| 20 | import com.android.tradefed.device.ITestDevice; |
| 21 | import com.android.tradefed.log.LogUtil.CLog; |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 22 | import com.android.tradefed.suite.checker.StatusCheckerResult.CheckStatus; |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 23 | import com.android.tradefed.util.KeyguardControllerState; |
| 24 | |
Julien Desprez | 510a483 | 2017-01-27 11:58:17 +0000 | [diff] [blame] | 25 | /** Checks the keyguard status after module execution. */ |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 26 | public class KeyguardStatusChecker implements ISystemStatusChecker { |
| 27 | |
| 28 | private boolean mIsKeyguardShowing; |
| 29 | private boolean mIsKeyguardOccluded; |
| 30 | |
| 31 | /** {@inheritDoc} */ |
| 32 | @Override |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 33 | public StatusCheckerResult postExecutionCheck(ITestDevice device) |
| 34 | throws DeviceNotAvailableException { |
| 35 | StatusCheckerResult result = new StatusCheckerResult(CheckStatus.SUCCESS); |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 36 | // We assume keyguard was dismissed before the module. |
| 37 | KeyguardControllerState ksc = device.getKeyguardState(); |
Julien Desprez | 510a483 | 2017-01-27 11:58:17 +0000 | [diff] [blame] | 38 | if (ksc == null) { |
| 39 | // for compatibility |
| 40 | CLog.logAndDisplay( |
| 41 | LogLevel.DEBUG, |
| 42 | "KeyguardControllerState is not supported by the " |
| 43 | + "device. Skipping System Checker."); |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 44 | return result; |
Julien Desprez | 510a483 | 2017-01-27 11:58:17 +0000 | [diff] [blame] | 45 | } |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 46 | mIsKeyguardShowing = ksc.isKeyguardShowing(); |
| 47 | mIsKeyguardOccluded = ksc.isKeyguardOccluded(); |
| 48 | if (mIsKeyguardShowing || mIsKeyguardOccluded) { |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 49 | String message = |
| 50 | String.format( |
| 51 | "SystemChecker - post-execution:\n" + "\tKeyguard on: %s, occluded: %s", |
| 52 | mIsKeyguardShowing, mIsKeyguardOccluded); |
| 53 | CLog.logAndDisplay(LogLevel.WARN, message); |
Guang Zhu | 03c985e | 2017-04-28 14:53:55 -0700 | [diff] [blame] | 54 | // best effort to dismiss keyguard: will not work if a secured keyguard was left around |
| 55 | CLog.w("Also attempting to dismiss keyguard."); |
| 56 | device.disableKeyguard(); |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 57 | result.setStatus(CheckStatus.FAILED); |
| 58 | result.setErrorMessage(message); |
| 59 | return result; |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 60 | } |
Julien Desprez | 3e4d47d | 2018-05-23 15:53:40 -0700 | [diff] [blame] | 61 | return result; |
Julien Desprez | 0e84933 | 2017-01-18 12:22:30 +0000 | [diff] [blame] | 62 | } |
| 63 | } |