Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e59ebe0 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

DeviceDetectionTask now used CommandExecutionTask and CommandExecutionResult

parent 047fea20
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import java.util.Map;
 * @author Vincent Bourgmayer
 * @deprecated 
 */
@Deprecated
public class Step {
    private StepUi ui; //Datas about user interface
    private String script;  //script's file script
+19 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.exceptions.TooManyDevicesException;
import ecorp.easy.installer.models.Command;
import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.models.steps.CommandExecutionResult;
import java.util.regex.Pattern;
import javafx.concurrent.Task;
import org.slf4j.Logger;
@@ -31,10 +32,17 @@ import org.slf4j.LoggerFactory;
 * @author Ingo
 */
public class DeviceDetectionTask extends Task<Phone>{
    final String CMD_adbDevices = "devices";    
    private final static Logger logger = LoggerFactory.getLogger(DeviceDetectionTask.class);
    private final static Pattern LINEBREAK_PATTERN = Pattern.compile("\\R");
    private final static Pattern SPACE_PATTERN = Pattern.compile("\\s+");
    private final Command command;

    
    public DeviceDetectionTask(){
        command = new Command(AppConstants.getADBFolderPath()+"adb");
        command.addParameter("1", "devices");
        command.addParameter("2", "-l");
    }
    
    /**
     * @inheritDoc 
@@ -45,7 +53,7 @@ public class DeviceDetectionTask extends Task<Phone>{
    protected Phone call() throws Exception{
        Phone detectedDevice = null;

        detectedDevice = runAdbDevicesCmd(AppConstants.getADBFolderPath()+"adb");
        detectedDevice = runAdbDevicesCmd();

        if(detectedDevice != null){
            logger.debug("call(), result: Device found");
@@ -59,19 +67,20 @@ public class DeviceDetectionTask extends Task<Phone>{
     * @return
     * @throws Exception 
     */
    private Phone runAdbDevicesCmd(String baseCmdString) throws Exception{
        logger.info("runADBDevicesCmd({})", baseCmdString);
    private Phone runAdbDevicesCmd() throws Exception{
        logger.info("runADBDevicesCmd(): ", command.getCommandBase());

        
        //@TODO use CommandExecutionTask instead of Command
        Command cmd = new Command(baseCmdString);
        cmd.addParameter("1", CMD_adbDevices);
        cmd.addParameter("2", "-l");
        cmd.execAndReadOutput();     
        CommandExecutionTask task = new CommandExecutionTask(command);

        task.run(); //I feel like it lacks something... but it work in test
        
        CommandExecutionResult result = task.get();
        
        Phone detectedDevice = null;
        String[] outputs = LINEBREAK_PATTERN.split(cmd.getShellOutput());
        logger.debug(" raw shell outputs = {} ", cmd.getShellOutput());
        String[] outputs = LINEBREAK_PATTERN.split(result.getShellOutput());
        logger.debug(" raw shell outputs = {} ", result.getShellOutput());
        if(outputs.length <=1){
            logger.info("  Waiting");
            Thread.sleep(2250);
@@ -105,7 +114,6 @@ public class DeviceDetectionTask extends Task<Phone>{
     */
    private Phone checkAdbDevicesResult(String resultLine){
        logger.debug("checkAdbDevicesResult({})", resultLine);
        boolean deviceFound = false;
        Phone result = new Phone();
        if(resultLine.contains("unauthorized")){
            logger.info("   Unauthorized device found");