From fb8c4746b5a944ddf94ed23200e75317b768b5b5 Mon Sep 17 00:00:00 2001 From: amin Date: Mon, 1 Mar 2021 04:27:07 +0300 Subject: [PATCH] Switch layout bounds added as a new command first I check `getprop debug.layout` to see if it is on or not, and then I call `setprop debug.layout false/true` and using `service call activity 1599295570` I poke the system to refresh settings https://susuthapa19961227.medium.com/enable-layout-debugging-in-android-using-adb-64016d755441 --- .../adbidea/action/SwitchLayoutBounds.kt | 9 +++++ .../developerphil/adbidea/adb/AdbFacade.kt | 1 + .../adb/command/SwitchLayoutBoundsCommand.kt | 37 +++++++++++++++++++ .../adb/command/receiver/ResponseReceiver.kt | 24 ++++++++++++ src/main/resources/META-INF/plugin.xml | 6 +++ 5 files changed, 77 insertions(+) create mode 100644 src/main/kotlin/com/developerphil/adbidea/action/SwitchLayoutBounds.kt create mode 100644 src/main/kotlin/com/developerphil/adbidea/adb/command/SwitchLayoutBoundsCommand.kt create mode 100644 src/main/kotlin/com/developerphil/adbidea/adb/command/receiver/ResponseReceiver.kt diff --git a/src/main/kotlin/com/developerphil/adbidea/action/SwitchLayoutBounds.kt b/src/main/kotlin/com/developerphil/adbidea/action/SwitchLayoutBounds.kt new file mode 100644 index 00000000..4e0f7f3c --- /dev/null +++ b/src/main/kotlin/com/developerphil/adbidea/action/SwitchLayoutBounds.kt @@ -0,0 +1,9 @@ +package com.developerphil.adbidea.action + +import com.developerphil.adbidea.adb.AdbFacade +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.project.Project + +class SwitchLayoutBounds : AdbAction() { + override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.switchLayoutBounds(project) +} diff --git a/src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt b/src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt index e9a506f3..4e9c7874 100644 --- a/src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt +++ b/src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt @@ -28,6 +28,7 @@ object AdbFacade { fun disableWifi(project: Project) = executeOnDevice(project, ToggleSvcCommand(WIFI, false)) fun enableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, true)) fun disableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, false)) + fun switchLayoutBounds(project: Project) = executeOnDevice(project, SwitchLayoutBoundsCommand()) private fun executeOnDevice(project: Project, runnable: Command) { if (AdbUtil.isGradleSyncInProgress(project)) { diff --git a/src/main/kotlin/com/developerphil/adbidea/adb/command/SwitchLayoutBoundsCommand.kt b/src/main/kotlin/com/developerphil/adbidea/adb/command/SwitchLayoutBoundsCommand.kt new file mode 100644 index 00000000..dae8560b --- /dev/null +++ b/src/main/kotlin/com/developerphil/adbidea/adb/command/SwitchLayoutBoundsCommand.kt @@ -0,0 +1,37 @@ +package com.developerphil.adbidea.adb.command + +import com.android.ddmlib.IDevice +import com.developerphil.adbidea.adb.command.receiver.GenericReceiver +import com.developerphil.adbidea.adb.command.receiver.ResponseHolder +import com.developerphil.adbidea.adb.command.receiver.ResponseReceiver +import com.developerphil.adbidea.ui.NotificationHelper.error +import com.developerphil.adbidea.ui.NotificationHelper.info +import com.intellij.openapi.project.Project +import org.jetbrains.android.facet.AndroidFacet +import java.util.concurrent.TimeUnit + + + +class SwitchLayoutBoundsCommand() : Command { + + + override fun run(project: Project, device: IDevice, facet: AndroidFacet, packageName: String): Boolean { + try { + val receiver = ResponseHolder() + device.executeShellCommand("getprop debug.layout", ResponseReceiver(receiver), 30L, TimeUnit.SECONDS) + val isAlreadyOn = receiver.response.contains("true") + val cmd = if(isAlreadyOn){ + "setprop debug.layout false && service call activity 1599295570" //SYSPROPS_TRANSACTION + } else { + "setprop debug.layout true && service call activity 1599295570" //SYSPROPS_TRANSACTION + } + device.executeShellCommand(cmd, ResponseReceiver(receiver), 30L, TimeUnit.SECONDS) + + info(String.format("%s on %s", if(isAlreadyOn)"Hide layout bound" else "Show layout bound", device.name)) + return true + } catch (e: Exception) { + error("Failure while attempting to switch layout bounds on ${device.name}: " + e.message) + } + return false + } +} diff --git a/src/main/kotlin/com/developerphil/adbidea/adb/command/receiver/ResponseReceiver.kt b/src/main/kotlin/com/developerphil/adbidea/adb/command/receiver/ResponseReceiver.kt new file mode 100644 index 00000000..2b02456b --- /dev/null +++ b/src/main/kotlin/com/developerphil/adbidea/adb/command/receiver/ResponseReceiver.kt @@ -0,0 +1,24 @@ +package com.developerphil.adbidea.adb.command.receiver + +import com.android.ddmlib.MultiLineReceiver +import java.util.* +import java.util.regex.Pattern + +data class ResponseHolder(var response: String = "") + +class ResponseReceiver(val responseHolder: ResponseHolder) : MultiLineReceiver() { + + val adbOutputLines: MutableList = ArrayList() + + override fun processNewLines(lines: Array) { + adbOutputLines.addAll(listOf(*lines)) + for (line in lines) { + if (line.isNotEmpty()) { + responseHolder.response += "$line\n" + } + } + } + + override fun isCancelled() = false + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d2d871d6..57a5e8c1 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -251,6 +251,12 @@ description="Disable mobile data on device or emulator"> + + +