Exemplo n.º 1
0
        public IProcessAsyncOperation ForwardPort(AndroidDevice device, int devicePort, int localPort,
                                                  ProcessEventHandler outputLog, ProcessEventHandler errorLog)
        {
            var args = string.Format("-s {0} forward tcp:{1} tcp:{2}", device.ID, localPort, devicePort);

            return(StartProcess(AdbExe, args, outputLog, errorLog));
        }
Exemplo n.º 2
0
        public ProcessWrapper LogCat(AndroidDevice device, ProcessEventHandler outputLog,
                                     ProcessEventHandler errorLog)
        {
            var args = string.Format("-s {0} logcat", device.ID);

            return(StartProcess(AdbExe, args, outputLog, errorLog));
        }
        public MonoDroidProcess(AndroidDevice device, string activity, string packageName,
                                Action <string> stdout, Action <string> stderr, IAsyncOperation startOp)
        {
            this.device      = device;
            this.packageName = packageName;
            this.stdout      = stdout;
            this.stderr      = stderr;

            //startTime = DateTime.Now;

            if (startOp == null)
            {
                StartTracking();
                return;
            }

            // Our launch intent.
            startOp.Completed += delegate(IAsyncOperation op) {
                if (!op.Success)
                {
                    SetCompleted(false);
                }
                else
                {
                    StartTracking();
                }
            };
        }
Exemplo n.º 4
0
        void AsyncGetProperties(AndroidDevice device)
        {
            var gpop = new AdbGetPropertiesOperation(device);

            lock (outstandingQueries) {
                outstandingQueries.Add(gpop);
            }
            gpop.Completed += delegate(IAsyncOperation op) {
                lock (outstandingQueries) {
                    if (disposed)
                    {
                        return;
                    }
                    outstandingQueries.Remove(gpop);
                    gpop.Dispose();
                }
                if (!op.Success)
                {
                    LoggingService.LogError(string.Format("Error getting properties from device '{0}'", device.ID), gpop.Error);
                    //fall through, to cache the null result for failed queries
                }
                lock (props) {
                    props [device.ID] = gpop.Properties;
                }
                if (Changed != null)
                {
                    Changed();
                }
            };
        }
Exemplo n.º 5
0
 public AdbTransportOperation(AndroidDevice device)
 {
     if (device == null)
     {
         throw new ArgumentNullException("device");
     }
     this.device = device;
 }
Exemplo n.º 6
0
        public IProcessAsyncOperation Uninstall(AndroidDevice device, string package, TextWriter outputLog, TextWriter errorLog)
        {
            var args = new ProcessArgumentBuilder();

            args.Add("-s", device.ID, "uninstall");
            args.AddQuoted(package);

            return(StartProcess(AdbExe, args.ToString(), outputLog, errorLog));
        }
Exemplo n.º 7
0
        public IProcessAsyncOperation PullFile(AndroidDevice device, string source, string destination,
                                               TextWriter outputLog, TextWriter errorLog)
        {
            var args = new ProcessArgumentBuilder();

            args.Add("-s", device.ID, "pull");
            args.AddQuoted(source, destination);

            return(StartProcess(AdbExe, args.ToString(), outputLog, errorLog));
        }
Exemplo n.º 8
0
        public AdbGetProcessIdOperation(AndroidDevice device, string packageName) :
            base(device)
        {
            if (packageName == null)
            {
                throw new ArgumentNullException("packageName");
            }

            this.packageName = packageName;
            BeginConnect();
        }
Exemplo n.º 9
0
        public AdbTrackLogOperation(AndroidDevice device, Action <string> output, params string [] parameters) : base(device)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            this.output     = output;
            this.parameters = parameters;

            BeginConnect();
        }
