How can I dismiss the android keyguard using adb intent - android

I am looking for a way to use ADB to dismiss the keyguard in order to automate some tasks.
I would like to start an ACTIVITY (perhaps to call the public method disableKeyguard in android.app.KeyguardManager.KeyguardLock), because I assume that it will work on all (or most) Android devices, but I am unsure of the syntax.
I do not wish to use MonkeyRunner, because it is not present (or perhaps, callable) on all devices. I also cannot send a MENU keycode (adb shell input keycode 82), because this does not dismiss the keyguard on all devices.
Currently I am sending events (low-level touch events), but this needs to be customized for each device, so it is a time consuming task.
Does anyone have a suggestion?

The "Activity Testing" article has a section called Unlocking the emulator or device that addresses this situation.
In short, there isn't a way to do it directly with adb but using disableKeyguard() isn't complicated (see the three lines of example code in the article linked to above). You could easily put together a little app that does nothing but disable the keyguard. It would then just be a matter of
adb install <apk>
adb shell am start <package>/.<activity>
# Whatever you need to automate
adb uninstall <package>
(Where <apk>, <package>, and <activity> all refer to the tiny app that just disables the keyguard.)

Related

Detecting the Android keyboard with Calabash?

I am writing a series of automated tests for an android app using calabash-android and I need to be able to detect whether the android system keyboard is visible or not and (if possible) read some of the keys (i.e. if the return key says Done instead of Next or Enter). I know there is the keyboard_visible? commands for iOS but I have not been able to find anything similar for android.
Has anyone built their own functions to handle these instances?
there is a way to take a dump of the screens current contents on android using a tool called uiautomator from the android SDK. You can then check this for whatever you need to. It's not the most elegant solution but it might just work. Have a look at this post.
Calabash handling "Complete action using" dialog
windown_input_method = %x(adb -s #{ENV['ADB_DEVICE_ARG']} shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")
This one returns true if keyboard is visible and false if not
ENV['ADB_DEVICE_ARG'] is environmental variable holding the device id of your android device connected. If you always run on one device, simply
windown_input_method = %x(adb shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")
will do

How to avoid lock screen event during monkey test

i am running monkey tests and i am facing issues with lock screen.
i have tried running tests with default command as below
"monkey -p com.xyz -v 1500000 -s 10000 --throttle 15000"
The tests start fine but eventually get to lock screen and thereby never able to unlock as i have alphanumeric key code as password which is very hard to guess by random events of monkey.
i just want the monkey to run only on app and ignore the lock screen events completely
i am enabling Never go to sleep from settings, please let me know if i can avoid monkey to stop pressing the power key.
You should write your own python script. Please take a look at a simple monkeyrunner program from Android doc and an example from this tutorial. When you write the sript don't use these types of events:
device.press('KEYCODE_POWER', 'DOWN_AND_UP')
device.press('KEYCODE_POWER', 'DOWN')
device.press('KEYCODE_POWER', 'UP')
which are reponsible for screen lock (more key codes). In order to run your own script use:
mokeyrunner srcipt_name.py
Another solution could be avoiding s (pseudo-random number generator) flag in adb shell monkey command. Then use interesting flags except for --pct-syskeys (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.) More flags you find in http://developer.android.com/tools/help/monkey.html

Shell script run through runtime.exec() behaves differently than if I run it through terminal

I have this snippet of shell script:
am start -n com.android.gallery3d/com.android.gallery3d.app.MovieActivity -d /sdcard/movie.mp4
sleep 5
input keyevent 4
This script basically reads as follow:
1. Open the gallery application to start movie.mp4
2. Sleep 5 seconds
3. Press back key
When I run this script through adb shell, things work out as expected which is the video plays only for the first 5 seconds and then the back key is pressed which essentially quits the gallery app.
However, when I run this though runtime.exec()
The gallery does start, but then nothing else happen. It seems like the system prevents me from running the script when the application is in the background.
Anybody happens to know any work around? Or is there any way to use INTENT to achieve the same result?
Thanks in advance
A script run by an application runs as the application userid, which does not have the extra
debug privileges that the adb shell (running as shell or even root) does.
For security reasons, applications are not supposed to be able to feed fake keystrokes to other applications and especially not to the system itself.
Perhaps instead of backing out of the gallery, you should try to start something else with an Intent.

Stop running application with ADB

is there a simple way to stop a running application using ADB.
Szenario:
Working on App
Have a script which uploads, installs and starts App on change
Problem:
Currently running version gets killed (not shutdown), which make testing cleanup very hard. Option would be to "do cleanup in between", like after a certain time, but I would prefer to do it in the correct location (so like with the OS, as long as the App is still running, so need to save value, as soon as the OS tells me e.g. memory low or calls onDestroy, I want to save stuff)
Chris
I'm not aware of a way to do this. I was hoping there might be a way to send an intent to tell the app to exit using adb shell e.g.
adb shell am start -a [intent] -n [class]
However, I found that somebody asked this question on a Google forum but they haven't got an answer:
http://groups.google.com/group/android-platform/browse_thread/thread/3fd02d01c6c3b41a/56814e518503efd6

Android.test.TouchUtils methods don't work on headless emulator, help!

I'm trying to get my Android tests running on headless emulator for future use on CI servers.
But non of the TouchUtils methods, like "clickView()" etc.. seem work this way.
I'm always getting SecurityException:
"Injecting to another application requires INJECT_EVENTS permission".
Looks like it doesn't click the right objects in the first place. In normal GUI mode everything works fine.
Is there any way around this?
If no, which setup would you recommend to run all the tests on remote machines?
Thank you!
The device is probably showing the lock screen. Check it with the hierarchyviewer or screenshot2.
You can unlock the screen by sending a menu button, for instance by using adb:
adb shell input keyevent 82
(The keyevent code can be found in android.view.KeyEvent.)

Categories

Resources