Skip to content

Commit fe135b4

Browse files
committed
Add another steptype for requirements and get them from config.
1 parent 64eafa4 commit fe135b4

7 files changed

Lines changed: 165 additions & 10 deletions

File tree

openandroidinstaller/app_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ def load_config(self, device_code: str):
6666
def increment_progressbar(self):
6767
"""Increment the progressbar and step counter."""
6868
self.progressbar.value = (self.num_steps - 1) / (
69-
self.num_total_steps + 2
69+
self.num_total_steps + 3
7070
) # don't show on the first step
7171
self.num_steps += 1 # increase the step counter

openandroidinstaller/assets/configs/sargo.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ metadata:
22
maintainer: Tobias Sterbak (tsterbak)
33
devicename: Pixel 3a
44
devicecode: sargo
5+
requirements:
6+
android: 12.1.0
57
steps:
68
unlock_bootloader:
79
- type: confirm_button

openandroidinstaller/assets/configs/starlte.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ metadata:
22
maintainer: Tobias Sterbak (tsterbak)
33
devicename: Samsung Galaxy S9
44
devicecode: starlte
5+
requirements:
6+
android: 10
57
steps:
68
unlock_bootloader:
79
flash_recovery:

openandroidinstaller/assets/configs/z3.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ metadata:
22
maintainer: Tobias Sterbak (tsterbak)
33
devicename: Sony Xperia Z3
44
devicecode: z3
5+
requirements:
6+
firmware: 23.5.A.1.291
57
steps:
68
unlock_bootloader:
79
- type: confirm_button

openandroidinstaller/installer_config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ def __init__(
4949
flash_recovery: List[Step],
5050
install_os: List[Step],
5151
metadata: dict,
52+
requirements: dict,
5253
):
5354
self.unlock_bootloader = unlock_bootloader
5455
self.flash_recovery = flash_recovery
5556
self.install_os = install_os
5657
self.metadata = metadata
58+
self.requirements = requirements
5759

5860
@classmethod
5961
def from_file(cls, path):
@@ -64,6 +66,7 @@ def from_file(cls, path):
6466
config = dict(raw_config)
6567
raw_steps = config["steps"]
6668
metadata = config["metadata"]
69+
requirements = config.get("requirements", None)
6770
else:
6871
logger.info("Validation of config failed.")
6972
return None
@@ -86,7 +89,9 @@ def from_file(cls, path):
8689
Step(**raw_step, title="Install OS")
8790
for raw_step in raw_steps.get("install_os", [])
8891
]
89-
return cls(unlock_bootloader, flash_recovery, install_os, metadata)
92+
return cls(
93+
unlock_bootloader, flash_recovery, install_os, metadata, requirements
94+
)
9095

9196

9297
def _load_config(device_code: str, config_path: Path) -> Optional[InstallerConfig]:
@@ -139,6 +144,10 @@ def validate_config(config: str) -> bool:
139144
"devicename": str,
140145
"devicecode": str,
141146
},
147+
schema.Optional("requirements"): {
148+
schema.Optional("android"): str,
149+
schema.Optional("firmware"): str,
150+
},
142151
"steps": {
143152
"unlock_bootloader": schema.Or(None, [step_schema]),
144153
"flash_recovery": [step_schema],

openandroidinstaller/openandroidinstaller.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
icons,
3939
)
4040
from loguru import logger
41-
from views import SelectFilesView, StepView, SuccessView, WelcomeView
41+
from views import SelectFilesView, StepView, SuccessView, WelcomeView, RequirementsView
4242
from tool_utils import run_command
4343

4444
# where to write the logs
4545
logger.add("openandroidinstaller.log")
4646

4747
# Toggle to True for development purposes
48-
DEVELOPMENT = False
49-
DEVELOPMENT_CONFIG = "yuga" # "a3y17lte" # "sargo"
48+
DEVELOPMENT = True
49+
DEVELOPMENT_CONFIG = "z3" # "a3y17lte" # "sargo"
5050

5151

5252
PLATFORM = sys.platform
@@ -75,16 +75,20 @@ def __init__(self):
7575
self.view = Column(expand=True, width=1200)
7676

