Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceMonitor"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public DeviceMonitor(AndroidDebugBridge bridge)
 {
     this.Server = bridge;
     this.Devices = new List<Device>();
     this.DebuggerPorts = new List<int>();
     this.DebuggerPorts.Add(DdmPreferences.DebugPortBase);
     this.LengthBuffer = new byte[4];
     this.LengthBuffer2 = new byte[4];
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceMonitor"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public DeviceMonitor(AndroidDebugBridge bridge)
 {
     this.Server        = bridge;
     this.Devices       = new List <Device>();
     this.DebuggerPorts = new List <int>();
     this.DebuggerPorts.Add(DdmPreferences.DebugPortBase);
     this.LengthBuffer  = new byte[4];
     this.LengthBuffer2 = new byte[4];
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceMonitor"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public DeviceMonitor(AndroidDebugBridge bridge)
 {
     Server          = bridge;
     Devices         = new List <Device>();
     DebuggerPorts   = new List <int>();
     ClientsToReopen = new Dictionary <IClient, int>();
     DebuggerPorts.Add(DdmPreferences.DebugPortBase);
     LengthBuffer = new byte[4];
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceMonitor"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public DeviceMonitor( AndroidDebugBridge bridge )
 {
     Server = bridge;
     Devices = new List<Device> ( );
     DebuggerPorts = new List<int> ( );
     ClientsToReopen = new Dictionary<IClient, int> ( );
     DebuggerPorts.Add ( DdmPreferences.DebugPortBase );
     LengthBuffer = new byte[4];
     LengthBuffer2 = new byte[4];
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Disconnects the current debug bridge, and destroy the object.
        /// </summary>
        /// <remarks>This also stops the current adb host server.</remarks>
        public static void DisconnectBridge( )
        {
            if (_instance != null)
            {
                _instance.Stop( );

                _instance.OnBridgeChanged(new AndroidDebugBridgeEventArgs(null));
                _instance = null;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a {@link AndroidDebugBridge} that is not linked to any particular executable.
        /// This bridge will expect adb to be running. It will not be able to start/stop/restart</summary>
        /// adb.
        /// If a bridge has already been started, it is directly returned with no changes
        /// <returns></returns>
        public static AndroidDebugBridge CreateBridge( )
        {
            if (_instance != null)
            {
                return(_instance);
            }

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

            return(_instance);
        }
Ejemplo n.º 8
0
        public AndroidTestRunner(string jdkLocation, string sdkLocation, string apkLocation)
            : base()
        {
            _apkLocation = apkLocation;
            _jdkLocation = jdkLocation;
            _adbLocation = string.Format ("{0}{1}", sdkLocation, "//platform-tools//adb");

            _keyTool = string.Format ("{0}{1}", _jdkLocation, "//bin//keytool");
            _jarSigner = string.Format ("{0}{1}", _jdkLocation, "//bin//jarsigner");
            _adb = AndroidDebugBridge.CreateBridge (_adbLocation, true);
            _devices = new List<IDevice> ();
            _androidVersionHelper = new AndroidVersionHelper (sdkLocation);
            _fingerprintHelper = new FingerprintHelper (_keyTool, _apkLocation);
            _keystoreHelper = new KeystoreHelper (_keyTool);
            _apkInstallHelper = new ApkInstallHelper (_adbLocation);
            _testHelper = new AndroidTestHelper (_adbLocation);
            BuildToolsVersion buildToolsVersion = _androidVersionHelper.GetHighestBuildToolsVersion ();
            _aaptLocation = string.Format ("{0}/{1}", buildToolsVersion.Location, "aapt");
            _keystores = _keystoreHelper.GetKeystores ();
            _apkFingerprint = _fingerprintHelper.FingerprintFromApk ();
            _adb.DeviceConnected += OnDeviceConnected;
            _adb.DeviceChanged += OnDeviceChanged;
            _adb.DeviceDisconnected += OnDeviceDisconnected;
            _adb.Start ();
            Console.WriteLine ("Checking apk signing...");
            if (!CheckFingerprint ())
            {
                Console.WriteLine ("No sign match, re-sign needed");
                ResignApk ();
            }
            else
            {
                Console.WriteLine ("Sign match, no need to re-sign");
            }
            GetPackageName ();
            Console.WriteLine ("Preparing Test Server");
            PrepareTestServer ();
            CheckDevicesForInstall ();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidDebugBridgeEventArgs"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public AndroidDebugBridgeEventArgs( AndroidDebugBridge bridge )
 {
     this.Bridge = bridge;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidDebugBridgeEventArgs"/> class.
 /// </summary>
 /// <param name="bridge">The bridge.</param>
 public AndroidDebugBridgeEventArgs(AndroidDebugBridge bridge)
 {
     this.Bridge = bridge;
 }
Ejemplo n.º 11
0
        private void UpdateDevices(List <Device> list)
        {
            // because we are going to call mServer.deviceDisconnected which will acquire this lock
            // we lock it first, so that the AndroidDebugBridge lock is always locked first.
            lock (AndroidDebugBridge.GetLock( )) {
                lock ( Devices ) {
                    // For each device in the current list, we look for a matching the new list.
                    // * if we find it, we update the current object with whatever new information
                    //   there is
                    //   (mostly state change, if the device becomes ready, we query for build info).
                    //   We also remove the device from the new list to mark it as "processed"
                    // * if we do not find it, we remove it from the current list.
                    // Once this is done, the new list contains device we aren't monitoring yet, so we
                    // add them to the list, and start monitoring them.

                    for (int d = 0; d < Devices.Count;)
                    {
                        Device device = Devices[d];

                        // look for a similar device in the new list.
                        int  count      = list.Count;
                        bool foundMatch = false;
                        for (int dd = 0; dd < count; dd++)
                        {
                            Device newDevice = list[dd];
                            // see if it matches in id and serial number.
                            if (String.Compare(newDevice.SerialNumber, device.SerialNumber, true) == 0)
                            {
                                foundMatch = true;

                                // update the state if needed.
                                if (device.State != newDevice.State)
                                {
                                    device.State = newDevice.State;
                                    device.OnStateChanged(EventArgs.Empty);

                                    // if the device just got ready/online, we need to start
                                    // monitoring it.
                                    if (device.IsOnline)
                                    {
                                        if (AndroidDebugBridge.ClientSupport)
                                        {
                                            if (StartMonitoringDevice(device) == false)
                                            {
                                                Log.e(TAG, "Failed to start monitoring {0}", device.SerialNumber);
                                            }
                                        }

                                        if (device.Properties.Count == 0)
                                        {
                                            QueryNewDeviceForInfo(device);
                                        }
                                    }
                                }

                                // remove the new device from the list since it's been used
                                list.RemoveAt(dd);
                                break;
                            }
                        }

                        if (foundMatch == false)
                        {
                            // the device is gone, we need to remove it, and keep current index
                            // to process the next one.
                            RemoveDevice(device);
                            device.State = DeviceState.Offline;
                            device.OnStateChanged(EventArgs.Empty);
                            Server.OnDeviceDisconnected(new DeviceEventArgs(device));
                        }
                        else
                        {
                            // process the next one
                            d++;
                        }
                    }

                    // at this point we should still have some new devices in newList, so we
                    // process them.
                    foreach (Device newDevice in list)
                    {
                        // add them to the list
                        Devices.Add(newDevice);
                        if (Server != null)
                        {
                            newDevice.State = DeviceState.Online;
                            newDevice.OnStateChanged(EventArgs.Empty);
                            Server.OnDeviceConnected(new DeviceEventArgs(newDevice));
                        }

                        // start monitoring them.
                        if (AndroidDebugBridge.ClientSupport)
                        {
                            if (newDevice.IsOnline)
                            {
                                StartMonitoringDevice(newDevice);
                            }
                        }

                        // look for their build info.
                        if (newDevice.IsOnline)
                        {
                            QueryNewDeviceForInfo(newDevice);
                        }
                    }
                }
            }
            list.Clear( );
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Disconnects the current debug bridge, and destroy the object.
        /// </summary>
        /// <remarks>This also stops the current adb host server.</remarks>
        public static void DisconnectBridge( )
        {
            if ( _instance != null ) {
                _instance.Stop ( );

                _instance.OnBridgeChanged ( new AndroidDebugBridgeEventArgs ( null ) );
                _instance = null;
            }
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a {@link AndroidDebugBridge} that is not linked to any particular executable.
        /// This bridge will expect adb to be running. It will not be able to start/stop/restart</summary>
        /// adb.
        /// If a bridge has already been started, it is directly returned with no changes
        /// <returns></returns>
        public static AndroidDebugBridge CreateBridge( )
        {
            if ( _instance != null ) {
                return _instance;
            }

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

            return _instance;
        }