Skip to content

Commit efcb95b

Browse files
committed
feat(android): android:mock_location is only for application package
1 parent f5b1f43 commit efcb95b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/runner/android/configure.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ marathon {
10901090
</Tabs>
10911091

10921092
### Location mock access
1093-
Some tests require mocking device location. Marathon can setup access for instrumentation package if you enable this option as following:
1093+
Some tests require mocking device location. Marathon can setup access for application package if you enable this option as following:
10941094

10951095
<Tabs>
10961096
<TabItem value="YAML" label="Marathonfile">

vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidAppInstaller.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AndroidAppInstaller(configuration: Configuration) {
4141
}
4242
}
4343
reinstall(device, applicationInfo.applicationPackage, applicationApk, bundle.splitApks ?: emptyList())
44+
appops(device, applicationInfo.applicationPackage)
4445
}
4546

4647
bundle.extraApplications?.let { extraApplications ->
@@ -53,22 +54,21 @@ class AndroidAppInstaller(configuration: Configuration) {
5354

5455
logger.debug { "Installing instrumentation package to ${device.serialNumber}" }
5556
reinstall(device, applicationInfo.instrumentationPackage, bundle.testApplication)
56-
appops(device, applicationInfo.instrumentationPackage)
5757
logger.debug { "Prepare installation finished for ${device.serialNumber}" }
5858
}
5959

60-
private suspend fun appops(device: AndroidDevice, instrumentationPackage: String) {
60+
private suspend fun appops(device: AndroidDevice, applicationPackage: String) {
6161
if (androidConfiguration.mockLocation) {
6262
if (device.apiLevel < 23) {
6363
logger.warn { "Can't setup mock location: device ${device.serialNumber} doesn't support appops" }
6464
return
6565
}
6666

67-
val appopsMessage = device.criticalExecuteShellCommand("appops set $instrumentationPackage android:mock_location allow")
67+
val appopsMessage = device.criticalExecuteShellCommand("appops set $applicationPackage android:mock_location allow")
6868
appopsMessage.let {
6969
if (it.exitCode != 0) {
7070
val (output, _) = device.criticalExecuteShellCommand("appops query-op android:mock_location allow")
71-
logger.error { "Can't set android:mock_location on $instrumentationPackage. List of apps currently using android:mock_location:$output" }
71+
logger.error { "Can't set android:mock_location on $applicationPackage. List of apps currently using android:mock_location:$output" }
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)