Exemplo n.º 10
0
        public InstallPackageOperation Install(AndroidDevice device, string package, TextWriter outputLog, TextWriter errorLog)
        {
            var args = new ProcessArgumentBuilder();

            args.Add("-s", device.ID, "install");
            args.AddQuoted(package);

            var errorCapture = new StringWriter();
            var errorWriter  = TeeTextWriter.ForNonNull(errorCapture, errorCapture);

            return(new InstallPackageOperation(StartProcess(AdbExe, args.ToString(), outputLog, errorWriter), errorCapture));
        }
		public MonoDroidExecutionCommand (string packageName, AndroidDevice device, FilePath apkPath,
			TargetRuntime runtime, TargetFramework framework, bool debugMode)
		{
			this.Device = device;
			this.PackageName = packageName;
			this.ApkPath = apkPath;
			this.Runtime = runtime;
			this.Framework = framework;
			this.DebugMode = debugMode;
			
			DebugPort = MonoDroidSettings.DebuggerPort;
			OutputPort = MonoDroidSettings.DebuggerOutputPort;
		}
Exemplo n.º 12
0
        public AdbShellOperation SetProperty(AndroidDevice device, string property, string value)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(new AdbShellOperation(device, string.Format("setprop \"{0}\" \"{1}\"", property, value)));
        }
Exemplo n.º 13
0
        //may block while it's showing a GUI. project MUST be built before calling this
        public static MonoDroidUploadOperation SignAndUpload(IProgressMonitor monitor, MonoDroidProject project,
                                                             ConfigurationSelector configSel, bool forceReplace, ref AndroidDevice device)
        {
            var conf  = project.GetConfiguration(configSel);
            var opMon = new AggregatedOperationMonitor(monitor);

            InvokeSynch(() => MonoDroidFramework.EnsureSdksInstalled());

            IAsyncOperation signOp = null;

            if (project.PackageNeedsSigning(configSel))
            {
                ClearUploadFlags(conf);
                signOp = project.SignPackage(configSel);
                opMon.AddOperation(signOp);
            }

            if (device == null)
            {
                device = InvokeSynch(() => ChooseDevice(null));
            }

            if (device == null)
            {
                opMon.Dispose();
                return(null);
            }

            if (!device.IsEmulator && MonoDroidFramework.CheckTrial())
            {
                opMon.Dispose();
                return(null);
            }

            //copture the device for a later anonymous method
            AndroidDevice dev = device;

            bool replaceIfExists = forceReplace || !GetUploadFlag(conf, device);

            var uploadOp = Upload(device, conf.ApkSignedPath, conf.PackageName, signOp, replaceIfExists);

            opMon.AddOperation(uploadOp);
            uploadOp.Completed += delegate(IAsyncOperation op) {
                if (op.Success)
                {
                    SetUploadFlag(conf, dev);
                }
                opMon.Dispose();
            };
            return(uploadOp);
        }
Exemplo n.º 14
0
        static MonoDroidUploadOperation Upload(AndroidDevice device, FilePath packageFile, string packageName,
                                               IAsyncOperation signingOperation, bool replaceIfExists)
        {
            var monitor = IdeApp.Workbench.ProgressMonitors.GetOutputProgressMonitor(
                GettextCatalog.GetString("Deploy to Device"), MonoDevelop.Ide.Gui.Stock.RunProgramIcon, true, true);

            var op = new MonoDroidUploadOperation(monitor, device, packageFile, packageName, signingOperation, replaceIfExists);

            op.Completed += delegate {
                monitor.Dispose();
            };
            op.Start();
            return(op);
        }
Exemplo n.º 15
0
 //simple flag used to determine whether the current binary has been uploaded to the device
 //we clear it before signing, and set it for each device after successful upload
 static bool GetUploadFlag(MonoDroidProjectConfiguration conf, AndroidDevice device)
 {
     try {
         var file = GetUploadFlagFileName(conf);
         if (File.Exists(file))
         {
             var deviceIds = File.ReadAllLines(file);
             return(deviceIds.Contains(device.ID));
         }
     } catch (Exception ex) {
         LoggingService.LogError("Error reading upload flag", ex);
     }
     return(true);
 }
Exemplo n.º 16
0
 static void SetUploadFlag(MonoDroidProjectConfiguration conf, AndroidDevice device)
 {
     try {
         var file = GetUploadFlagFileName(conf);
         if (!File.Exists(file))
         {
             File.WriteAllText(file, device.ID);
         }
         else
         {
             File.AppendAllText(file, "\n" + device.ID);
         }
     } catch (Exception ex) {
         LoggingService.LogError("Error setting upload flag", ex);
     }
 }
