From 69a7d8c80d9e17264138a0b64025bf93c5584a19 Mon Sep 17 00:00:00 2001 From: frankpreel Date: Mon, 9 Jan 2023 10:19:28 +0100 Subject: [PATCH 1/4] DeviceInformationTask, provides information about devices through adb getprop command --- .../tasks/DeviceInformationTask.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java diff --git a/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java b/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java new file mode 100644 index 00000000..f62319fc --- /dev/null +++ b/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java @@ -0,0 +1,63 @@ +/* + * Copyright 2023 - ECORP SAS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package ecorp.easy.installer.tasks; + +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; +import org.slf4j.LoggerFactory; + +/** + * This class provides information about devices through adb getprop command + * + * @author Frank PREEL + */ +public class DeviceInformationTask extends Task{ + private final static Logger logger = LoggerFactory.getLogger(DeviceInformationTask.class); + private final Command command; + + // "ro.build.version.release" + public DeviceInformationTask(String key){ + command = new Command(AppConstants.getADBFolderPath()+"adb"); + command.addParameter("1", "shell"); + command.addParameter("2", "getprop"); + command.addParameter("3", key); + } + + /** + * @return + * @throws java.lang.Exception + * @inheritDoc + */ + @Override + protected String call() throws Exception{ + logger.info("runADBDevicesCmd(): ", command.getCommandBase()); + CommandExecutionTask task = new CommandExecutionTask(command); + task.run(); //I feel like it lacks something... but it work in test + + CommandExecutionResult result = task.get(); + logger.debug(" raw shell outputs = {} ", result.getShellOutput()); + + return result.getShellOutput(); + } + +} \ No newline at end of file -- GitLab From 7478d3cafb4373e24237efe0f2e16626aec014e3 Mon Sep 17 00:00:00 2001 From: frankpreel Date: Mon, 9 Jan 2023 10:20:21 +0100 Subject: [PATCH 2/4] Add properties about Android version & manufacturer --- .../ecorp/easy/installer/models/Phone.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/ecorp/easy/installer/models/Phone.java b/src/main/java/ecorp/easy/installer/models/Phone.java index 95595742..e6630073 100644 --- a/src/main/java/ecorp/easy/installer/models/Phone.java +++ b/src/main/java/ecorp/easy/installer/models/Phone.java @@ -33,6 +33,8 @@ public class Phone { private boolean flashed = false; private boolean adbAuthorized = false; //private boolean isReady = false; //tell if preparation process succeed + private int androidVersion = 0; + private String manufacturer = null; private Process flashingProcess; @@ -154,7 +156,6 @@ public class Phone { public Process getFlashingProcess() { return flashingProcess; } - /** * Set the flashing process of the phone @@ -163,4 +164,41 @@ public class Phone { public void setFlashingProcess(Process flashingProcess) { this.flashingProcess = flashingProcess; } + + /** + * Get the android version + * Can return 0 if not setted + * @return + */ + public int getAndroidVersion() { + return androidVersion; + } + + /** + * Set the Android version + * @param version + */ + public void setAndroidVersion(String version) { + try { + this.androidVersion = Integer.parseInt(version.replaceAll("\\s", "")); + } catch (Exception e) {} + } + + /** + * Get the Manufacturer + * Can return null if not setted + * @return + */ + public String getManufacturer() { + return manufacturer; + } + + /** + * Set the manufacturer + * @param manufacturer + */ + public void setManufacturer(String manufacturer) { + System.out.println(manufacturer); + this.manufacturer = manufacturer.replaceAll("\\s", ""); + } } -- GitLab From fb3087ef3955cf8230b0824339b589269e434244 Mon Sep 17 00:00:00 2001 From: frankpreel Date: Mon, 9 Jan 2023 10:21:20 +0100 Subject: [PATCH 3/4] Only proceed OnePlus Android 11 --- .../DeviceDetectedController.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/DeviceDetectedController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/DeviceDetectedController.java index bd11c459..35580666 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/DeviceDetectedController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/DeviceDetectedController.java @@ -22,6 +22,7 @@ import ecorp.easy.installer.helpers.DeviceHelper; import ecorp.easy.installer.exceptions.TooManyDevicesException; import ecorp.easy.installer.models.Phone; import ecorp.easy.installer.tasks.DeviceDetectionTask; +import ecorp.easy.installer.tasks.DeviceInformationTask; import ecorp.easy.installer.utils.UiUtils; import java.io.IOException; import java.net.URL; @@ -78,6 +79,32 @@ public class DeviceDetectedController extends AbstractSubController{ DeviceDetectionTask detectorTask = new DeviceDetectionTask(); detectorTask.setOnSucceeded((WorkerStateEvent t) -> { Phone result = detectorTask.getValue(); + + final DeviceInformationTask android_version = new DeviceInformationTask("ro.build.version.release"); + final Thread tav = new Thread(android_version); + tav.setDaemon(true); + tav.start(); + android_version.setOnSucceeded((WorkerStateEvent wav) -> { + result.setAndroidVersion(android_version.getValue()); + logger.debug("android_version : {}", result.getAndroidVersion()); + }); + android_version.setOnFailed((WorkerStateEvent wav) -> {}); + + try { + tav.join(); + } catch(Exception e) { + System.out.println(e); + } + final DeviceInformationTask manufacturer = new DeviceInformationTask("ro.product.manufacturer"); + final Thread tm = new Thread(manufacturer); + tm.setDaemon(true); + tm.start(); + manufacturer.setOnSucceeded((WorkerStateEvent m) -> { + result.setManufacturer(manufacturer.getValue()); + logger.debug("Manufacturer : {}", result.getManufacturer()); + }); + manufacturer.setOnFailed((WorkerStateEvent m) -> {}); + handleDetectionResult(result); }); @@ -117,6 +144,10 @@ public class DeviceDetectedController extends AbstractSubController{ return; } + if (isIncompatibleVersion(phone)) { + displayIncompatibleDeviceFound(phone.getAdbModel()); + return; + } final String model = phone.getAdbModel(); if(model == null || model.isEmpty()) displayUnknowDeviceFound(); @@ -145,6 +176,18 @@ public class DeviceDetectedController extends AbstractSubController{ } } + // Temporary Fix see https://gitlab.e.foundation/e/devices/easy-installer/-/issues/461 + // Allow only Android 11 flash for the OnePlus + private boolean isIncompatibleVersion(Phone phone) { + try { + if (phone.getManufacturer().toLowerCase().equals("oneplus") && + phone.getAndroidVersion() != 11) { + return true; + } + } catch (Exception e) {} + return false; + } + //Note: Two below function could be merged and use a parameter to define detectionMsg.setText.. /** -- GitLab From b140d6897b005cdef0b73da53e045b555b0c89db Mon Sep 17 00:00:00 2001 From: frankpreel Date: Mon, 9 Jan 2023 10:23:12 +0100 Subject: [PATCH 4/4] Useless import removed --- .../java/ecorp/easy/installer/tasks/DeviceInformationTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java b/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java index f62319fc..53b1c85a 100644 --- a/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java +++ b/src/main/java/ecorp/easy/installer/tasks/DeviceInformationTask.java @@ -21,7 +21,7 @@ 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; import org.slf4j.LoggerFactory; -- GitLab