Esempio n. 1
0
 /// <summary>
 /// 构造器
 /// </summary>
 public DevicesGetter()
 {
     adbDevices      = new AdbCommand(ADB_DEVICES_COMMAND);
     fastbootDevices = new FastbootCommand(FSB_DEVICES_COMMAND);
     adbDevices.NeverCreateNewWindow      = true;
     fastbootDevices.NeverCreateNewWindow = true;
 }
Esempio n. 2
0
        /// <summary>
        /// 通过数据线连接Apk server
        /// </summary>
        /// <returns></returns>
        private bool Connect()
        {
            string result;

            AdbCommand.ExecuteAdbCommand("forward tcp:6666 tcp:6666", out result);
            return(Connect("127.0.0.1"));
        }
Esempio n. 3
0
        /// <summary>
        /// CAT命令查看文件内容
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public string Cat(string file)
        {
            var result = new AdbCommand("shell cat " + file).Execute();

            result.ThrowIfShellExitCodeNotEqualsZero();
            return(result.Output.ToString());
        }
Esempio n. 4
0
        /// <summary>
        /// 推送文件到设备
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="device"></param>
        /// <param name="path"></param>
        public static void PushTo(this FileInfo fileInfo, IDevice device, string path)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException(nameof(fileInfo));
            }

            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            using (var command = new AdbCommand(device, $"push \"{fileInfo.FullName}\" \"{path}\""))
            {
                var result = command.Execute();
                if (result.ExitCode != 0)
                {
                    throw new AdbCommandFailedException(result.Output)
                          {
                              ExitCode = result.ExitCode
                          };
                }
            }
        }
        /// <summary>
        /// 执行ADB命令
        /// </summary>
        /// <param name="device"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static Tuple <Output, int> Adb(this IDevice device, string command)
        {
            var cmd    = new AdbCommand(device, command);
            var result = cmd.Execute();

            return(new Tuple <Output, int>(result.Output, result.ExitCode));
        }
Esempio n. 6
0
        /// <summary>
        /// 安装应用
        /// </summary>
        /// <param name="apkFileInfo"></param>
        /// <param name="device"></param>
        public static void InstallTo(this FileInfo apkFileInfo, IDevice device)
        {
            if (apkFileInfo == null)
            {
                throw new ArgumentNullException(nameof(apkFileInfo));
            }

            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (apkFileInfo.Extension != ".apk")
            {
                throw new ArgumentException("Is not apk file!", nameof(apkFileInfo));
            }
            using (var command = new AdbCommand(device, $"install \"{apkFileInfo.FullName}\""))
            {
                var result = command.Execute();
                if (result.ExitCode != 0)
                {
                    throw new AdbCommandFailedException(result.Output)
                          {
                              ExitCode = result.ExitCode
                          };
                }
            }
        }
Esempio n. 7
0
        protected override int VisualMain()
        {
            DialogResult dialogResult = DialogResult.No;
            string       path         = null;

            App.RunOnUIThread(() =>
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                dialogResult            = fbd.ShowDialog();
                path = fbd.SelectedPath;
            });

            if (dialogResult == DialogResult.OK)
            {
                string tmpFile = $"{Adb.AdbTmpPathOnDevice}/screenshot.png";
                TargetDevice.Shell($"/system/bin/screencap -p {tmpFile}");
                var result = new AdbCommand(TargetDevice, $"pull {tmpFile} {path}")
                             .To((e) =>
                {
                    WriteLine(e.Text);
                }).Execute();
                return(result.ExitCode);
            }
            return(ERR);
        }
Esempio n. 8
0
        /// <summary>
        /// 调用find命令寻找文件
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Output Find(string name)
        {
            var result = new AdbCommand($"find {name}").Execute();

            result.ThrowIfShellExitCodeNotEqualsZero();
            return(result.Output);
        }
