Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injecting to another application requires INJECT_EVENT permission #80

Closed
renas opened this issue Aug 19, 2015 · 8 comments
Closed

Injecting to another application requires INJECT_EVENT permission #80

renas opened this issue Aug 19, 2015 · 8 comments

Comments

@renas
Copy link
Contributor

renas commented Aug 19, 2015

From jaglas...@gmail.com on February 21, 2010 23:31:57

I get this error when running the test in the example:

java.lang.SecurityException: Injecting to another application requires
INJECT_EVENT permission
at android.os.Parcel.readException(Parcel.java:1218)
at android.os.Parcel.readException(Parcel.java:1206)
at
android.view.IWindowManager$Stub$Proxy.injectKeyEvent(IWindowManager.java:8
05)
at android.app.Instrumentation.sendKeySync(Instrumentation.java:859)
at android.app.Instrumentation.sendKeyDownUpSync(Instrumentation.java:871)
at com.jayway.android.robotium.solo.Solo.pressMenuItem(Solo.java:556)
at com.jayway.test.NotePadTest.testAddNote(NotePadTest.java:38)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java
:205)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:1
95)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentati
onTestCase2.java:175)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.ja
va:430)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:
1447)

I tried adding the permission to the manifest file, but that did not help.

Original issue: http://code.google.com/p/robotium/issues/detail?id=1

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From renasr...@gmail.com on February 22, 2010 08:58:29

The security exception that you get means that the test cases are trying to interact
with an application that they are not allowed to interact with (e.g. another
application or the platform). This tells me that Note pad does not start when your
test cases start to execute. One example when this can happen is when the emulators
lock screen is active. Then the test cases try to interact with the lock screen
instead and therefore a security exception is thrown.

Can you please make sure that Note pad does indeed start when you select the example
test project and click run application as Android JUnit Test. If it does not start,
try to run Note pad separately by right clicking it and select run as Android
Application. If that is successfull then try to run the test cases again.

If this does not work then please get back to me with more information and observations.

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From jaglass...@gmail.com on February 22, 2010 09:24:01

Thanks for your quick reply. You were correct. This error is occurring because the
lock screen is active. If I unlock the emulator after it starts and then start the
test, it will run.

Is there a solution so that I can run this as an automated test and not have to
manually go to the home screen?

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From jaglas...@gmail.com on February 22, 2010 09:25:27

Sorry, the above reply is from jaglassjr. I was signed into another account.

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From renasr...@gmail.com on February 22, 2010 10:49:44

Once you have unlocked the emulator there is no need to go the home screen. Its just
the first time when you start the emulator that you need to unlock it. Im sure there
must be an adb command that you can send to the emulator in order to unlock it. Try
looking at different adb commands and see if you find one that suites your needs.

Status: Invalid

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From magedark...@gmail.com on October 12, 2010 18:52:04

U can do the following:

KeyguardManager km =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (km.inKeyguardRestrictedInputMode())
{
KeyguardManager.KeyguardLock lock = km.newKeyguardLock("some_tag");
lock.disableKeyguard();
SystemClock.sleep(2000);
}

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From chris@orr.me.uk on October 13, 2010 01:23:18

That's not a very good workaround; it requires adding that code to the application under test and adding the android.permission.DISABLE_KEYGUARD permission to your app.

This is described here: http://developer.android.com/intl/fr/guide/topics/testing/testing_android.html#UnlockDevice Perhaps this is also useful for automatically unlocking the emulator: http://bit.ly/cMrbEM

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From fassi404@gmail.com on November 17, 2010 20:35:28

I am using SMS appliction in my project while testing through robotium when it goes into SMS app it is not coming back to my applicion......if anyone knows solution plz reply as soon as possible.

@renas
Copy link
Contributor Author

renas commented Aug 19, 2015

From zamesIly...@gmail.com on February 26, 2014 01:10:04

I have the same problem but I try to test UI with robotium.
Also I build project with gradle. When I worked with eclipse/IDEA(without gradle) it worked fine.

@renas renas closed this as completed Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant