Hello guys,
I’ve been trying to run some calaba.sh tests in an Android application a couple of days ago, playing with CircleCI, learning about that and figuring out how it works. Initially, my tests weren’t running because this exception…
Failed to perform gesture. java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
…was raising once the test was trying to interact with the emulator, i.e., touching a button. I researched about that issue and it normally is raised when there is another application or some other layout above which belongs to some other application we are not testing (keyboard, system dialog, etc).
I tried to debug it with many methods, using some adb
commands, but I wasn’t finding any clue that was causing that issue. Finally, among many researches and shell commands, I found a command that gives you the foreground application and the element that is being focused, I used that while debugging via SSH and I could realize that the emulator was showing a system dialog telling that “Process system isn’t responding”, but the problem is that the dialog is being shown right after the device is turned on (without launching my app).
Here are the steps I followed:
- Commited a project with this
circle.yml
file:
general:
branches:
only:
- master
- develop
artifacts:
- /home/ubuntu/my_project/app/build/outputs/apk/
- /home/ubuntu/my_project/app/src/androidTest/functionalTestReport.html
- /home/ubuntu/my_project/app/src/androidTest/screenshot_*.png
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
QEMU_AUDIO_DRV: none
ruby:
version: 2.3.1 # I use a local ruby server to test API calls (mock_server)
dependencies:
override:
- gem install bundler
- bundle install:
pwd: app/src/androidTest/mock_server
- gem install calabash-android
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-25.0.2,android-25,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- ./gradlew dependencies
- ./gradlew assemble
test:
pre:
- emulator -avd circleci-android24 -no-window:
background: true
parallel: true
- circle-android wait-for-boot
override:
- echo Hi there
- Waited for the emulator to boot
- Connected via SSH
- Run following commands:
$ adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
> mCurrentFocus=Window{4200361 u0 KeyguardScrim}
> mFocusedApp=AppWindowToken{9bdc296 token=Token{f94d858 ActivityRecord{c61c93b u0 com.android.launcher3/.Launcher t3}}}
$ adb shell input keyevent 82 # To unlock the device | open apps menu
$ adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
> mCurrentFocus=Window{439cb3b u0 Application Not Responding: system} # I noticed here the "Application Not Responding", tried to get a Screenshot but each time I was getting a 0 bytes file. Well, that issue is in other hand.
> mFocusedApp=AppWindowToken{9bdc296 token=Token{f94d858 ActivityRecord{c61c93b u0 com.android.launcher3/.Launcher t3}}}
- At this point, my previous
circle.yml
file which were running tests, all would fail, because of theSecurityException
described. So I preferred to try closing that dialog and running tests manually.
$ adb root
> restarting adbd as root
$ adb shell uiautomator dump /data/view.xml # to dump current emulator UI hierarchy in a file.
> UI hierchary dumped to: /data/view.xml
$ adb shell cat /data/view.xml
> # Returned the XML formatted below
---
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,256][480,579]">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,280][456,555]">
<node index="0" text="" resource-id="android:id/content" class="android.widget.FrameLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,280][456,555]">
<node index="0" text="" resource-id="android:id/parentPanel" class="android.widget.LinearLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,280][456,555]">
<node index="0" text="" resource-id="android:id/topPanel" class="android.widget.LinearLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,280][456,376]">
<node index="0" text="" resource-id="android:id/title_template" class="android.widget.LinearLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,280][456,376]">
<node index="0" text="Process system isn't responding" resource-id="android:id/alertTitle" class="android.widget.TextView" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[60,307][420,376]" /></node>
</node>
<node index="1" text="" resource-id="android:id/customPanel" class="android.widget.FrameLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,376][456,555]">
<node index="0" text="" resource-id="android:id/custom" class="android.widget.FrameLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,376][456,555]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="android" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,376][456,555]">
<node index="0" text="Close app" resource-id="android:id/aerr_close" class="android.widget.Button" package="android" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,399][456,471]" />
<node index="1" text="Wait" resource-id="android:id/aerr_wait" class="android.widget.Button" package="android" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,471][456,543]" /></node>
</node>
</node>
</node>
</node>
</node>
</node>
</hierarchy>
- In the previous XML, I noticed the alert message, which is “Process system isn’t responding”, and took the “Close app” button coordinates, to manually close it.
$ adb shell input touchscreen swipe 24 399 25 399
$ adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
> mCurrentFocus=Window{f1c8384 u0 com.android.launcher3/com.android.launcher3.Launcher}
> mFocusedApp=AppWindowToken{9bdc296 token=Token{f94d858 ActivityRecord{c61c93b u0 com.android.launcher3/.Launcher t3}}}
- Finally, I run calabash tests and now I wasn’t getting the
SecurityException
, tests were running normally. Yay!
My question is: is that a normal behaviour? How to avoid that issue?
Note: I’ve seen in many community posts that people use fb-adb shell input touchscreen swipe 370 735 371 735
after adb shell input keyevent 82
, I don’t know if that is related with the issue I’m having or not, because I actually added that line and I didn’t work.
Note2: Seems that this guy posted the the same issue in a blog (http://blog.mohitkanwal.com/blog/2015/12/23/troubleshooting-android-emulators-on-circleci/), he could get a screenshot of the emulator state, in my case taking a screenshot gives a IO Exception: EOF
.
Thanks in advance.