I would like to know if android devices are locked before creating my appium drivers.
I’ve browse the web to find a solution but I found nothing except that:
KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if( myKM.inKeyguardRestrictedInputMode()) {
//it is locked
} else {
//it is not locked
}
But I don’t know how to retrieve/create the ‘context’ variable.
And I am not sure there is no other way (using adb command maybe) to know if a device is locked.
Configuration:
JAVA jdk 8 multi threading
Appium 1.6.0 and 1.6.4 BETA
OS: MAC
Android real devices
TestNG
Maven
Context:
1 - With adb, retrieve the number of connected device
2 - Start an Appium server per connected devices programmatically
3 - Create an Appium driver per connected devices
4- Start tests
Appium is not able to do that when the device is locked with a PIN, and it’s the case for all the devices I have to test. It’s why I need to know if a device is locked
My question is not how to unlock my devices (with or without PIN), I already have a method to do it,
But how to detect / how to know if a device is locked.
“Key code constant: Wakeup key. Wakes up the device. Behaves somewhat like KEYCODE_POWER but it has no effect if the device is already awake.”
unfortunately it was added on API 20, so I still need to have support for the kitkat devices Don’t know why, but appium started failing alot more on latests versions when unlocking devices (with none security, just sleeping).