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

Commit 00abe678 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

make device detection and download source to work as expected. Add code in...

make device detection and download source to work as expected. Add code in MainController & DeviceHelper to load flash process after preparation process
parent 5bfcbf00
Loading
Loading
Loading
Loading
+96 −80
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package ecorp.easy.installer.controllers;

import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.controllers.subcontrollers.AbstractSubController;
import ecorp.easy.installer.EasyInstaller;
import ecorp.easy.installer.controllers.steps.StepController;
import ecorp.easy.installer.helpers.DeviceHelper;
import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.models.PreparationProcess;
import ecorp.easy.installer.models.Process;
import ecorp.easy.installer.models.Steps.Step;
import ecorp.easy.installer.utils.UiUtils;
@@ -80,20 +80,13 @@ public class MainWindowController implements Initializable {
        
        //Just for test
        device.setAdbDevice("dummy");
        try{
            currentProcess =  DeviceHelper.loadPreparationProcess(device);
        }catch(IOException e){
            logger.info("Impossible to load preparation config file");
        }catch(NullPointerException | ParseException | NumberFormatException e){
            logger.info("Error in preparation config file :"+e.getMessage());
        }
        currentStepKey = "p0";
        
        loadProcess();
        
        StepController.setParentController(this);
        
        loadNextStep(currentStepKey);

        /*loadSubScene();*/
        DoubleProperty fontSize = new SimpleDoubleProperty(0);
        
        fontSize.bind(root.widthProperty().add(root.heightProperty()).divide(123.2)); //72 = 1440 (default width): 20 (default font size). 51.2 = 1024 / 20        
@@ -172,17 +165,7 @@ public class MainWindowController implements Initializable {
     */
    public void loadSubScene(){
        logger.info("loadSubScene("+currentSubRootId+")");
        
        if(currentSubRootId == null || currentSubRootId.isEmpty()){
            
            currentSubRootId =loadSubUI("1-beforeYouBegin.fxml", "before_mTitle").getId();
        }else{
        switch(currentSubRootId){
case "enableDevMode":
                case "deviceDetectedRoot":
                    changeView(currentSubRootId, "5-downloadSrc.fxml", "download_mTitle");
                    disableNextButton(true);
                    break;
            case "downloadSceneRoot":
                changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle");
                break;
@@ -213,7 +196,6 @@ case "enableDevMode":
                break;
        }
    }
    }
    
    public void retryToFlash(){
        changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle");
@@ -362,17 +344,23 @@ case "enableDevMode":
        return currentStepKey;
    }
    
    /**
     * @TODO: find a better name
     * @param nextStepKey 
     */
    public void loadNextStep(String nextStepKey){
        if(nextStepKey != null){
        if(nextStepKey == null){ //end of the currentProcess
            loadProcess();
            nextStepKey = currentStepKey;
        }else{
            this.currentStepKey = nextStepKey;
        }
        Step step = this.currentProcess.getStep(nextStepKey);
        if( step != null ){
            switch(step.getType()){
                case "custom":
                    loadSubUI("customStep.fxml", null);
                    break;
                    case "account":
                        break;
                case "executable":
                    break;
                case "custom-executable":
@@ -391,10 +379,38 @@ case "enableDevMode":
                    }
                    break;
                case "deviceDetection":
                        loadSubUI("4-deviceDetected.fxml", "detect_mTitle");
                    loadSubUI("deviceDetection.fxml", "detect_mTitle");
                    break;
                case "account":
                    break;
                case "downloadSources":
                    loadSubUI("downloadSrc.fxml", "download_mTitle");
                    break;
                default:
                    logger.error("Invalid nextStep key");
                    break;
            }
        }
    }
    
    private void loadProcess(){
        try{
            if(currentProcess == null){
                logger.info("|=== Start of Preparation process ===|");
                currentProcess =  DeviceHelper.loadPreparationProcess(device);
                currentStepKey = "p0"; //@TODO define first key in process 
            }else if(currentProcess instanceof PreparationProcess){
                logger.info("|=== End of Preparation process ===|");
                currentProcess = DeviceHelper.loadFlashProcess(device);
                currentStepKey = "f0";
            }else {
                logger.error("No process to load.");
            }
        }catch(IOException e){
            logger.info("Impossible to load preparation config file");
        }catch(NullPointerException | ParseException | NumberFormatException e){
            logger.info("Error in preparation config file :"+e.getMessage());
        }

    }
}
 No newline at end of file
+9 −9
Original line number Diff line number Diff line
@@ -14,10 +14,11 @@
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package ecorp.easy.installer.controllers.subcontrollers;
package ecorp.easy.installer.controllers.steps;


import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.controllers.subcontrollers.AbstractSubController;
import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.tasks.DeviceDetectionTask;
import ecorp.easy.installer.utils.UiUtils;
@@ -38,13 +39,11 @@ import org.slf4j.LoggerFactory;
 *
 * @author Vincent Bourgmayer
 */
public class DeviceDetectedController extends AbstractSubController{
    private final static Logger logger = LoggerFactory.getLogger(DeviceDetectedController.class);
public class DeviceDetectionController extends StepController{
    private final static Logger logger = LoggerFactory.getLogger(DeviceDetectionController.class);
    @FXML private Button buyNewDevice;
    @FXML private Button startDetectionButton;
    @FXML private Label detectionMsg;
    @FXML private VBox deviceDetectedRoot;
    
    
    @Override
    public void initialize(URL location, ResourceBundle resources){
@@ -52,6 +51,7 @@ public class DeviceDetectedController extends AbstractSubController{
        UiUtils.hideNode(buyNewDevice);
        UiUtils.hideNode(startDetectionButton);
        detectionMsg.setText(i18n.getString("detect_lbl_detecting"));
        parentController.disableNextButton(true);
        startDetection();
    }        
    
@@ -61,8 +61,8 @@ public class DeviceDetectedController extends AbstractSubController{
    public void startDetection(){
        logger.info("startDetection()");
        
        if(deviceDetectedRoot.getChildren().get(0).getClass().equals(VBox.class)){
            deviceDetectedRoot.getChildren().remove(0);
        if( ((VBox)stepRoot).getChildren().get(0).getClass().equals(VBox.class)){
            ((VBox)stepRoot).getChildren().remove(0);
            UiUtils.showNode(detectionMsg);
        }
        
@@ -150,7 +150,7 @@ public class DeviceDetectedController extends AbstractSubController{
    private void displayUnauthorizedDeviceFound(){

        VBox container = new VBox();
        container.maxWidthProperty().bind(deviceDetectedRoot.widthProperty().multiply(0.69));
        container.maxWidthProperty().bind(((VBox)stepRoot).widthProperty().multiply(0.69));
        container.setAlignment(Pos.CENTER);
        container.setSpacing(25.0);
        
@@ -170,7 +170,7 @@ public class DeviceDetectedController extends AbstractSubController{
        
        container.getChildren() .addAll( lblA, lblB, imageView, lblC);
        
        deviceDetectedRoot.getChildren().add(0, container);
        ((VBox)stepRoot).getChildren().add(0, container);
        UiUtils.hideNode(detectionMsg);
        showTryAgainButton(true);
    }
+4 −7
Original line number Diff line number Diff line
@@ -14,10 +14,11 @@
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package ecorp.easy.installer.controllers.subcontrollers;
package ecorp.easy.installer.controllers.steps;


import ecorp.easy.installer.controllers.MainWindowController;
import ecorp.easy.installer.controllers.subcontrollers.AbstractSubController;
import ecorp.easy.installer.models.PreparationProcess;
import ecorp.easy.installer.models.SourceToDownload;
import ecorp.easy.installer.tasks.DownloadTask;
@@ -42,7 +43,7 @@ import org.slf4j.LoggerFactory;
 *
 * @author Vincent Bourgmayer
 */
public class DownloadSrcController extends AbstractSubController {
public class DownloadSrcController extends StepController {
    private final static Logger logger = LoggerFactory.getLogger(DownloadSrcController.class);
    private @FXML ProgressBar preparationProgressBar;
    private @FXML Label progressLabel;
@@ -57,11 +58,7 @@ public class DownloadSrcController extends AbstractSubController {
    public void initialize(URL location, ResourceBundle resources) {
        super.initialize(location, resources);
        UiUtils.hideNode(restartDownloadBtn);
    }
        
    @Override
    public void setParentController(MainWindowController parentController){
        super.setParentController(parentController);
        sourcesToDownload = ((PreparationProcess) parentController.getCurrentProcess()).getSources();
        taskIterator =  sourcesToDownload.entrySet().iterator();
        startNextDownload();
+0 −1
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ public abstract class ConfigParser {
                break;
            default:
                result = parseBasicStep(yaml, type);
                //logger.debug("Ignore step with type: "+type);
                break;
        }
        return result;
+18 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package ecorp.easy.installer.helpers;
import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.models.PreparationProcess;
import ecorp.easy.installer.models.Process;
import ecorp.easy.installer.models.SourceToDownload;
import ecorp.easy.installer.models.Steps.Step;
import java.io.IOException;
@@ -93,24 +94,22 @@ public class DeviceHelper {
     * @throws NumberFormatException There is issue in yaml with a number
     */
    public static PreparationProcess loadPreparationProcess(Phone phone) throws IOException, ParseException, NumberFormatException, NullPointerException{
        //First create the fixed step : enable adb, etc.
        
        //@TODO: First create the fixed step : enable adb, etc.
        final Map yamlContent = loadYaml(phone.getAdbDevice()+"_preparation.yml");
        if(yamlContent == null) return null;
        
        //first load stepCount
        int stepsCount = (Integer) yamlContent.get("stepsCount");
        final PreparationProcess preparationProcess = new PreparationProcess(stepsCount);
        final PreparationProcess result = new PreparationProcess(stepsCount);

        //second part consist to load Step object from YAML
        
        HashMap<String, Step> steps = parseSteps( (Map) yamlContent.get("preparation") );
        preparationProcess.addSteps(steps );
        HashMap<String, Step> steps = parseSteps( (Map) yamlContent.get("steps") );
        result.addSteps(steps );
        
        //third part consist to load sources to download
        preparationProcess.setSources(ConfigParser.parseSources((Map) yamlContent.get("sources")));
        
        return preparationProcess;
        result.setSources(ConfigParser.parseSources((Map) yamlContent.get("sources")));
        return result;
    }
    

@@ -130,4 +129,15 @@ public class DeviceHelper {
        }
        return result;
    }

    public static Process loadFlashProcess(Phone phone) throws IOException, ParseException, NumberFormatException, NullPointerException{
        final Map yamlContent = loadYaml(phone.getAdbDevice()+"_flash.yml");
        int stepsCount = (Integer) yamlContent.get("stepsCount");
        Process result = new Process(stepsCount);
        
        HashMap<String, Step> steps = parseSteps( (Map) yamlContent.get("steps") );
        result.addSteps(steps );
        
        return result;
    }
}
Loading