Skip to content

Commit

Permalink
Improve set permissions logs and avoid affecting location permissions (
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 authored Jan 8, 2025
1 parent 4c71c7b commit eadbad8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
11 changes: 7 additions & 4 deletions maestro-ios-driver/src/main/kotlin/util/LocalSimulatorUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ object LocalSimulatorUtils {
)
}

fun setPermissions(deviceId: String, bundleId: String, permissions: Map<String, String>) {
fun setAppleSimutilsPermissions(deviceId: String, bundleId: String, permissions: Map<String, String>) {
val permissionsMap = permissions.toMutableMap()
if (permissionsMap.containsKey("all")) {
val value = permissionsMap.remove("all")
Expand All @@ -437,6 +437,7 @@ object LocalSimulatorUtils {

if (permissionsArgument.isNotEmpty()) {
try {
logger.info("[Start] Setting permissions via pinned applesimutils")
runCommand(
listOf(
"$homedir/.maestro/deps/applesimutils",
Expand All @@ -448,7 +449,10 @@ object LocalSimulatorUtils {
permissionsArgument
)
)
logger.info("[Done] Setting permissions pinned applesimutils")
} catch (e: Exception) {
logger.error("Exception while setting permissions through pinned applesimutils ${e.message}", e)
logger.info("[Start] Setting permissions via applesimutils as fallback")
runCommand(
listOf(
"applesimutils",
Expand All @@ -460,13 +464,12 @@ object LocalSimulatorUtils {
permissionsArgument
)
)
logger.info("[Done] Setting permissions via applesimutils as fallback")
}
}

setSimctlPermissions(deviceId, bundleId, permissions)
}

private fun setSimctlPermissions(deviceId: String, bundleId: String, permissions: Map<String, String>) {
fun setSimctlPermissions(deviceId: String, bundleId: String, permissions: Map<String, String>) {
val permissionsMap = permissions.toMutableMap()

permissionsMap.remove("all")?.let { value ->
Expand Down
21 changes: 20 additions & 1 deletion maestro-ios/src/main/java/ios/simctl/SimctlIOSDevice.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ios.simctl

import com.github.michaelbull.result.Result
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.runCatching
import hierarchy.ViewHierarchy
import ios.IOSDevice
Expand All @@ -9,6 +10,7 @@ import xcuitest.api.DeviceInfo
import okio.Sink
import okio.buffer
import okio.source
import org.slf4j.LoggerFactory
import util.IOSLaunchArguments.toIOSLaunchArguments
import util.LocalSimulatorUtils
import java.io.File
Expand All @@ -20,6 +22,11 @@ import java.util.UUID
class SimctlIOSDevice(
override val deviceId: String,
) : IOSDevice {

companion object {
private val logger = LoggerFactory.getLogger(SimctlIOSDevice::class.java)
}

private var screenRecording: LocalSimulatorUtils.ScreenRecording? = null

override fun open() {
Expand Down Expand Up @@ -161,7 +168,19 @@ class SimctlIOSDevice(
}

override fun setPermissions(id: String, permissions: Map<String, String>) {
LocalSimulatorUtils.setPermissions(deviceId, id, permissions)
val formattedPermissions = permissions.entries.joinToString(separator = ", ") { "${it.key}=${it.value}" }

runCatching {
logger.info("[Start] Setting permissions $formattedPermissions through applesimutils")
LocalSimulatorUtils.setAppleSimutilsPermissions(deviceId, id, permissions)
logger.info("[Done] Setting permissions through applesimutils")
}.onFailure {
logger.error("Failed setting permissions $permissions via applesimutils", it)
}

logger.info("[Start] Setting Permissions $formattedPermissions through simctl")
LocalSimulatorUtils.setSimctlPermissions(deviceId, id, permissions)
logger.info("[Done] Setting Permissions $formattedPermissions through simctl")
}

override fun eraseText(charactersToErase: Int) {
Expand Down

0 comments on commit eadbad8

Please sign in to comment.