2424import processing .app .exec .ProcessResult ;
2525import processing .mode .android .EmulatorController .State ;
2626
27- import java .io .File ;
2827import java .io .IOException ;
2928import java .util .ArrayList ;
3029import java .util .Collections ;
@@ -50,6 +49,8 @@ class Devices {
5049
5150 private static final String BT_DEBUG_PORT = "4444" ;
5251
52+ private AndroidSDK sdk ;
53+
5354 private Device selectedDevice ;
5455
5556 public static Devices getInstance () {
@@ -61,6 +62,14 @@ public static Devices getInstance() {
6162 private final ExecutorService deviceLaunchThread =
6263 Executors .newSingleThreadExecutor ();
6364
65+ public void setSDK (AndroidSDK sdk ) {
66+ this .sdk = sdk ;
67+ }
68+
69+ public AndroidSDK getSDK () {
70+ return sdk ;
71+ }
72+
6473 public Device getSelectedDevice () {
6574 return selectedDevice ;
6675 }
@@ -69,18 +78,18 @@ public void setSelectedDevice(Device selectedDevice) {
6978 this .selectedDevice = selectedDevice ;
7079 }
7180
72- public static void killAdbServer () {
81+ public void killAdbServer () {
7382 System .out .println ("Shutting down any existing adb server..." );
7483 System .out .flush ();
7584 try {
76- AndroidSDK .runADB ("kill-server" );
85+ sdk .runADB ("kill-server" );
7786 } catch (final Exception e ) {
7887 System .err .println ("Devices.killAdbServer() failed." );
7988 e .printStackTrace ();
8089 }
8190 }
8291
83- public static void enableBluetoothDebugging () {
92+ public void enableBluetoothDebugging () {
8493 final Devices devices = Devices .getInstance ();
8594 java .util .List <Device > deviceList = devices .findMultiple (false );
8695
@@ -95,8 +104,8 @@ public static void enableBluetoothDebugging() {
95104 try {
96105 // Try Enable debugging over bluetooth
97106 // http://developer.android.com/training/wearables/apps/bt-debugging.html
98- AndroidSDK .runADB ("-s" , device .getId (), "forward" , "tcp:" + BT_DEBUG_PORT , "localabstract:/adb-hub" );
99- AndroidSDK .runADB ("connect" , "127.0.0.1:" + BT_DEBUG_PORT );
107+ sdk .runADB ("-s" , device .getId (), "forward" , "tcp:" + BT_DEBUG_PORT , "localabstract:/adb-hub" );
108+ sdk .runADB ("connect" , "127.0.0.1:" + BT_DEBUG_PORT );
100109 } catch (final Exception e ) {
101110 e .printStackTrace ();
102111 }
@@ -123,10 +132,10 @@ public void run() {
123132 }
124133
125134
126- public Future <Device > getEmulator (final File sdkToolsPath , final boolean wear ) {
135+ public Future <Device > getEmulator (final boolean wear ) {
127136 final Callable <Device > androidFinder = new Callable <Device >() {
128137 public Device call () throws Exception {
129- return blockingGetEmulator (sdkToolsPath , wear );
138+ return blockingGetEmulator ( wear );
130139 }
131140 };
132141 final FutureTask <Device > task = new FutureTask <Device >(androidFinder );
@@ -135,7 +144,7 @@ public Device call() throws Exception {
135144 }
136145
137146
138- private final Device blockingGetEmulator (final File sdkToolsPath , final boolean wear ) {
147+ private final Device blockingGetEmulator (final boolean wear ) {
139148 String port = AVD .getPreferredPort (wear );
140149 Device emu = find (true , port );
141150 if (emu != null ) {
@@ -151,7 +160,7 @@ private final Device blockingGetEmulator(final File sdkToolsPath, final boolean
151160
152161 if (emuController .getState () == State .NOT_RUNNING ) {
153162 try {
154- emuController .launch (sdkToolsPath , wear ); // this blocks until emulator boots
163+ emuController .launch (sdk , wear ); // this blocks until emulator boots
155164 } catch (final IOException e ) {
156165 System .err .println ("Problem while launching emulator." );
157166 e .printStackTrace (System .err );
@@ -309,15 +318,15 @@ void deviceRemoved(final Device device) {
309318 * @return list of device identifiers
310319 * @throws IOException
311320 */
312- public static List <String > list () {
321+ public List <String > list () {
313322 if (AndroidSDK .adbDisabled ) {
314323 return Collections .emptyList ();
315324 }
316325
317326 ProcessResult result ;
318327 try {
319328// System.out.println("listing devices 00");
320- result = AndroidSDK .runADB ("devices" );
329+ result = sdk .runADB ("devices" );
321330// System.out.println("listing devices 05");
322331 } catch (InterruptedException e ) {
323332 return Collections .emptyList ();
0 commit comments