Exemplo n.º 17
0
        protected override void Run()
        {
            if (!MonoDroidFramework.EnsureSdksInstalled())
            {
                return;
            }

            var configSel = IdeApp.Workspace.ActiveConfiguration;
            var proj      = GetActiveExecutableMonoDroidProject();

            OperationHandler upload = delegate {
                using (var monitor = new MonoDevelop.Ide.ProgressMonitoring.MessageDialogProgressMonitor()) {
                    AndroidDevice device = null;

                    var conf     = (MonoDroidProjectConfiguration)proj.GetConfiguration(configSel);
                    var deviceId = proj.GetDeviceTarget(conf);
                    if (deviceId != null)
                    {
                        device = MonoDroidFramework.DeviceManager.GetDevice(deviceId);
                    }
                    if (device == null)
                    {
                        proj.SetDeviceTarget(conf, null);
                    }

                    MonoDroidUtility.SignAndUpload(monitor, proj, configSel, true, ref device);
                }
            };

            if (proj.NeedsBuilding(configSel))
            {
                IdeApp.ProjectOperations.Build(proj).Completed += upload;
            }
            else
            {
                upload(null);
            }
        }
Exemplo n.º 18
0
 void ClearTracking()
 {
     lock (lockObj) {
         if (op != null)
         {
             ((IDisposable)op).Dispose();
         }
         op = null;
         if (propTracker != null)
         {
             propTracker.Dispose();
         }
         propTracker = null;
         if (pop != null)
         {
             pop.Dispose();
         }
         pop           = null;
         Devices       = new AndroidDevice[0];
         lastForwarded = null;
         OnChanged(null, null);
     }
 }
Exemplo n.º 19
0
		public AdbGetPackagesOperation (AndroidDevice device, string packageFileName) : base (device)
		{
			this.packageFileName = packageFileName;
			BeginConnect ();
		}
Exemplo n.º 20
0
        public IProcessAsyncOperation WaitForDevice(AndroidDevice device, TextWriter outputLog, TextWriter errorLog)
        {
            var args = string.Format("-s {0} wait-for-device", device.ID);

            return(StartProcess(AdbExe, args, outputLog, errorLog));
        }
Exemplo n.º 21
0
		public AdbTrackLogOperation (AndroidDevice device, Action<string> output, params string [] parameters) : base (device)
		{
			if (output == null)
				throw new ArgumentNullException ("output");
			
			this.output = output;
			this.parameters = parameters;
			
			BeginConnect ();
		}
Exemplo n.º 22
0
		public AdbGetDateOperation GetDeviceDate (AndroidDevice device)
		{
			return new AdbGetDateOperation (device);
		}
Exemplo n.º 23
0
 public AdbShellOperation StartActivity(AndroidDevice device, string activity)
 {
     return(new AdbShellOperation(device,
                                  string.Format("am start -a android.intent.action.MAIN -n '{0}'", activity)));
 }
Exemplo n.º 24
0
		public AdbTrackLogOperation (AndroidDevice device, Action<string> output, params string [] parameters) : base (device)
		{
			this.output = output;
			this.parameters = parameters;
		}
Exemplo n.º 25
0
		public InstallPackageOperation Install (AndroidDevice device, string package, TextWriter outputLog, TextWriter errorLog)
		{
			var args = new ProcessArgumentBuilder ();
			args.Add ("-s", device.ID, "install");
			args.AddQuoted (package);
			
			var errorCapture = new StringWriter ();
			var errorWriter = TeeTextWriter.ForNonNull (errorCapture, errorCapture);
			return new InstallPackageOperation (StartProcess (AdbExe, args.ToString (), outputLog, errorWriter), errorCapture);
		}
Exemplo n.º 26
0
		public IProcessAsyncOperation WaitForDevice (AndroidDevice device, TextWriter outputLog, TextWriter errorLog)
		{
			var args = string.Format ("-s {0} wait-for-device", device.ID);
			return StartProcess (AdbExe, args, outputLog, errorLog);
		}