7777
# create default starter views
78-
welcome = WelcomeView(
78+
welcome_view = WelcomeView(
7979
on_confirm=self.confirm,
8080
state=self.state,
8181
)
82-
select_files = SelectFilesView(
82+
requirements_view = RequirementsView(
83+
on_confirm=self.confirm,
84+
state=self.state,
85+
)
86+
select_files_view = SelectFilesView(
8387
on_confirm=self.confirm,
8488
state=self.state,
8589
)
8690
# ordered to allow for pop
87-
self.default_views = [select_files, welcome]
91+
self.default_views = [select_files_view, requirements_view, welcome_view]
8892
# create the final success view
8993
self.final_view = SuccessView(state=self.state)
9094

@@ -124,7 +128,7 @@ def log_version_infos(bin_path):
124128
"""Log the version infos of adb, fastboot and heimdall."""
125129
# adb
126130
adbversion = [line for line in run_command("adb", ["version"], bin_path)]
127-
adbversion = '\n'.join(adbversion[:1])
131+
adbversion = "\n".join(adbversion[:1])
128132
logger.info(f"{adbversion}")
129133
# fastboot
130134
fbversion = [line for line in run_command("fastboot", ["--version"], bin_path)]
@@ -137,7 +141,7 @@ def log_version_infos(bin_path):
137141
def main(page: Page):
138142
logger.info(f"Running OpenAndroidInstaller on {PLATFORM}")
139143
log_version_infos(bin_path=BIN_PATH)
140-
logger.info(20*"-")
144+
logger.info(100 * "-")
141145
# Configure the application base page
142146
page.title = "OpenAndroidInstaller"
143147
page.window_height = 780

openandroidinstaller/views.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ class BaseView(UserControl):
6767
def __init__(self, state: AppState, image: str = "placeholder.png"):
6868
super().__init__()
6969
self.state = state
70+
# right part of the display, add content here.
7071
self.right_view = Column(expand=True)
72+
# left part of the display: used for displaying the images
7173
self.left_view = Column(
7274
width=600,
7375
controls=[Image(src=f"/assets/imgs/{image}")],
@@ -81,6 +83,140 @@ def __init__(self, state: AppState, image: str = "placeholder.png"):
8183
)
8284

8385

86+
class RequirementsView(BaseView):
87+
"""View to display requirements and ask for confirmation."""
88+
89+
def __init__(
90+
self,
91+
state: AppState,
92+
on_confirm: Callable,
93+
):
94+
super().__init__(state=state)
95+
self.on_confirm = on_confirm
96+
97+
def build(self):
98+
self.continue_button = ElevatedButton(
99+
"Continue",
100+
on_click=self.on_confirm,
101+
icon=icons.NEXT_PLAN_OUTLINED,
102+
disabled=True,
103+
expand=True,
104+
)
105+
106+
# build up the main view
107+
self.right_view.controls.extend(
108+
[
109+
get_title("Check the Requirements"),
110+
Text(
111+
"Before continuing you need to check some requirements to progress. Please read the instructions and check the boxes if everything is fine."
112+
),
113+
Divider(),
114+
]
115+
)
116+
self.checkboxes = []
117+
118+
def enable_continue_button(e):
119+
"""Enable the continue button if all checkboxes are ticked."""
120+
for checkbox in self.checkboxes:
121+
if not checkbox.value:
122+
logger.info(checkbox)
123+
self.continue_button.disabled = True
124+
return
125+
logger.info("All requirements ticked. Allow to continue")
126+
self.continue_button.disabled = False
127+
self.right_view.update()
128+
129+
# check if there are additional requirements given in the config
130+
if self.state.config.requirements:
131+
# android version
132+
required_android_version = self.state.config.requirements.get("android")
133+
if required_android_version:
134+
android_checkbox = Checkbox(
135+
label="The required android version is installed. (Or I know the risk of continuing)",
136+
on_change=enable_continue_button,
137+
)
138+
android_version_check = Column(
139+
[
140+
Markdown(
141+
f"""
142+
#### Android Version {required_android_version}:
143+
Before following these instructions please ensure that the device is currently using Android {required_android_version} firmware.
144+
If the vendor provided multiple updates for that version, e.g. security updates, make sure you are on the latest!
145+
If your current installation is newer or older than Android {required_android_version}, please upgrade or downgrade to the required
146+
version before proceeding (guides can be found on the internet!).
147+
"""
148+
),
149+
android_checkbox,
150+
]
151+
)
152+
self.checkboxes.append(android_checkbox)
153+
self.right_view.controls.append(android_version_check)
154+
155+
# firmware version
156+
required_firmware_version = self.state.config.requirements.get("firmware")
157+
if required_firmware_version:
158+
firmware_checkbox = Checkbox(
159+
label="The required firmware version is installed. (Or I know the risk of continuing)",
160+
on_change=enable_continue_button,
161+
)
162+
firmware_version_check = Column(
163+
[
164+
Markdown(
165+
f"""
166+
#### Firmware Version {required_firmware_version}:
167+
Before following these instructions please ensure that the device is on firmware version {required_firmware_version}.
168+
To discern this, you can run the command `adb shell getprop ro.build.display.id` on the stock ROM.
169+
If the device is not on the specified version, please follow the instructions below to install it.
170+
"""
171+
),
172+
firmware_checkbox,
173+
]
174+
)
175+
self.checkboxes.append(firmware_checkbox)
176+
self.right_view.controls.append(firmware_version_check)
177+
178+
# default requirements: battery level
179+
battery_checkbox = Checkbox(
180+
label="The battery level is over 80%.",
181+
on_change=enable_continue_button,
182+
)
183+
battery_version_check = Column(
184+
[
185+
Markdown(
186+
f"""
187+
#### Battery level over 80%
188+
Before continuing make sure your device battery level is above 80%.
189+
"""
190+
),
191+
battery_checkbox,
192+
]
193+
)
194+
self.checkboxes.append(battery_checkbox)
195+
self.right_view.controls.append(battery_version_check)
196+
197+
# default requirement: disable lock code and fingerprint
198+
lock_checkbox = Checkbox(
199+
label="No lock code or fingerprint lock enabled.",
200+
on_change=enable_continue_button,
201+
)
202+
lock_check = Column(
203+
[
204+
Markdown(
205+
f"""
206+
#### Disable all device lock codes and fingerprint locks.
207+
"""
208+
),
209+
lock_checkbox,
210+
]
211+
)
212+
self.checkboxes.append(lock_checkbox)
213+
self.right_view.controls.append(lock_check)
214+
215+
# add the final confirm and continue button
216+
self.right_view.controls.append(Row([self.continue_button], alignment="center"))
217+
return self.view
218+
219+
84220
class WelcomeView(BaseView):
85221
def __init__(
86222
self,

0 commit comments

Comments
 (0)