Skip to content

Commit

Permalink
feat(android): android:mock_location is only for application package
Browse files Browse the repository at this point in the history
  • Loading branch information
matzuk committed Dec 13, 2024
1 parent f5b1f43 commit efcb95b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/runner/android/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ marathon {
</Tabs>

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

<Tabs>
<TabItem value="YAML" label="Marathonfile">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AndroidAppInstaller(configuration: Configuration) {
}
}
reinstall(device, applicationInfo.applicationPackage, applicationApk, bundle.splitApks ?: emptyList())
appops(device, applicationInfo.applicationPackage)
}

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

logger.debug { "Installing instrumentation package to ${device.serialNumber}" }
reinstall(device, applicationInfo.instrumentationPackage, bundle.testApplication)
appops(device, applicationInfo.instrumentationPackage)
logger.debug { "Prepare installation finished for ${device.serialNumber}" }
}

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

val appopsMessage = device.criticalExecuteShellCommand("appops set $instrumentationPackage android:mock_location allow")
val appopsMessage = device.criticalExecuteShellCommand("appops set $applicationPackage android:mock_location allow")
appopsMessage.let {
if (it.exitCode != 0) {
val (output, _) = device.criticalExecuteShellCommand("appops query-op android:mock_location allow")
logger.error { "Can't set android:mock_location on $instrumentationPackage. List of apps currently using android:mock_location:$output" }
logger.error { "Can't set android:mock_location on $applicationPackage. List of apps currently using android:mock_location:$output" }
}
}
}
Expand Down

0 comments on commit efcb95b

Please sign in to comment.