Exemplo n.º 27
0
 public AdbGetPackagesOperation(AndroidDevice device) : this(device, DefaultPackagesFile)
 {
 }
Exemplo n.º 28
0
		public ProcessWrapper LogCat (AndroidDevice device, ProcessEventHandler outputLog,
			ProcessEventHandler errorLog)
		{
			var args = string.Format ("-s {0} logcat", device.ID);
			return StartProcess (AdbExe, args, outputLog, errorLog);
		}
Exemplo n.º 29
0
		public AdbTransportOperation (AndroidDevice device)
		{
			this.device = device;
		}
Exemplo n.º 30
0
		public IProcessAsyncOperation ForwardPort (AndroidDevice device, int devicePort, int localPort,
			ProcessEventHandler outputLog, ProcessEventHandler errorLog)
		{
			var args = string.Format ("-s {0} forward tcp:{1} tcp:{2}", device.ID, localPort, devicePort);
			return StartProcess (AdbExe, args, outputLog, errorLog);
		}
Exemplo n.º 31
0
		public AdbShellOperation StartActivity (AndroidDevice device, string activity)
		{
			return new AdbShellOperation (device,
				string.Format ("am start -a android.intent.action.MAIN -n '{0}'", activity));
		}
Exemplo n.º 32
0
		public IProcessAsyncOperation Uninstall (AndroidDevice device, string package, TextWriter outputLog, TextWriter errorLog)
		{
			var args = new ProcessArgumentBuilder ();
			args.Add ("-s", device.ID, "uninstall");
			args.AddQuoted (package);
			
			return StartProcess (AdbExe, args.ToString (), outputLog, errorLog);
		}
Exemplo n.º 33
0
		public AdbKillProcessOperation (AndroidDevice device, string packageName) : 
			base (device, "am broadcast -a mono.android.intent.action.SEPPUKU " +
				"-c mono.android.intent.category.SEPPUKU." + packageName)
		{
			BeginConnect ();
		}
Exemplo n.º 34
0
 public AdbGetPackagesOperation(AndroidDevice device, string packageFileName) : base(device)
 {
     this.packageFileName = packageFileName;
     BeginConnect();
 }
Exemplo n.º 35
0
		public AdbGetPartitionSizeOperation (AndroidDevice device, string partition) : base (device, "df " + partition)
		{
			this.partition = partition;
			BeginConnect ();
		}
Exemplo n.º 36
0
 public AdbGetPropertiesOperation(AndroidDevice device) : base(device)
 {
     BeginConnect();
 }
Exemplo n.º 37
0
		public AdbGetPropertiesOperation (AndroidDevice device) : base (device) {}
Exemplo n.º 38
0
		public AdbShellOperation (AndroidDevice device, string command) : base (device)
		{
			this.command = command;
		}
Exemplo n.º 39
0
		//this should be a singleton created from MonoDroidFramework
		internal DeviceManager ()
		{
			Devices = new AndroidDevice[0];
		}
Exemplo n.º 40
0
		public AdbShellOperation SetProperty (AndroidDevice device, string property, string value)
		{
			if (property == null)
				throw new ArgumentNullException ("property");
			if (value == null)
				throw new ArgumentNullException ("value");
			
			return new AdbShellOperation (device, string.Format ("setprop \"{0}\" \"{1}\"", property, value));
		}
		public MonoDroidExecutionHandler (AndroidDevice target)
		{
			this.DeviceTarget = target;
		}		
Exemplo n.º 42
0
 public AdbGetDateOperation(AndroidDevice device) : base(device, "date +%s")
 {
     BeginConnect();
 }
