/// <summary> /// Creates a new debug bridge from the location of the command line tool. /// <p/> /// Any existing server will be disconnected, unless the location is the same and /// <code>forceNewBridge</code> is set to false. </summary> /// <param name="osLocation"> the location of the command line tool 'adb' </param> /// <param name="forceNewBridge"> force creation of a new bridge even if one with the same location /// already exists. </param> /// <returns> a connected bridge. </returns> public static AndroidDebugBridge createBridge(string osLocation, bool forceNewBridge) { lock (sLock) { if (sThis != null) { if (sThis.mAdbOsLocation != null && sThis.mAdbOsLocation.Equals(osLocation) && forceNewBridge == false) { return sThis; } else { // stop the current server sThis.stop(); } } try { sThis = new AndroidDebugBridge(osLocation); sThis.start(); } catch (Exception) { sThis = null; } // because the listeners could remove themselves from the list while processing // their event callback, we make a copy of the list and iterate on it instead of // the main list. // This mostly happens when the application quits. IDebugBridgeChangeListener[] listenersCopy = sBridgeListeners.ToArray(); // notify the listeners of the change foreach (IDebugBridgeChangeListener listener in listenersCopy) { // we attempt to catch any exception so that a bad listener doesn't kill our // thread try { listener.bridgeChanged(sThis); } catch (Exception e) { Log.e(DDMS, e); } } return sThis; } }
/// <summary> /// Disconnects the current debug bridge, and destroy the object. /// <p/>This also stops the current adb host server. /// <p/> /// A new object will have to be created with <seealso cref="#createBridge(String, boolean)"/>. /// </summary> public static void disconnectBridge() { lock (sLock) { if (sThis != null) { sThis.stop(); sThis = null; // because the listeners could remove themselves from the list while processing // their event callback, we make a copy of the list and iterate on it instead of // the main list. // This mostly happens when the application quits. IDebugBridgeChangeListener[] listenersCopy = sBridgeListeners.ToArray(); // notify the listeners. foreach (IDebugBridgeChangeListener listener in listenersCopy) { // we attempt to catch any exception so that a bad listener doesn't kill our // thread try { listener.bridgeChanged(sThis); } catch (Exception e) { Log.e(DDMS, e); } } } } }
/// <summary> /// Creates a new <seealso cref="DeviceMonitor"/> object and links it to the running /// <seealso cref="AndroidDebugBridge"/> object. </summary> /// <param name="server"> the running <seealso cref="AndroidDebugBridge"/>. </param> internal DeviceMonitor(AndroidDebugBridge server) { mServer = server; mDebuggerPorts.Add(DdmPreferences.debugPortBase); }