Skip to content

Commit b99e84f

Browse files
authored
Refactoring and lifeimprovements (#18)
- Refactor search_device function - Move call to phone function to other module - Enable the continue button only if the previous call was successful - Allow loading local configs also
2 parents 2068455 + c651cb4 commit b99e84f

File tree

11 files changed

+838
-207
lines changed

11 files changed

+838
-207
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ install:
33
poetry install
44
poetry run python scripts/download-tools.py
55

6+
test:
7+
poetry run pytest tests/
8+
69
app:
710
poetry run python openandroidinstaller/openandroidinstaller.py
811

9-
build-app: install
12+
build-app:
1013
poetry run pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "/assets/favicon.ico" --add-data "openandroidinstaller/assets:assets" --add-binary "openandroidinstaller/bin/adb:bin" --add-binary "openandroidinstaller/bin/fastboot:bin" --add-binary "openandroidinstaller/bin/heimdall:bin"
1114

1215

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ Vendor | Device Name | CodeName | Models | Status
3232
---|---|---|---|---
3333
Samsung | Galaxy A3 2017 | a3y17lte | SM-A320FL | tested
3434
Samsung | Galaxy A5 2016 | a5xelte | | under development
35+
Samsung | Galaxy S7 | herolte | | planned
3536
Google | Pixel 3a | sargo | sargo | tested
3637
Sony | Xperia Z | yuga | C6603 | tested
3738
Sony | Xperia Z3 | z3 | | under development
38-
Sony | Xperia ZX | kagura | | under development
39+
Sony | Xperia ZX | kagura | | planned
3940
Fairphone | Fairphone 2 | FP2 | | under development
41+
Xiaomi | Mi 9 Lite | pyxis | | planned
4042

4143

4244
## Usage

openandroidinstaller/assets/configs/a3y17lte.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ steps:
1717
content: "Unplug the USB cable from your device. Then manually reboot into recovery by pressing the Volume Down + Power buttons for 8~10 seconds until the screen turns black & release the buttons immediately when it does, then boot to recovery with the device powered off, hold Volume Up + Home + Power."
1818
- title: "Flash LineageOS"
1919
type: confirm_button
20-
content: "Now tap 'Wipe' on your phone. Then tap 'Format Data' and continue with the formatting process. This will remove encryption and delete all files stored in the internal storage. Confirm to continue once you are done."
20+
content: "Now swipe right to allow modifications then tap 'Wipe' on your phone. Next tap 'Format Data' and follow the instructions on your phone to continue with the formatting process. This will remove encryption and delete all files stored in the internal storage. Confirm to continue once you are done."
2121
- title: "Flash LineageOS"
2222
type: confirm_button
23-
content: "Return to the previous menu on your phone and tap 'Advanced Wipe', then select the 'Cache' and 'System' partitions and then 'Swipe to Wipe'. Confirm to continue once you are done."
23+
content: "Return to the previous menu on your phone by going back two times. Them tap 'Advanced Wipe', and select the 'Cache' and 'System' partitions and then 'Swipe to Wipe'. Confirm to continue once you are done."
2424
- title: "Flash LineageOS"
2525
type: confirm_button
26-
content: "Now connect the phone to the computer again with the USB-cable. On the device, go back and select “Advanced”, “ADB Sideload”, then swipe to begin sideload. Then confirm here."
26+
content: "Now connect the phone to the computer again with the USB-cable. On the device, go back three times and select “Advanced”, then “ADB Sideload”. Select 'Wipe cache' and 'Wipe dalvik cache', then swipe to begin sideload. Then confirm here."
2727
- title: "Flash LineageOS"
2828
type: call_button
2929
content: "Now it's time to flash the LineageOS image. Don't remove the USB-Cable and press 'Confirm and run' to start! This might take a while. Confirm after it's done."

openandroidinstaller/assets/configs/a5xelte.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ steps:
2020
content: "Now tap 'Wipe' on your phone. Then tap 'Format Data' and continue with the formatting process. This will remove encryption and delete all files stored in the internal storage. Confirm to continue once you are done."
2121
- title: "Flash LineageOS"
2222
type: confirm_button
23-
content: "Return to the previous menu on your phone and tap 'Advanced Wipe', then select the 'Cache' and 'System' partitions and then 'Swipe to Wipe'. Confirm to continue once you are done."
23+
content: "Return to the previous menu on your phone by going back two times. Them tap 'Advanced Wipe', and select the 'Cache' and 'System' partitions and then 'Swipe to Wipe'. Confirm to continue once you are done."
2424
- title: "Flash LineageOS"
2525
type: confirm_button
26-
content: "Now connect the phone to the computer again with the USB-cable. On the device, go back and select “Advanced”, “ADB Sideload”, then swipe to begin sideload. Then confirm here."
26+
content: "Now connect the phone to the computer again with the USB-cable. On the device, go back three times and select “Advanced”, then “ADB Sideload”. Select 'Wipe cache' and 'Wipe dalvik cache', then swipe to begin sideload. Then confirm here."
2727
- title: "Flash LineageOS"
2828
type: call_button
2929
content: "Now it's time to flash the LineageOS image. Don't remove the USB-Cable and press 'Confirm and run' to start! This might take a while. Confirm after it's done."

openandroidinstaller/installer_config.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# If not, see <https://www.gnu.org/licenses/>."""
1414
# Author: Tobias Sterbak
1515

16-
from typing import List
16+
from typing import List, Optional
17+
from pathlib import Path
18+
from loguru import logger
1719

1820
import yaml
1921

@@ -50,7 +52,33 @@ def from_file(cls, path):
5052
raw_steps = config["steps"]
5153
metadata = config["metadata"]
5254
except yaml.YAMLError as exc:
53-
print(exc)
55+
logger.info(exc)
5456

5557
steps = [Step(**raw_step) for raw_step in raw_steps]
5658
return cls(steps, metadata)
59+
60+
61+
def _load_config(device_code: str, config_path: Path) -> Optional[InstallerConfig]:
62+
"""
63+
Function to load a function from given path and directory path.
64+
65+
Try to load local file in the same directory as the executable first, then load from assets.
66+
"""
67+
# try loading a custom local file first
68+
custom_path = Path.cwd().joinpath(Path(f"{device_code}.yaml"))
69+
try:
70+
config = InstallerConfig.from_file(custom_path)
71+
logger.info(f"Loaded custom device config from {custom_path}.")
72+
logger.info(f"Config metadata: {config.metadata}.")
73+
return config
74+
except FileNotFoundError:
75+
# if no localfile, then try to load a config file from assets
76+
path = config_path.joinpath(Path(f"{device_code}.yaml"))
77+
try:
78+
config = InstallerConfig.from_file(path)
79+
logger.info(f"Loaded device config from {path}.")
80+
logger.info(f"Config metadata: {config.metadata}.")
81+
return config
82+
except FileNotFoundError:
83+
logger.info(f"No device config found for {path}.")
84+
return None

0 commit comments

Comments
 (0)