Exemplo n.º 43
0
        public MonoDroidUploadOperation(IProgressMonitor monitor, AndroidDevice device, FilePath packageFile, string packageName,
                                        IAsyncOperation signingOperation, bool replaceIfExists)
        {
            var         toolbox              = MonoDroidFramework.Toolbox;
            var         project              = DefaultUploadToDeviceHandler.GetActiveExecutableMonoDroidProject();
            var         conf                 = (MonoDroidProjectConfiguration)project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration);
            int         apiLevel             = MonoDroidFramework.FrameworkVersionToApiLevel(project.TargetFramework.Id.Version);
            int         runtimeVersion       = MonoDroidFramework.GetRuntimeVersion();
            string      packagesListLocation = null;
            PackageList list                 = null;

            replaceIfExists = replaceIfExists || signingOperation != null;

            chop = new ChainedAsyncOperationSequence(monitor,
                                                     new ChainedAsyncOperation()
            {
                Skip         = () => MonoDroidFramework.DeviceManager.GetDeviceIsOnline(device.ID) ? "" : null,
                TaskName     = GettextCatalog.GetString("Waiting for device"),
                Create       = () => toolbox.WaitForDevice(device, monitor.Log, monitor.Log),
                Completed    = op => { DeviceNotFound = !op.Success; },
                ErrorMessage = GettextCatalog.GetString("Failed to get device")
            },
                                                     new ChainedAsyncOperation <AdbShellOperation> ()
            {
                TaskName  = GettextCatalog.GetString("Getting the package list location from device"),
                Create    = () => new AdbShellOperation(device, "ls /data/system/packages.xml"),
                Completed = op => {
                    string output = op.Output.Trim(new char [] { '\n', '\r' });
                    if (output == "/data/system/packages.xml")
                    {
                        packagesListLocation = output;
                    }
                    else
                    {
                        packagesListLocation = "/dbdata/system/packages.xml";
                    }
                }
            },
                                                     new ChainedAsyncOperation <AdbGetPackagesOperation> ()
            {
                TaskName     = GettextCatalog.GetString("Getting package list from device"),
                Create       = () => new AdbGetPackagesOperation(device, packagesListLocation),
                Completed    = op => list = op.PackageList,
                ErrorMessage = GettextCatalog.GetString("Failed to get package list")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Uninstalling old version of shared runtime package"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.GetOldRuntimesAndPlatforms(apiLevel, runtimeVersion).Count() == 0 ?
                           "" : null,
                Create = () => {                         // Cleanup task, no need to wait for it
                    foreach (InstalledPackage oldPackage in list.GetOldRuntimesAndPlatforms(apiLevel, runtimeVersion))
                    {
                        toolbox.Uninstall(device, oldPackage.Name, monitor.Log, monitor.Log);
                    }
                    return(Core.Execution.NullProcessAsyncOperation.Success);
                },
                ErrorMessage = GettextCatalog.GetString("Failed to uninstall package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Installing shared runtime package on device"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.IsCurrentRuntimeInstalled(runtimeVersion) ?
                           "" : null,
                Create = () => {
                    var pkg = MonoDroidFramework.SharedRuntimePackage;
                    if (!File.Exists(pkg))
                    {
                        var msg = GettextCatalog.GetString("Could not find shared runtime package file");
                        monitor.ReportError(msg, null);
                        LoggingService.LogError("{0} '{1}'", msg, pkg);
                        return(null);
                    }
                    return(toolbox.Install(device, pkg, monitor.Log, monitor.Log));
                },
                ErrorMessage = GettextCatalog.GetString("Failed to install shared runtime package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Installing the platform framework"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.IsCurrentPlatformInstalled(apiLevel, runtimeVersion) ?
                           "" : null,
                Create = () => {
                    var platformApk = MonoDroidFramework.GetPlatformPackage(apiLevel);
                    if (!File.Exists(platformApk))
                    {
                        var msg = GettextCatalog.GetString("Could not find platform package file");
                        monitor.ReportError(msg, null);
                        LoggingService.LogError("{0} '{1}'", msg, platformApk);
                        return(null);
                    }
                    return(toolbox.Install(device, platformApk, monitor.Log, monitor.Log));
                },
                ErrorMessage = GettextCatalog.GetString("Failed to install the platform framework")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName     = GettextCatalog.GetString("Uninstalling old version of package"),
                Skip         = () => (!replaceIfExists || !list.ContainsPackage(packageName))? "" : null,
                Create       = () => toolbox.Uninstall(device, packageName, monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to uninstall package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName     = GettextCatalog.GetString("Waiting for packaging signing to complete"),
                Skip         = () => (signingOperation == null || signingOperation.IsCompleted) ? "" : null,
                Create       = () => signingOperation,
                ErrorMessage = GettextCatalog.GetString("Package signing failed"),
            },
                                                     new ChainedAsyncOperation()
            {
                Skip = () => (list.ContainsPackage(packageName) && !replaceIfExists)
                                                ? GettextCatalog.GetString("Package is already up to date") : null,
                TaskName     = GettextCatalog.GetString("Installing package"),
                Create       = () => toolbox.Install(device, packageFile, monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to install package")
            }
                                                     );
        }
Exemplo n.º 44
0
 public AdbGetPartitionSizeOperation(AndroidDevice device, string partition) : base(device, "df " + partition)
 {
     this.partition = partition;
     BeginConnect();
 }
Exemplo n.º 45
0
 public AdbGetDateOperation GetDeviceDate(AndroidDevice device)
 {
     return(new AdbGetDateOperation(device));
 }
Exemplo n.º 46
0
 public AdbBaseShellOperation(AndroidDevice device, string command) : base(device)
 {
     this.command = command;
 }
Exemplo n.º 47
0
		public AdbGetPackagesOperation (AndroidDevice device) : this (device, DefaultPackagesFile)
		{
		}
Exemplo n.º 48
0
 public AdbShellOperation(AndroidDevice device, string command) : base(device, command)
 {
     BeginConnect();
 }
Exemplo n.º 49
0
		public AdbGetPropertiesOperation (AndroidDevice device) : base (device)
		{
			BeginConnect ();
		}
Exemplo n.º 50
0
        protected override void OnExecute(IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configSel)
        {
            var conf = (MonoDroidProjectConfiguration)GetConfiguration(configSel);

            IConsole console = null;
            var      opMon   = new AggregatedOperationMonitor(monitor);

            try {
                var  handler          = context.ExecutionHandler as MonoDroidExecutionHandler;
                bool useHandlerDevice = handler != null && handler.DeviceTarget != null;

                AndroidDevice device = null;

                if (useHandlerDevice)
                {
                    device = handler.DeviceTarget;
                }
                else
                {
                    var deviceId = GetDeviceTarget(conf);
                    if (deviceId != null)
                    {
                        device = MonoDroidFramework.DeviceManager.GetDevice(deviceId);
                    }
                    if (device == null)
                    {
                        SetDeviceTarget(conf, null);
                    }
                }

                var uploadOp = MonoDroidUtility.SignAndUpload(monitor, this, configSel, false, ref device);

                //user cancelled device selection
                if (device == null)
                {
                    return;
                }

                if (!device.IsEmulator && MonoDroidFramework.CheckTrial())
                {
                    return;
                }

                opMon.AddOperation(uploadOp);
                uploadOp.WaitForCompleted();

                if (!uploadOp.Success || monitor.IsCancelRequested)
                {
                    return;
                }

                //get the activity name after signing produced the final manifest
                string activity;
                if (!GetActivityNameFromManifest(monitor, conf, out activity))
                {
                    return;
                }

                //successful, persist the device choice
                if (!useHandlerDevice)
                {
                    SetDeviceTarget(conf, device.ID);
                }

                var command = (MonoDroidExecutionCommand)CreateExecutionCommand(configSel, conf);
                command.Device   = device;
                command.Activity = activity;

                //FIXME: would be nice to skip this if it's a debug handler, which will set another value later
                var propOp = MonoDroidFramework.Toolbox.SetProperty(device, "debug.mono.extra", string.Empty);
                opMon.AddOperation(propOp);
                propOp.WaitForCompleted();
                if (!propOp.Success)
                {
                    monitor.ReportError(GettextCatalog.GetString("Could not clear debug settings on device"),
                                        propOp.Error);
                    return;
                }

                console = context.ConsoleFactory.CreateConsole(false);
                var executeOp = context.ExecutionHandler.Execute(command, console);
                opMon.AddOperation(executeOp);
                executeOp.WaitForCompleted();
            } finally {
                opMon.Dispose();
                if (console != null)
                {
                    console.Dispose();
                }
            }
        }
Exemplo n.º 51
0
		public AdbGetDateOperation (AndroidDevice device) : base (device, "date +%s")
		{
			BeginConnect ();
		}
Exemplo n.º 52
0
		public void SetDeviceTarget (MonoDroidProjectConfiguration conf, AndroidDevice value)
		{
			UserProperties.SetValue<AndroidDevice> (GetDeviceTargetKey (conf), value);
		}
Exemplo n.º 53
0
		public AdbShellOperation (AndroidDevice device, string command) : base (device, command)
		{
			BeginConnect ();
		}
Exemplo n.º 54
0
		void ClearTracking ()
		{
			lock (lockObj) {
				if (op != null)
					((IDisposable)op).Dispose ();
				op = null;
				if (propTracker != null)
					propTracker.Dispose ();
				propTracker = null;
				Devices = new AndroidDevice[0];
				lastForwarded = null;
				OnChanged (null, null);
			}
		}
Exemplo n.º 55
0
		public AdbGetPackagesOperation (AndroidDevice device) : base (device) {}
Exemplo n.º 56
0
		void AsyncGetProperties (AndroidDevice device)
		{
			var gpop = new AdbGetPropertiesOperation (device);
			lock (outstandingQueries) {
				outstandingQueries.Add (gpop);
			}
			gpop.Completed += delegate (IAsyncOperation op) {
				lock (outstandingQueries) {
					if (disposed)
						return;
					outstandingQueries.Remove (gpop);
					gpop.Dispose ();
				}
				if (!op.Success) {
					LoggingService.LogError (string.Format ("Error getting properties from device '{0}'", device.ID), gpop.Error);
					//fall through, to cache the null result for failed queries
				}
				lock (props) {
					props [device.ID] = gpop.Properties	;
				}
				if (Changed != null)
					Changed ();
			};
		}
Exemplo n.º 57
0
		public AdbGetProcessIdOperation (AndroidDevice device, string packageName) :
			base (device)
		{
			if (packageName == null)
				throw new ArgumentNullException ("packageName");

			this.packageName = packageName;
		}
Exemplo n.º 58
0
		public IProcessAsyncOperation PullFile (AndroidDevice device, string source, string destination,
			TextWriter outputLog, TextWriter errorLog)
		{
			var args = new ProcessArgumentBuilder ();
			args.Add ("-s", device.ID, "pull");
			args.AddQuoted (source, destination);
			
			return StartProcess (AdbExe, args.ToString (), outputLog, errorLog);
		}
		protected override void OnRun (DebuggerStartInfo startInfo)
		{
			var dsi = (MonoDroidDebuggerStartInfo) startInfo;
			var cmd = dsi.ExecutionCommand;
			debugDevice = cmd.Device;
			
			bool alreadyForwarded = MonoDroidFramework.DeviceManager.GetDeviceIsForwarded (cmd.Device.ID);
			if (!alreadyForwarded)
				MonoDroidFramework.DeviceManager.SetDeviceLastForwarded (null);
			
			long date = 0;
			int runningProcessId = 0; // Already running activity
			DateTime setPropertyTime = DateTime.MinValue;
			launchOp = new ChainedAsyncOperationSequence (
				new ChainedAsyncOperation<AndroidToolbox.GetDateOperation> () {
					Create = () => MonoDroidFramework.Toolbox.GetDeviceDate (cmd.Device),
					Completed = (op) => {
						if (op.Success) {
							date = op.Date;
							setPropertyTime = DateTime.Now;
						} else {
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to get date from device"));
							this.OnDebuggerOutput (true, op.GetOutput ());
						}
					},
				},
				new ChainedAsyncOperation<AndroidToolbox.AdbOutputOperation> () {
					Create = () => {
						this.OnDebuggerOutput (false, GettextCatalog.GetString ("Setting debug property") + "\n");
						long expireDate = date + (DEBUGGER_TIMEOUT_MS / 1000);
						string monoOptions = string.Format ("debug={0}:{1}:{2},timeout={3},server=y", dsi.Address, dsi.DebugPort, 0, expireDate);
						return MonoDroidFramework.Toolbox.SetProperty (cmd.Device, "debug.mono.extra", monoOptions);
					},
					Completed = (op) => {
						if (!op.Success) {
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to set debug property on device"));
							this.OnDebuggerOutput (true, op.GetOutput ());
						} else {
							debugPropertySet = true;
						}
					}
				},
				new ChainedAsyncOperation () {
					Skip = () => alreadyForwarded? "" : null,
					Create = () => {
						this.OnDebuggerOutput (false, GettextCatalog.GetString ("Forwarding debugger port") + "\n");
						return MonoDroidFramework.Toolbox.ForwardPort (cmd.Device, dsi.DebugPort, dsi.DebugPort, DebuggerOutput, DebuggerError);
					},
					Completed = (op) => {
						if (!op.Success) {
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to forward port on device"));
						}
					}
				},
				new ChainedAsyncOperation () {
					Skip = () => alreadyForwarded? "" : null,
					Create = () => {
						this.OnDebuggerOutput (false, GettextCatalog.GetString ("Forwarding console port") + "\n");
						return MonoDroidFramework.Toolbox.ForwardPort (cmd.Device, dsi.OutputPort, dsi.OutputPort, DebuggerOutput, DebuggerError);
					},
					Completed = (op) => {
						if (!op.Success) {
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to forward port on device"));
						} else {
							MonoDroidFramework.DeviceManager.SetDeviceLastForwarded (cmd.Device.ID);
						}
					}
				},
				new ChainedAsyncOperation<AdbGetProcessIdOperation> () {
					Create = () => new AdbGetProcessIdOperation (cmd.Device, cmd.PackageName),
					Completed = (op) => {
						if (!op.Success) {
							this.OnDebuggerOutput (true, "Error trying to detect already running process");
						} else if (op.ProcessId > 0) {
							this.OnDebuggerOutput (false, GettextCatalog.GetString ("Already running activity detected, restarting it in debug mode") + "\n");
							runningProcessId = op.ProcessId;
						}
					}
				},
				new ChainedAsyncOperation () {
					Skip = () => runningProcessId <= 0 ? "" : null,
					Create = () => new AdbShellOperation (cmd.Device, "kill " + runningProcessId),
					Completed = (op) => {
						if (!op.Success) {
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to stop already running activity"));
						}
					}
				},
				new ChainedAsyncOperation () {
					Create = () => MonoDroidFramework.Toolbox.StartActivity (cmd.Device, cmd.Activity, DebuggerOutput, DebuggerError),
					Completed = (op) => {
						if (!op.Success)
							this.OnDebuggerOutput (true, GettextCatalog.GetString ("Failed to start activity"));
					}
				}
			);
			launchOp.Completed += delegate (IAsyncOperation op) {
				if (!op.Success) {
					EndSession ();
					return;
				}
				launchOp = null;
					
				Action<string> stdout = s => OnTargetOutput (false, s);
				Action<string> stderr = s => OnTargetOutput (true, s);

				trackProcessOp = new MonoDroidProcess (cmd.Device, cmd.Activity, cmd.PackageName, stdout, stderr);
				trackProcessOp.Completed += delegate {
					EndSession ();
				};
			
				System.Threading.Thread.Sleep (WAIT_BEFORE_CONNECT_MS);
				
				var msSinceSetProperty = (long) Math.Floor ((DateTime.Now - setPropertyTime).TotalMilliseconds);
				long msTillPropertyExpires = DEBUGGER_TIMEOUT_MS - msSinceSetProperty;
				
				if (msTillPropertyExpires < 100 || msTillPropertyExpires > DEBUGGER_TIMEOUT_MS)
					return;
				
				int retries = (int) Math.Floor ((double)  msTillPropertyExpires / WAIT_BEFORE_RETRY_MS) - 2;
				
				StartConnecting (dsi, retries, WAIT_BEFORE_RETRY_MS);
			};
			
			TargetExited += delegate {
				EndLaunch ();
			};
			
			launchOp.Start ();
		}
Exemplo n.º 60
0
 public AdbKillProcessOperation(AndroidDevice device, string packageName) :
     base(device, "am broadcast -a mono.android.intent.action.SEPPUKU " +
          "-c mono.android.intent.category.SEPPUKU." + packageName)
 {
     BeginConnect();
 }