@@ -4,11 +4,13 @@ import com.android.ddmlib.Client
4
4
import com.android.ddmlib.IDevice
5
5
import com.android.tools.idea.run.AndroidProcessHandler
6
6
import com.android.tools.idea.run.editor.AndroidDebugger
7
+ import com.developerphil.adbidea.compatibility.BackwardCompatibleGetter
7
8
import com.developerphil.adbidea.invokeLater
8
9
import com.developerphil.adbidea.waitUntil
9
10
import com.intellij.execution.ExecutionManager
10
11
import com.intellij.execution.process.ProcessOutputTypes
11
12
import com.intellij.openapi.project.Project
13
+ import org.joor.Reflect.on
12
14
13
15
class Debugger (private val project : Project , private val device : IDevice , private val packageName : String ) {
14
16
@@ -26,25 +28,47 @@ class Debugger(private val project: Project, private val device: IDevice, privat
26
28
27
29
private fun closeOldSessionAndRun (androidDebugger : AndroidDebugger <* >, client : Client ) {
28
30
terminateRunSessions(client)
29
- androidDebugger.attachToClient( project, client)
31
+ AttachToClient (androidDebugger, project, client).get( )
30
32
}
31
33
32
34
// Disconnect any active run sessions to the same client
33
35
private fun terminateRunSessions (selectedClient : Client ) {
34
- val pid = selectedClient.clientData.pid
36
+ val pid = PidGetter ( selectedClient).get()
35
37
36
38
// find if there are any active run sessions to the same client, and terminate them if so
37
39
for (handler in ExecutionManager .getInstance(project).getRunningProcesses()) {
38
40
if (handler is AndroidProcessHandler ) {
39
41
val client = handler.getClient(selectedClient.device)
40
- if (client != null && client.clientData.pid == pid) {
42
+ if (client != null && PidGetter ( client).get() == pid) {
41
43
handler.detachProcess()
42
44
handler.notifyTextAvailable(" Disconnecting run session: a new debug session will be established.\n " , ProcessOutputTypes .STDOUT )
43
45
break
44
46
}
45
47
}
46
48
}
47
49
}
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
+ }
48
60
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
+ }
49
70
71
+ override fun getPreviousImplementation () {
72
+ on(androidDebugger).call(" attachToClient" , project, client)
73
+ }
50
74
}
0 commit comments