예제 #1
0
        /// <summary>
        /// Creates a new debug bridge from the location of the command line tool.
        /// </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>
        /// <remarks>Any existing server will be disconnected, unless the location is the same and
        /// <code>forceNewBridge</code> is set to false.
        /// </remarks>
        public static AndroidDebugBridge CreateBridge(String osLocation, bool forceNewBridge)
        {
            if (_instance != null)
            {
                if (!String.IsNullOrEmpty(AdbOsLocation) && string.Compare(AdbOsLocation, osLocation, true) == 0 && !forceNewBridge)
                {
                    return(_instance);
                }
                else
                {
                    // stop the current server
                    Log.d(TAG, "Stopping Current Instance");
                    _instance.Stop( );
                }
            }

            try {
                _instance = new AndroidDebugBridge(osLocation);
                _instance.Start( );
                _instance.OnBridgeChanged(new AndroidDebugBridgeEventArgs(_instance));
            } catch (ArgumentException) {
                _instance.OnBridgeChanged(new AndroidDebugBridgeEventArgs(null));
                _instance = null;
            }

            return(_instance);
        }