Beispiel #1
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(string path)
        {
            if (Device == null)
            {
                throw new ArgumentNullException("device", "Device cannot be null.");
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "Path cannot be null or empty.");
            }

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver();
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = Device.BusyBox.Available ? "touch" : ">";
                    var command = string.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU())
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!string.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(string.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(Device.FileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public FileEntry Create(String path)
        {
            Device.ThrowIfNull("Device");

            path.ThrowIfNullOrWhiteSpace("path");

            if (!Device.IsOffline)
            {
                if (Exists(path))
                {
                    throw new ArgumentException("The specified path already exists.");
                }
                else
                {
                    var cer     = new CommandErrorReceiver();
                    var escaped = LinuxPath.Escape(path);
                    // use native touch command if its available.
                    var cmd     = ">";
                    var command = String.Format("{0} {1}", cmd, escaped);
                    if (Device.CanSU())
                    {
                        Device.ExecuteRootShellCommand(command, cer);
                    }
                    else
                    {
                        Device.ExecuteShellCommand(command, cer);
                    }
                    if (!String.IsNullOrEmpty(cer.ErrorMessage))
                    {
                        throw new IOException(String.Format("Error creating file: {0}", cer.ErrorMessage));
                    }
                    else
                    {
                        // at this point, the newly created file should exist.
                        return(this.fileListingService.FindFileEntry(path));
                    }
                }
            }
            else
            {
                throw new IOException("Device is not online");
            }
        }
        public override TaskResult Run(Managed.Adb.Device adbDevice)
        {
            TaskResult result = new TaskResult();

            //un install
            var apkInfo = APKInfo.ParseAPK(mPackgeLocation);

            try {
                if (adbDevice.PackageManager.Exists(apkInfo.PackgeName))
                {
                    adbDevice.UninstallPackage(apkInfo.PackgeName);
                }
            } catch {
            }

            LogWrapper.LogInfo("CanuSU:" + adbDevice.SerialNumber + ":" + adbDevice.CanSU());
            string          remoteFilePath = adbDevice.SyncPackageToDevice(mPackgeLocation);
            InstallReceiver receiver       = new InstallReceiver();
            String          cmd            = String.Format("pm install {1}{0}", remoteFilePath, true ? "-r " : String.Empty);

            if (adbDevice.CanSU())
            {
                adbDevice.ExecuteRootShellCommand(cmd, receiver);
            }
            else
            {
                adbDevice.ExecuteShellCommand(cmd, receiver);
            }

            if (!String.IsNullOrEmpty(receiver.ErrorMessage))
            {
                result.ok  = false;
                result.Msg = receiver.ErrorMessage;
            }
            return(result);
        }