public MainWindow() { InitializeComponent(); DdmPreferences.LogLevel = Managed.Adb.LogLevel.Verbose; Environment.SetEnvironmentVariable("ANDROID_SDK", @"D:\SDK\Android\sdk"); AndroidDebugBridge bridge = AndroidDebugBridge.CreateBridge(System.IO.Path.Combine(Environment.GetEnvironmentVariable("ANDROID_SDK"), "platform-tools\\adb.exe"), true); while (!bridge.HasInitialDeviceList()) { Thread.Sleep(1000); } device = bridge.DeviceMonitor.Devices[0]; device.ExecuteShellCommand("am startservice --user 0 -n com.d8plus.smartarrow/.SmartArrowService", NullOutputReceiver.Instance); while (!device.HasClients) { Thread.Sleep(1000); } Mouse.AddPreviewMouseMoveHandler(this, (sender, e) => { var po = e.GetPosition(this); //1080 x 1920 int w = (int)(1080 * po.X / this.RenderSize.Width); int h = (int)(1920 * po.Y / this.RenderSize.Height); Debug.WriteLine(string.Format("move {0},{1}", w, h)); device.ExecuteShellCommand(string.Format("echo move {0},{1} >> /sdcard/SmartArrow.event", w, h), NullOutputReceiver.Instance); }); Observable.FromEventPattern<System.ComponentModel.CancelEventArgs>(this, "Closing").Subscribe(arg => { device.ExecuteShellCommand("am stopservice --user 0 -n com.d8plus.smartarrow/.SmartArrowService", NullOutputReceiver.Instance); arg.EventArgs.Cancel = false; }); }
/// <summary> /// Does the LS. /// </summary> /// <param name="entry">The entry.</param> private void DoLS(FileEntry entry) { // create a list that will receive the list of the entries List <FileEntry> entryList = new List <FileEntry> ( ); // create a list that will receive the link to compute post ls; List <String> linkList = new List <String> ( ); try { // create the command String command = String.Format(TOOLBOX_LS, entry.FullPath); // create the receiver object that will parse the result from ls ListingServiceReceiver receiver = new ListingServiceReceiver(entry, entryList, linkList); // call ls. Device.ExecuteShellCommand(command, receiver); // finish the process of the receiver to handle links receiver.FinishLinks( ); } catch (IOException e) { Log.e("ddms", e); throw; } // at this point we need to refresh the viewer entry.FetchTime = DateTime.Now.CurrentTimeMillis( ); // sort the children and set them as the new children entryList.Sort(new FileEntry.FileEntryComparer( )); entry.Children = entryList; }
/// <summary> /// Resolves the link to the true path. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <workitem id="19712">Uses "ls -l" to resolve links</workitem> public String ResolveLink(String path) { if (this.Device.BusyBox.Available) { var cresult = new CommandResultReceiver( ); this.Device.BusyBox.ExecuteShellCommand("readlink -f {0}", cresult, path); // if cresult is empty, return the path return((cresult == null || String.IsNullOrEmpty(cresult.Result)) ? path : cresult.Result); } else { try { // this uses the ls command to get the link path var receiver = new LinkResoverReceiver( ); Device.ExecuteShellCommand("ls {0} -l".With(path.ToArgumentSafe( )), receiver); if (!String.IsNullOrEmpty(receiver.ResolvedPath)) { return(receiver.ResolvedPath); } } catch (Exception e) { Log.d("FileSytem", e.Message); } return(path); } }
/// <summary> /// Attempts to mount the mount point to the associated device without knowing the device or the type. /// Some devices may not support this method. /// </summary> /// <param name="mountPoint"></param> public void Mount(String mountPoint) { mountPoint.ThrowIfNull("mountPoint"); Device.ThrowIfNull("Device"); CommandErrorReceiver cer = new CommandErrorReceiver(); Device.ExecuteShellCommand("mount {0}", cer, mountPoint); }
/// <summary> /// Unmounts the specified mount point. /// </summary> /// <param name="mountPoint">The mount point.</param> /// <param name="options">The options.</param> public void Unmount(String mountPoint, String options) { mountPoint.ThrowIfNull("mountPoint"); Device.ThrowIfNull("Device"); CommandErrorReceiver cer = new CommandErrorReceiver(); Device.ExecuteShellCommand("umount {1} {0}", cer, !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty, mountPoint); }
/// <summary> /// Mounts the specified device. /// </summary> /// <param name="mountPoint">The mp.</param> /// <param name="options">The options.</param> public void Mount(MountPoint mountPoint, String options) { mountPoint.ThrowIfNull("mountPoint"); Device.ThrowIfNull("Device"); CommandErrorReceiver cer = new CommandErrorReceiver(); Device.ExecuteShellCommand("mount {0} {4} -t {1} {2} {3}", cer, mountPoint.IsReadOnly ? "-r" : "-w", mountPoint.FileSystem, mountPoint.Block, mountPoint.Name, !String.IsNullOrEmpty(options) ? String.Format("-o {0}", options) : String.Empty); }
/// <summary> /// this is a fallback if the mkdir -p fails for somereason /// </summary> /// <param name="path"></param> internal void MakeDirectoryFallbackInternal(string path, CommandErrorReceiver cer) { string[] segs = path.Split(new char[] { LinuxPath.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); FileEntry current = Device.FileListingService.Root; foreach (var pathItem in segs) { FileEntry[] entries = Device.FileListingService.GetChildren(current, true, null); bool found = false; foreach (var e in entries) { if (string.Compare(e.Name, pathItem, false) == 0) { current = e; found = true; break; } } if (!found) { current = FileEntry.FindOrCreate(Device, LinuxPath.Combine(current.FullPath, pathItem + new string(new char[] { LinuxPath.DirectorySeparatorChar }))); Device.ExecuteShellCommand("mkdir {0}", cer, current.FullEscapedPath); } } }
/// <summary> /// Unmounts the specified mount point. /// </summary> /// <param name="mountPoint">The mount point.</param> /// <param name="options">The options.</param> public void Unmount(string mountPoint, string options) { CommandErrorReceiver cer = new CommandErrorReceiver(); if (Device.BusyBox.Available) { Device.ExecuteShellCommand("busybox umount {1} {0}", cer, !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty, mountPoint); } else { Device.ExecuteShellCommand("umount {1} {0}", cer, !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty, mountPoint); } }
/// <summary> /// Attempts to mount the mount point to the associated device without knowing the device or the type. /// Some devices may not support this method. /// </summary> /// <param name="mountPoint"></param> public void Mount(string mountPoint) { CommandErrorReceiver cer = new CommandErrorReceiver(); if (Device.BusyBox.Available) { Device.ExecuteShellCommand("busybox mount {0}", cer, mountPoint); } else { Device.ExecuteShellCommand("mount {0}", cer, mountPoint); } }
/// <summary> /// Mounts the specified device. /// </summary> /// <param name="mp">The mp.</param> /// <param name="options">The options.</param> public void Mount(MountPoint mp, string options) { CommandErrorReceiver cer = new CommandErrorReceiver(); if (Device.BusyBox.Available) { Device.ExecuteShellCommand("busybox mount {0} {4} -t {1} {2} {3}", cer, mp.IsReadOnly ? "-r" : "-w", mp.FileSystem, mp.Block, mp.Name, !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty); } else { Device.ExecuteShellCommand("mount {0} {4} -t {1} {2} {3}", cer, mp.IsReadOnly ? "-r" : "-w", mp.FileSystem, mp.Block, mp.Name, !string.IsNullOrEmpty(options) ? string.Format("-o {0}", options) : string.Empty); } }
public override TaskResult Run(Managed.Adb.Device adbDevice) { TaskResult result = new TaskResult(); String cmd = String.Format("am start {0}/{1}", mPackgeName, mLaunchActivity); var receiver = new LaunchAppReceiver(); adbDevice.ExecuteShellCommand(cmd, receiver); //if (!String.IsNullOrEmpty(receiver.ErrorMessage)) { // result.ok = false; // result.Msg = receiver.ErrorMessage; //} return(result); }
/// <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"); } }
/// <summary> /// Attempts to mount the mount point to the associated device without knowing the device or the type. /// Some devices may not support this method. /// </summary> /// <param name="mountPoint"></param> public void Mount(String mountPoint) { mountPoint.ThrowIfNull("mountPoint"); Device.ThrowIfNull("Device"); CommandErrorReceiver cer = new CommandErrorReceiver( ); if (Device.BusyBox.Available) { Device.ExecuteShellCommand("busybox mount {0}", cer, mountPoint); } else { Device.ExecuteShellCommand("mount {0}", cer, mountPoint); } }
/// <summary> /// Checks for busy box. /// </summary> private void CheckForBusyBox( ) { if (this.Device.IsOnline) { try { Commands.Clear( ); Device.ExecuteShellCommand(BUSYBOX_COMMAND, new BusyBoxCommandsReceiver(this)); Available = true; } catch (FileNotFoundException) { Available = false; } } else { Available = false; } }
/// <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"); } }
/// <summary> /// Gets if the specified path exists on the device. /// </summary> /// <param name="path">the path to check</param> /// <returns><c>true</c>, if the path exists; otherwise, <c>false</c></returns> /// <exception cref="IOException">If the device is not connected.</exception> /// <exception cref="ArgumentNullException">If the device or path is null.</exception> public bool Exists(String path) { Device.ThrowIfNull("Device"); path.ThrowIfNullOrWhiteSpace("path"); if (!Device.IsOffline) { try { Device.ExecuteShellCommand( Device.FileListingService.ForceBusyBox ? FileListingService.BUSYBOX_LS : FileListingService.TOOLBOX_LS, NullOutputReceiver.Instance, path); return(true); } catch (FileNotFoundException) { return(false); } } 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); }
/// <include file='.\BusyBox.xml' path='/BusyBox/Install/*'/> public bool Install(String busybox) { busybox.ThrowIfNullOrWhiteSpace("busybox"); FileEntry bb = null; try { Device.ExecuteShellCommand(BUSYBOX_COMMAND, NullOutputReceiver.Instance); return(true); } catch { // we are just checking if it is already installed so we really expect it to wind up here. } try { MountPoint mp = Device.MountPoints["/data"]; bool isRO = mp.IsReadOnly; Device.RemountMountPoint(Device.MountPoints["/data"], false); FileEntry path = null; try { path = this.fileListingService.FindFileEntry(BUSYBOX_BIN); } catch (FileNotFoundException) { // path doesn't exist, so we make it. this.fileSystem.MakeDirectory(BUSYBOX_BIN); // attempt to get the FileEntry after the directory has been made path = this.fileListingService.FindFileEntry(BUSYBOX_BIN); } this.fileSystem.Chmod(path.FullPath, "0755"); String bbPath = LinuxPath.Combine(path.FullPath, BUSYBOX_COMMAND); this.fileSystem.Copy(busybox, bbPath); bb = this.fileListingService.FindFileEntry(bbPath); this.fileSystem.Chmod(bb.FullPath, "0755"); Device.ExecuteShellCommand("{0}/busybox --install {0}", new ConsoleOutputReceiver( ), path.FullPath); // check if this path exists in the path already if (Device.EnvironmentVariables.ContainsKey("PATH")) { var paths = Device.EnvironmentVariables["PATH"].Split(':'); var found = paths.Where(p => String.Compare(p, BUSYBOX_BIN, false) == 0).Count( ) > 0; // we didnt find it, so add it. if (!found) { // this doesn't seem to actually work Device.ExecuteShellCommand(@"echo \ Mad Bee buxybox >> /init.rc", NullOutputReceiver.Instance); Device.ExecuteShellCommand(@"echo export PATH={0}:\$PATH >> /init.rc", NullOutputReceiver.Instance, BUSYBOX_BIN); } } if (mp.IsReadOnly != isRO) { // Put it back, if we changed it Device.RemountMountPoint(mp, isRO); } Device.ExecuteShellCommand("sync", NullOutputReceiver.Instance); } catch (Exception) { throw; } CheckForBusyBox( ); return(true); }
/// <summary> /// this is a fallback if the mkdir -p fails for somereason /// </summary> /// <param name="path"></param> /// <param name="cer"></param> internal void MakeDirectoryFallbackInternal(String path, CommandErrorReceiver cer) { Device.ExecuteShellCommand("mkdir {0}", cer, path); }