I need android.permission.WRITE_SETTINGS for my Android application’s junit tests. I am using IntelliJ Idea 11.1.2 and the unit tests in their own module, which contains second AndroidManifest.xml for the tests.
I added <uses-permission android:name="android.permission.WRITE_SETTINGS" /> to the test module’s AndroidManifest.xml.
Error:java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=1063, uid=10035 requires android.permission.WRITE_SETTINGS
Ugly quick fix: I add the same permission also to the application’s AndroidManifest.xml. Tests run without a single error.
The problem: I DO NOT want to give the whole application permission to change settings.
Is there a way to give permissions only for the tests?
Is there a way to give permissions only for the tests?
Short answer is no.
Your Android Test Project and Android Application Project are actually two applications, with test.apk instruments app.apk and run time. <uses-permission> is per application, added it to the test project’s AndroidManifest.xml only gives required permission to test.apk, not the application under testing i.e. app.apk.