I'd like to add android.permission.PACKAGE_USAGE_STATS to let the test app know when the target app com.example.dummy is running or not. I added a separate AndroidManifest.xml file to androidTest folder with the following lines:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.dummy.test">
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
</manifest>
and in gradle file:
sourceSets {
androidTest {
manifest.srcFile 'src/androidTest/AndroidManifest.xml'
}
}
and now I try to use "pm grant" just to see whether or not I can grant android.permission.PACKAGE_USAGE_STATS to test app:
adb shell pm grant com.example.dummy.test android.permission.PACKAGE_USAGE_STATS
The problem - I get the following error:
Operation not allowed: java.lang.SecurityException: Package com.example.dummy.test has not requested permission android.permission.PACKAGE_USAGE_STATS
The question is how can I add this permission only to androidTest correctly, i.e. so this permission will be available for com.example.dummy.test package?