Esempio n. 9
0
        /// <summary>
        /// Dials (does not call) a phone number on the Android device
        /// </summary>
        /// <param name="phoneNumber">Phone number to dial</param>
        public void DialPhoneNumber(string phoneNumber)
        {
            if (this.device.State != DeviceState.ONLINE)
                return;

            AdbCommand adbCmd = Adb.FormAdbShellCommand(this.device, false, "service", "call", "phone", "1", "s16", phoneNumber);
            Adb.ExecuteAdbCommandNoReturn(adbCmd);
        }
Esempio n. 10
0
 /// <summary>
 /// 安装apk
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void installBtn_Click(object sender, EventArgs e)
 {
     dispalyTxt.AppendText(System.DateTime.Now + "  " + "开始安装" + "\r\n");
     AdbCommand.InstallApk(file);
     dispalyTxt.AppendText(System.DateTime.Now + "  " + "安装成功" + "\r\n");
     AdbCommand.InstallApkAndStart();
     dispalyTxt.AppendText(System.DateTime.Now + "  " + "启动成功" + "\r\n");
 }
Esempio n. 11
0
        private void start_Apk_Click(object sender, EventArgs e)
        {
            dispalyTxt.AppendText(System.DateTime.Now + "  " + "启动开始" + "\r\n");
            string str = string.Empty;
            bool   b   = AdbCommand.ExecuteAdbCommand("shell am start -n com.qwebob.generaldev/.GeneralDevActivity", out str);

            dispalyTxt.AppendText(System.DateTime.Now + "  " + "启动" + b.ToString() + "  " + str + "\r\n");
        }
