Skip to content

Commit aa8a15e

Browse files
committed
Fix an issue where the debugger would fail to attach on Android Studio 3.6
1 parent 9e2d922 commit aa8a15e

File tree

1 file changed

+27
-3
lines changed
  • src/main/kotlin/com/developerphil/adbidea/debugger

1 file changed

+27
-3
lines changed

src/main/kotlin/com/developerphil/adbidea/debugger/Debugger.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import com.android.ddmlib.Client
44
import com.android.ddmlib.IDevice
55
import com.android.tools.idea.run.AndroidProcessHandler
66
import com.android.tools.idea.run.editor.AndroidDebugger
7+
import com.developerphil.adbidea.compatibility.BackwardCompatibleGetter
78
import com.developerphil.adbidea.invokeLater
89
import com.developerphil.adbidea.waitUntil
910
import com.intellij.execution.ExecutionManager
1011
import com.intellij.execution.process.ProcessOutputTypes
1112
import com.intellij.openapi.project.Project
13+
import org.joor.Reflect.on
1214

1315
class Debugger(private val project: Project, private val device: IDevice, private val packageName: String) {
1416

@@ -26,25 +28,47 @@ class Debugger(private val project: Project, private val device: IDevice, privat
2628

2729
private fun closeOldSessionAndRun(androidDebugger: AndroidDebugger<*>, client: Client) {
2830
terminateRunSessions(client)
29-
androidDebugger.attachToClient(project, client)
31+
AttachToClient(androidDebugger, project, client).get()
3032
}
3133

3234
// Disconnect any active run sessions to the same client
3335
private fun terminateRunSessions(selectedClient: Client) {
34-
val pid = selectedClient.clientData.pid
36+
val pid = PidGetter(selectedClient).get()
3537

3638
// find if there are any active run sessions to the same client, and terminate them if so
3739
for (handler in ExecutionManager.getInstance(project).getRunningProcesses()) {
3840
if (handler is AndroidProcessHandler) {
3941
val client = handler.getClient(selectedClient.device)
40-
if (client != null && client.clientData.pid == pid) {
42+
if (client != null && PidGetter(client).get() == pid) {
4143
handler.detachProcess()
4244
handler.notifyTextAvailable("Disconnecting run session: a new debug session will be established.\n", ProcessOutputTypes.STDOUT)
4345
break
4446
}
4547
}
4648
}
4749
}
50+
}
51+
52+
/**
53+
* To remove when 4.0 hits stable.
54+
*/
55+
class PidGetter(private val client: Client) : BackwardCompatibleGetter<Int>() {
56+
override fun getCurrentImplementation() = client.clientData.pid
57+
58+
override fun getPreviousImplementation() = on(client).call("getClientData").call("getPid").get<Int>()!!
59+
}
4860

61+
/**
62+
* To remove when 4.0 hits stable.
63+
*/
64+
class AttachToClient(private val androidDebugger: AndroidDebugger<*>,
65+
private val project: Project,
66+
private val client: Client) : BackwardCompatibleGetter<Unit>() {
67+
override fun getCurrentImplementation() {
68+
androidDebugger.attachToClient(project, client, null)
69+
}
4970

71+
override fun getPreviousImplementation() {
72+
on(androidDebugger).call("attachToClient", project, client)
73+
}
5074
}

0 commit comments

Comments
 (0)