Esempio n. 12
0
        private void PullFileMethod()
        {
            string localDataPath = Config.DefaultConfig[DATA_PATH, SCAN_DATA_PATH];

            if (string.IsNullOrEmpty(localDataPath))
            {
                localDataPath = Environment.CurrentDirectory;
                Config.DefaultConfig[DATA_PATH, SCAN_DATA_PATH] = localDataPath;
                Config.DefaultConfig.Save();
            }

            if (!Directory.Exists(localDataPath))
            {
                try
                {
                    Directory.CreateDirectory(localDataPath);
                }
                catch
                {
                    updateProcessBar.Invoke(-2);
                    return;
                }
            }

            List <string> dataFiles = AdbCommand.Ls(DEVICE_DATA_PATH);

            if (dataFiles == null || dataFiles.Count == 0)
            {
                updateProcessBar.Invoke(-2);
                return;
            }
            else
            {
                int max = toolStripProgressBar.Maximum;
                toolStripProgressBar.Value = 0;
                int count = 0;

                foreach (string s in dataFiles)
                {
                    // 获取s的文件名,判断在本地是否存在,如果存在,
                    // 则为文件增加序号,最终结果变化为:
                    // xxxx.txt,xxxx_1.txt,xxxx_2.txt等
                    string tmpPath = GetFilePath(s, localDataPath);

                    if (string.IsNullOrEmpty(tmpPath))
                    {
                        continue;
                    }

                    AdbCommand.CopyFromAndroid(s, tmpPath);
                    AdbCommand.Move(s, DEVICE_BACK_PATH + "//" + GetFileName(tmpPath, '\\') + ".txt");
                    updateProcessBar.Invoke(++count);
                }

                updateProcessBar.Invoke(-1);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Calls a phone number on the Android device
        /// </summary>
        /// <param name="phoneNumber">Phone number to call</param>
        public void CallPhoneNumber(string phoneNumber)
        {
            if (this.device.State != DeviceState.ONLINE)
                return;

            AdbCommand adbCmd = Adb.FormAdbShellCommand(this.device, false, "service", "call", "phone", "2", "s16", phoneNumber);
            Adb.ExecuteAdbCommandNoReturn(adbCmd);
            adbCmd = Adb.FormAdbShellCommand(this.device, false, "input", "keyevent", (int)KeyEventCode.BACK);
            Adb.ExecuteAdbCommandNoReturn(adbCmd);
        }
        public FileTransferCmd(string ip)
        {
            ip_   = ip;
            port_ = PORT;

            if (ip == LOOPBACK_IP)
            {
                string adbResult;
                AdbCommand.ExecuteAdbCommand("forward tcp:6661 tcp:6661", out adbResult);
            }
        }
Esempio n. 15
0
 private void buttonConnect_Click(object sender, EventArgs e)
 {
     if (AdbCommand.DeviceConnected())
     {
         toolStripStatusLabelText.Text = "设备已连接";
     }
     else
     {
         toolStripStatusLabelText.Text       = "设备未连接";
         toolStripStatusLabelDeviceTime.Text = "";
     }
 }
Esempio n. 16
0
        private void buttonTimeSync_Click(object sender, EventArgs e)
        {
            string localTimeString = DateTime.Now.ToString("yyyyMMdd.HHmmss");

            if (AdbCommand.SetDeviceDateTime(localTimeString))
            {
                toolStripStatusLabelText.Text       = "时间同步成功";
                toolStripStatusLabelDeviceTime.Text = DateTime.Now.ToString("yyyy-MM-dd.HH:mm:ss");
            }
            else
            {
                toolStripStatusLabelText.Text = "时间同步失败";
            }
        }
Esempio n. 17
0
        private static string GetAdbVersion()
        {
            string versionOutput = new AdbCommand("version").Execute().Output;
            var    match         = Regex.Match(versionOutput, @"[\w|\s]*[version\s](?<name>[\d|\.]+)([\r\n|\n]*)Version\s(?<code>\d+)", RegexOptions.Multiline);

            if (match.Success)
            {
                return(match.Result("${name}(${code})"));
            }
            else
            {
                return("unknown");
            }
        }
Esempio n. 18
0
        protected override int VisualMain()
        {
            //var warnMsg = CoreLib.Current.Languages.Get("EObsoleteAndTryImageHelper");
            //Ux.Warn(warnMsg);
            //return ERR;
            string       savePath     = null;
            DialogResult dialogResult = DialogResult.No;

            App.RunOnUIThread(() =>
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog
                {
                    Description = "请选择保存路径"
                };
                dialogResult = fbd.ShowDialog();
                savePath     = fbd.SelectedPath;
            });

            var finder = new DeviceImageFinder(TargetDevice);

            WriteLineAndSetTip("寻找Boot文件中");
            var path = finder.PathOf(DeviceImage.Recovery);

            if (path == null)
            {
                WriteLineAndSetTip("寻找路径失败");
                return(ERR);
            }
            else
            {
                WriteLine("寻找成功:" + path);
            }
            WriteLineAndSetTip("正在复制到临时目录");
            var tmpPath  = $"{Adb.AdbTmpPathOnDevice}/tmp.img";
            var cpResult = new SuCommand(TargetDevice, $"cp {path} {tmpPath}")
                           .To(OutputPrinter)
                           .Execute();
            var pullResult = new AdbCommand(TargetDevice, $"pull {tmpPath} \"{Path.Combine(savePath, "recovery.img")}\"")
                             .To(OutputPrinter)
                             .Execute();

            return(OK);
        }
Esempio n. 19
0
        private static void FindDevices(out string cmd)
        {
            while (true)
            {
                AdbCommand.ExecuteAdbCommand("devices", out cmd);

                if (cmd.Length > 25)
                {
                    cmd     = cmd.Substring(24, 16);
                    devices = cmd;
                    //connectStatus = true;
                    break;
                }
                if (connectStatus)
                {
                    break;
                }
            }
        }
Esempio n. 20
0
        private void CheckConnectionState()
        {
            // 确保adb服务运行
            AdbCommand.AdbStartServer();

            while (true)
            {
                bool state = AdbCommand.DeviceConnected();
                if (!state)
                {
                    updateConnectionState.BeginInvoke(state, "", null, null);
                }
                else
                {
                    string timeString = AdbCommand.GetDeviceDateTime();
                    updateConnectionState.BeginInvoke(state, timeString, null, null);
                }
                Thread.Sleep(5000);
            }
        }
Esempio n. 21
0
        public IActionResult ShellAdbCommand([FromBody] AdbCommand adbCommand)
        {
            if (!IsAdbCommandExecutable(adbCommand, out var actionResult))
            {
                return(actionResult);
            }

            string output;

            try
            {
                output = _externalProcesses.RunProcessAndReadOutput("adb",
                                                                    $"-s {adbCommand.AndroidDeviceId} shell {adbCommand.Command}");
                _logger.Debug($"{nameof(AdbCommand)} shell [{adbCommand.Command}] output: [{output}]");
            }
            catch (Exception ex)
            {
                return(StatusCodeExtension(500, "Failed to run adb command. " + ex.Message));
            }

            return(StatusCodeExtension(200, output));
        }
Esempio n. 22
0
 /// <summary>
 /// gets Adbs command arguments.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 public string AdbCommandArguments( string device, AdbCommand command )
 {
     if ( string.IsNullOrEmpty ( device ) ) {
         return AdbCommandToString ( command );
     } else {
         return string.Format ( "-s {0} {1}", device, AdbCommandToString ( command ) );
     }
 }
Esempio n. 23
0
        /// <summary>
        /// Runs the adb command.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="command">The command.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        private string RunAdbCommand( string device, AdbCommand command, string args, bool wait, bool logCommand )
        {
            try {
                StringBuilder result = new StringBuilder ( );
                Process proc = new Process ( );
                StringBuilder commandArg = new StringBuilder ( AdbCommandArguments ( device, command ) );
                if ( !string.IsNullOrEmpty ( args ) ) {
                    commandArg.AppendFormat ( " {0}", args );
                }
                ProcessStartInfo psi = new ProcessStartInfo ( FolderManagement.GetSdkTool ( ADB_COMMAND ), commandArg.ToString ( ) );
                if ( logCommand ) {
                    this.LogDebug ( "{0} {1}", System.IO.Path.GetFileName ( psi.FileName ), psi.Arguments );
                }

                psi.CreateNoWindow = true;
                psi.ErrorDialog = false;
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;
                psi.WindowStyle = ProcessWindowStyle.Hidden;
                proc.StartInfo = psi;
                proc.OutputDataReceived += delegate ( object sender, DataReceivedEventArgs e ) {
                    if ( !string.IsNullOrEmpty ( e.Data ) ) {
                        result.AppendLine ( e.Data.Trim ( ) );
                    }
                };

                proc.ErrorDataReceived += delegate ( object sender, DataReceivedEventArgs e ) {
                    if ( !string.IsNullOrEmpty ( e.Data ) ) {
                        result.AppendLine ( e.Data.Trim ( ) );
                    }
                };

                proc.Exited += delegate ( object sender, EventArgs e ) {

                };
                proc.Start ( );
                proc.BeginOutputReadLine ( );
                proc.BeginErrorReadLine ( );

                if ( wait ) {
                    proc.WaitForExit ( );
                } else {
                    Thread.Sleep ( 250 );
                }

                return result.ToString ( );
            } catch ( Win32Exception wex ) {
                this.LogError ( wex.Message, wex );
            } catch ( Exception ex ) {
                this.LogError ( ex.Message, ex );
            }
            return string.Empty;
        }
Esempio n. 24
0
 private string RunAdbCommand( string device, AdbCommand command, string args )
 {
     return RunAdbCommand ( device, command, args, true, true );
 }
Esempio n. 25
0
        /// <summary>
        /// runs the command
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="command">The command.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        private CommandResult CommandRun( string device, AdbCommand command, string args )
        {
            var regexOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline;

            // we may need to re-tcp connect if adb root fails. so lets do that.
            if ( device.IsMatch ( DroidExplorer.Resources.Strings.IPDeviceRegex, regexOptions ) || device.IsMatch ( DroidExplorer.Resources.Strings.HostDeviceRegex, regexOptions ) ) {
                TcpConnect ( device );
            }

            switch ( command ) {
                case AdbCommand.Connect:
                    return new TcpConnectCommandResult ( RunAdbCommand ( device, command, args, true, false ) );
                case AdbCommand.Devices:
                    return new DeviceListCommandResult ( RunAdbCommand ( device, command, "-l", true, false ) );
                case AdbCommand.Help:
                    this.LogWarn ( "Help command not supported" );
                    return new GenericCommandResult ( "* help command not supported *" );
                case AdbCommand.Root:
                    return new GenericCommandResult ( RunAdbCommand ( device, command, args, true, false ) );
                case AdbCommand.Status_Window:
                    try {
                        return new GenericCommandResult ( RunAdbCommand ( device, AdbCommand.Get_State, args, true, false ) );
                    } catch ( AdbException aex) {
                        this.LogWarn ( aex.Message, aex );
                        return new GenericCommandResult ( "Unknown" );
                    }
                case AdbCommand.Wait_For_Device:
                    this.LogWarn ( "Wait-For-Device command not supported" );
                    return new GenericCommandResult ( "* wait for device command not supported *" );
                case AdbCommand.ShellLS:
                    string path = args.Remove ( 0, Properties.Resources.ListDirectoryCommand.Trim ( ).Length - 4 ).Trim ( );
                    return new DirectoryListCommandResult ( RunAdbCommand ( device, AdbCommand.Shell, args ), path );
                case AdbCommand.ShellScreenCapture:
                    return new ScreenCaptureCommandResult ( RunAdbCommand ( device, AdbCommand.Shell, "screenrecord " + args ) );
                case AdbCommand.ShellPackageManager:
                    return new PackageManagerListPackagesCommandResult ( RunAdbCommand ( device, AdbCommand.Shell, string.Format ( "pm {0}", args ) ) );
                case AdbCommand.Jdwp:
                    return new IntegerListCommandResult ( RunAdbCommand ( device, command, args ) );
                case AdbCommand.Remount:
                    return new GenericCommandResult ( RunAdbCommand ( device, command, args, false, true ) );
                case AdbCommand.Push:
                case AdbCommand.Pull:
                    return new TransferCommandResult ( RunAdbCommand ( device, command, args ) );
                case AdbCommand.Shell:
                case AdbCommand.Get_SerialNo:
                case AdbCommand.Version:
                case AdbCommand.Get_State:
                case AdbCommand.Uninstall:
                case AdbCommand.Install:
                case AdbCommand.Backup:
                case AdbCommand.Restore:
                    return new GenericCommandResult ( RunAdbCommand ( device, command, args, true, true ) );
                case AdbCommand.Start_Server:
                case AdbCommand.Kill_Server:
                    return new GenericCommandResult ( RunAdbCommand ( device, command, args, false, true ) );
                case AdbCommand.Forward:
                case AdbCommand.Reverse:
                    return new GenericCommandResult ( RunAdbCommand ( device, command, args, false, true ) );
                case AdbCommand.Bugreport:
                case AdbCommand.Logcat:

                case AdbCommand.Emu:
                case AdbCommand.Sync:
                case AdbCommand.PPP:
                    this.LogWarn ( string.Format ( CultureInfo.InvariantCulture, "* {0} command not supported *", AdbCommandToString ( command ) ) );
                    return new GenericCommandResult ( string.Format ( CultureInfo.InvariantCulture, "* {0} command not supported *", AdbCommandToString ( command ) ) );
                default:
                    this.LogWarn ( string.Format ( CultureInfo.InvariantCulture, "* unknown command ({0}) not supported *", AdbCommandToString ( command ) ) );
                    return new GenericCommandResult ( string.Format ( "* unknown command ({0}) not supported *", AdbCommandToString ( command ) ) );
            }
        }
Esempio n. 26
0
 /// <summary>
 /// Convert the Adb Command to the string value
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private string AdbCommandToString( AdbCommand command )
 {
     return command.ToString ( ).Replace ( "_", "-" ).ToLower ( );
 }
Esempio n. 27
0
        private string CommandStart(string sendCmd)
        {
            string str = string.Empty;

            #region
            if (sendCmd.StartsWith("adbcmd"))
            {
                if (sendCmd.IndexOf("openwifiset") != -1)//wifi设置
                {
                    AdbCommand.OpenWifiSettings(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("ctrlGPS") != -1)//Gps界面设置
                {
                    AdbCommand.CtrlGps(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("swipe") != -1)//划屏
                {
                    AdbCommand.Swipe(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("getFocusedActivity") != -1)//包名类名获取
                {
                    AdbCommand.GetFocusedActivity(out str);
                }
                else if (sendCmd.IndexOf("touch") != -1)//点击
                {
                    AdbCommand.TouchScreen(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("getprop") != -1)//信息获取
                {
                    AdbCommand.GetProp(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("snap") != -1)//截屏
                {
                    AdbCommand.ScreenCapture(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("rm") != -1)//删除
                {
                    AdbCommand.Remove(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("pull") != -1)//Pull
                {
                    AdbCommand.Pull(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("push") != -1)//Push
                {
                    AdbCommand.Push(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("key") != -1)//KeyEvent
                {
                    AdbCommand.KeyEvrnt(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("wifi connect") != -1)//wifi 连接
                {
                    MessageBox.Show("请确保手机在Apk开启界面");
                    //AdbCommand.GetFocusedActivity(out str);
                    //if (str.IndexOf("com.qwebob.generaldev/.GeneralDevActivity") != -1)
                    //{
                    connectStatus = PhoneCmd_.Connect(sendCmd.Substring(20, sendCmd.Length - 20));
                    if (connectStatus)
                    {
                        wifiStatus = true;
                    }
                    adbdevices_txt.Text   = sendCmd.Substring(20, sendCmd.Length - 20);
                    Wifi_radioBtn.Checked = true;
                    usb_radioBtn.Checked  = false;
                    //}
                    //else
                    //{

                    //}
                }
                else if (sendCmd.IndexOf("tcpip") != -1)//KeyEvent
                {
                    AdbCommand.TcpIp(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("connect") != -1)//adb connect
                {
                    AdbCommand.AdbWifiConnect(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("disconnect") != -1)//adb connect
                {
                    AdbCommand.AdbDisconnect(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("start-server") != -1)//adb connect
                {
                    AdbCommand.StartServer(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("kill-server") != -1)//adb connect
                {
                    AdbCommand.KillServer(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("devices") != -1)//adb connect
                {
                    AdbCommand.Devices(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("install") != -1)//adb connect
                {
                    AdbCommand.Install(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("uninstall") != -1)//adb connect
                {
                    AdbCommand.Uninstall(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("get-serialno") != -1)//adb connect
                {
                    AdbCommand.GetSN(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("reboot") != -1)//adb connect
                {
                    AdbCommand.GetSN(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
                else if (sendCmd.IndexOf("logcat") != -1)//adb connect
                {
                    AdbCommand.LogCat(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }



                else//其他指令
                {
                    AdbCommand.ExecuteAdbShellCmd(sendCmd.Substring(7, sendCmd.Length - 7), out str);
                }
            }
            #endregion
            else if (sendCmd.IndexOf("音频操作") != -1)
            {
                if (sendCmd.IndexOf("播放声音") != -1)
                {
                    AudioCmd.Instance.ExecuteCmd("播放声音", sendCmd.Substring(9), out str);
                }
                else if (sendCmd.IndexOf("停止播放") != -1)
                {
                    AudioCmd.Instance.ExecuteCmd("停止播放", sendCmd.Substring(9), out str);
                }
                else if (sendCmd.IndexOf("录音") != -1)
                {
                    AudioCmd.Instance.ExecuteCmd("录音", sendCmd.Substring(7), out str);
                }
                else if (sendCmd.IndexOf("停止录音") != -1)
                {
                    AudioCmd.Instance.ExecuteCmd("停止录音", sendCmd.Substring(9), out str);
                }
                else
                {
                    str = "CmdNotSupport";
                }
            }
            else if (sendCmd.IndexOf("RStechCmd") != -1)
            {
                string[] strPram = sendCmd.Split(new char[] { ' ' });

                RStechCmd.Instance.ExecuteCmd(strPram[1], sendCmd.Substring(11 + strPram[1].Length), out str);
            }
            else
            {
                if (connectStatus)
                {
                    if (sendCmd.IndexOf("push") != -1)
                    {
                        PhoneCmd_.ExecutePush(sendCmd, out str);
                    }
                    else if (sendCmd.IndexOf("pull") != -1)
                    {
                        PhoneCmd_.ExecutePull(sendCmd, out str);
                    }
                    else if (sendCmd == "Wifi state")
                    {
                        PhoneCmd_.ExecuteSendData(sendCmd, out str);
                        int    num_ = str.IndexOf("ip");
                        string ip_  = str.Substring(num_ + 3);
                        PhoneIp = ip_.Remove(ip_.Length - 1);
                    }
                    else
                    {
                        PhoneCmd_.ExecuteSendData(sendCmd, out str);
                    }
                }
                else
                {
                    MessageBox.Show("请先连接手机");
                }
            }
            return(str);
        }
Esempio n. 28
0
 /// <summary>
 ///卸载apk
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void uninstallBtn_Click(object sender, EventArgs e)
 {
     AdbCommand.UninstallApk();
 }
        private void ExecuteInstallCmd(string param, out string retValue)
        {
            bool ret = AdbCommand.InstallApkAndStart();

            retValue = ret ? "Res=Pass" : "Res=Fail";
        }
Esempio n. 30
0
        private void getCurrentSettings()
        {
            StringReader reader;
            String       line = null;

            // Set to defaults
            rotateCheck.Checked        = true;
            headsetCheck.Checked       = true;
            managedCheck.Checked       = true;
            castCheck.Checked          = true;
            hotspotCheck.Checked       = true;
            bluetoothCheck.Checked     = true;
            zenCheck.Checked           = true;
            volumeCheck.Checked        = true;
            wifiCheck.Checked          = true;
            ethernetCheck.Checked      = true;
            mobileCheck.Checked        = true;
            airplaneCheck.Checked      = true;
            batteryCombo.SelectedIndex = 1;
            alarmCheck.Checked         = true;
            clockCombo.SelectedIndex   = 1;
            nfcCheck.Checked           = true;
            showZenCheck.Checked       = false;
            volumeSilentCheck.Checked  = false;
            importanceCheck.Checked    = false;

            // Get secure settings
            AdbCommand secureCommand = Adb.FormAdbShellCommand(device, false, "settings", "--user", "current", "list", "secure");
            String     secResults    = Adb.ExecuteAdbCommand(secureCommand);

            line   = null;
            reader = new StringReader(secResults);
            do
            {
                line = reader.ReadLine();
                if (line != null)
                {
                    if (line.Contains("icon_blacklist"))
                    {
                        rotateCheck.Checked    = !line.Contains("rotate");
                        headsetCheck.Checked   = !line.Contains("headset");
                        managedCheck.Checked   = !line.Contains("managed_profile");
                        castCheck.Checked      = !line.Contains("cast");
                        hotspotCheck.Checked   = !line.Contains("hotspot");
                        bluetoothCheck.Checked = !line.Contains("bluetooth");
                        zenCheck.Checked       = !line.Contains("zen");
                        volumeCheck.Checked    = !line.Contains("volume");
                        wifiCheck.Checked      = !line.Contains("wifi");
                        ethernetCheck.Checked  = !line.Contains("ethernet");
                        mobileCheck.Checked    = !line.Contains("mobile");
                        airplaneCheck.Checked  = !line.Contains("airplane");

                        if (line.Contains("battery"))
                        {
                            batteryCombo.SelectedIndex = 2;
                        }
                        else
                        {
                            batteryCombo.SelectedIndex = 1;
                        }

                        alarmCheck.Checked = !line.Contains("alarm_clock");

                        if (line.Contains(",clock") || line.Contains("clock,") || line.Contains(" clock"))
                        {
                            clockCombo.SelectedIndex = 2;
                        }
                        else
                        {
                            clockCombo.SelectedIndex = 1;
                        }

                        nfcCheck.Checked = !line.Contains("nfc_on");
                    }
                    else if (line.Contains("clock_seconds"))
                    {
                        if (line.Contains("1"))
                        {
                            clockCombo.SelectedIndex = 0;
                        }
                    }
                    else if (line.Contains("sysui_show_full_zen"))
                    {
                        showZenCheck.Checked = line.Contains("1");
                    }
                    else if (line.Contains("sysui_volume_up_silent") || line.Contains("sysui_volume_down_silent"))
                    {
                        volumeSilentCheck.Checked = line.Contains("1");
                    }
                    else if (line.Contains("show_importance_slider"))
                    {
                        importanceCheck.Checked = line.Contains("1");
                    }
                }
            }while (line != null);

            // Get system settings
            AdbCommand systemCommand = Adb.FormAdbShellCommand(device, false, "settings", "--user", "current", "list", "system");
            String     sysResults    = Adb.ExecuteAdbCommand(systemCommand);

            line   = null;
            reader = new StringReader(sysResults);
            do
            {
                line = reader.ReadLine();
                if (line != null)
                {
                    if (line.Contains("status_bar_show_battery_percent"))
                    {
                        if (line.Contains("1"))
                        {
                            batteryCombo.SelectedIndex = 0;
                        }
                    }
                }
            }while (line != null);
        }
Esempio n. 31
0
        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="file"></param>
        public void Mkdir(string file)
        {
            var result = new AdbCommand($"mkdir {file}").Execute();

            result.ThrowIfShellExitCodeNotEqualsZero();
        }
Esempio n. 32
0
        private void pushFileMethod()
        {
            string localSystemFilePath = Config.DefaultConfig[DATA_PATH, SYSTEM_DATA_PATH];


            if (string.IsNullOrEmpty(localSystemFilePath))
            {
                localSystemFilePath = Environment.CurrentDirectory;
                Config.DefaultConfig[DATA_PATH, SYSTEM_DATA_PATH] = localSystemFilePath;
                Config.DefaultConfig.Save();
            }

            if (!Directory.Exists(localSystemFilePath))
            {
                try
                {
                    Directory.CreateDirectory(localSystemFilePath);
                }
                catch
                {
                    updateProcessBar.Invoke(-2);
                    return;
                }
            }

            if (!Directory.Exists(localSystemFilePath))
            {
                return;
            }

            DirectoryInfo dir = new DirectoryInfo(localSystemFilePath);

            FileInfo[] files = dir.GetFiles();

            int txtCount = GetTxtFileCount(files);

            if (txtCount <= 0)
            {
                updateProcessBar.Invoke(-2);
                return;
            }

            int max = toolStripProgressBar.Maximum;

            toolStripProgressBar.Value = 0;
            int count = 0;

            AdbCommand.MakeDir(DEVICE_SYSTEM_PATH);

            foreach (FileInfo file in files)
            {
                if (file.FullName.Length < 4)
                {
                    continue;
                }
                else if (file.FullName.Substring(file.FullName.Length - 4, 4) == ".TXT" ||
                         file.FullName.Substring(file.FullName.Length - 4, 4) == ".txt")
                {
                    AdbCommand.CopyFromPC(file.FullName, DEVICE_SYSTEM_PATH);
                    updateProcessBar.Invoke(++count);
                }
            }

            updateProcessBar.Invoke(-1);
        }