Skip to content

Commit 32841e1

Browse files
authored
Package tools (#11)
- Automatically download adb, fastboot and heimdall - Enable packaging the tools in Linux to executable - Update how configs are named and detected - Add parts to README (improved install instructions, licence and used tools)
2 parents acf4db4 + 7eec486 commit 32841e1

File tree

13 files changed

+209
-51
lines changed

13 files changed

+209
-51
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
install:
2-
sudo apt update && sudo apt install android-tools-adb android-tools-fastboot
2+
curl -sSL https://install.python-poetry.org | python3 -
33
poetry install
4+
poetry run python scripts/download-tools.py
45

56
app:
67
poetry run python openandroidinstaller/openandroidinstaller.py
78

8-
build-app:
9-
poetry run pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "/assets/favicon.ico" --add-data "openandroidinstaller/assets:assets"
9+
build-app: install
10+
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"
11+
1012

1113
clean-build:
1214
rm -rf build/ dist/

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,28 @@ Sony | Xperia Z3 | z3 | | under development
3838
Sony | Xperia ZX | kagura | | under development
3939
Fairphone | Fairphone 2 | FP2 | | under development
4040

41-
## Installation
41+
42+
## Usage
43+
4244
Currently, only linux is supported.
4345

4446
1. Download the AppImage, .exe or appropriate file for your OS.
45-
2. Install `adb` and `fastboot` by running `sudo apt install android-tools-adb android-tools-fastboot`
46-
3. OPTIONAL: Install `heimdall` for Samsung Devices:
47-
- download heimdall: https://androidfilehost.com/?w=files&flid=304516
48-
- install heimdall:
49-
- `$ unzip /path/to/heimdall_ubuntu.zip -d /tmp`
50-
- `$ cp /tmp/bin/heimdall* /usr/bin/`
51-
- `$ rm -rf /tmp/bin`
52-
53-
## Usage
47+
2. Download the lineageOS image and the custom recovery image. A source for files can be found here: https://lineageosroms.com
48+
3. Start the desktop app and follow the instructions.
5449

55-
Download the lineageOS image and the custom recovery image. A source for files can be found here: https://lineageosroms.com
56-
Start the desktop app and follow the instructions.
5750

5851
## Run OpenAndroidInstaller for development
5952

53+
Currently development is only supported on Ubunut Linux. MacOS should also work fine.
54+
6055
1. Clone the main branch of this repository
61-
2. Follow the steps 2. and 3. from 'Installation' above.
62-
3. Run `make poetry` and `make install` to setup poetry and the relevant requirements
63-
4. Run `make app` to start the desktop app from the source.
56+
2. Run `make install` to install poetry to manage python and install the requirend dependencies like adb, fastboot and heimdall.
57+
3. Run `make app` to start the desktop app from the source.
58+
59+
60+
## Contributing
6461

65-
## Contribute your own installation configurations
62+
### Contribute your own installation configurations
6663

6764
If you want to use the tool for a non-supported smartphone, the fastest way is to adapt an [existing config file](https://github.com/openandroidinstaller-dev/openandroidinstaller/tree/main/openandroidinstaller/assets/configs).
6865

@@ -84,8 +81,22 @@ Every step in the config file corresponds to one view in the application. These
8481
After you created a config file, you can open a pull request to make the file available to other users. The file should be named after device name output by `adb shell dumpsys bluetooth_manager | grep 'name:' | cut -c9-` when the devices is connected to the computer. Please also add the device to the supported devices table above.
8582

8683

87-
## Contributing
84+
## Tools
85+
86+
- The [Android SDK Platform Tools](https://developer.android.com/studio/releases/platform-tools) (such as adb and fastboot) are [Apache](https://android.googlesource.com/platform/system/adb/+/refs/heads/master/NOTICE)-licensed universal Android utilities
87+
- [Heimdall](https://gitlab.com/BenjaminDobell/Heimdall/) is an [MIT](https://gitlab.com/BenjaminDobell/Heimdall/-/blob/master/LICENSE)-licensed replacement for the leaked ODIN tool to flash Samsung devices.
88+
8889

8990
## Acknowledgements
9091

9192
* Funded from September 2022 until February 2023 by ![logos of the "Bundesministerium für Bildung und Forschung", Prodotype Fund and OKFN-Deutschland](resources/pf_funding_logos.svg)
93+
94+
95+
## License
96+
Original development by [Tobias Sterbak](https://tobiassterbak.com). Copyright (C) 2022.
97+
98+
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.
99+
100+
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.
101+
102+
You should have received a copy of the GNU General Public License along with this program. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).

openandroidinstaller/assets/configs/Fairphone 2.yaml renamed to openandroidinstaller/assets/configs/FP2.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
metadata:
2-
- maintainer: Tobias Sterbak (tsterbak)
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Fairphone 2
34
requirements:
45
steps:
56
- title: "Flash a custom recovery"

openandroidinstaller/assets/configs/Samsung Galaxy A3 2017.yaml renamed to openandroidinstaller/assets/configs/a3y17lte.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
metadata:
2-
- maintainer: Tobias Sterbak (tsterbak)
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Samsung Galaxy A3 (2017)
34
requirements:
45
- heimdall
56
steps:

openandroidinstaller/assets/configs/Samsung Galaxy A5 2016.yaml renamed to openandroidinstaller/assets/configs/a5xelte.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
metadata:
2-
- maintainer: Tobias Sterbak (tsterbak)
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Samsung Galaxy A5 (2016)
34
requirements:
45
- heimdall
56
steps:

openandroidinstaller/assets/configs/Pixel 3a.yaml renamed to openandroidinstaller/assets/configs/sargo.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
metadata:
2-
- maintainer: Tobias Sterbak (tsterbak)
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Pixel 3a
34
requirements:
45
steps:
56
- title: "Unlock the bootloader"

openandroidinstaller/assets/configs/Xperia Z.yaml renamed to openandroidinstaller/assets/configs/yuga.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
metadata:
2-
- maintainer: Tobias Sterbak (tsterbak)
2+
maintainer: Tobias Sterbak (tsterbak)
3+
devicename: Sony Xperia Z
34
requirements:
45
steps:
56
- title: "Unlock the bootloader"

openandroidinstaller/installer_config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,20 @@ def __init__(
3737

3838

3939
class InstallerConfig:
40-
def __init__(self, steps: List[Step]):
40+
def __init__(self, steps: List[Step], metadata: dict):
4141
self.steps = steps
42+
self.metadata = metadata
4243

4344
@classmethod
4445
def from_file(cls, path):
4546
with open(path, "r") as stream:
4647
try:
47-
raw_steps = yaml.safe_load(stream)
48-
raw_steps = dict(raw_steps)["steps"]
48+
raw_config = yaml.safe_load(stream)
49+
config = dict(raw_config)
50+
raw_steps = config["steps"]
51+
metadata = config["metadata"]
4952
except yaml.YAMLError as exc:
5053
print(exc)
5154

5255
steps = [Step(**raw_step) for raw_step in raw_steps]
53-
return cls(steps)
56+
return cls(steps, metadata)

openandroidinstaller/openandroidinstaller.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@
5353

5454
# Toggle to True for development purposes
5555
DEVELOPMENT = False
56-
DEVELOPMENT_CONFIG = "Xperia Z" # "Pixel 3a"
56+
DEVELOPMENT_CONFIG = "a3y17lte" # "sargo"
5757

5858

5959
PLATFORM = sys.platform
6060
logger.info(f"Running OpenAndroidInstaller on {PLATFORM}")
6161
# Define asset paths
6262
CONFIG_PATH = Path(__file__).parent.joinpath(Path("assets/configs")).resolve()
6363
IMAGE_PATH = Path(__file__).parent.joinpath(Path("assets/imgs")).resolve()
64+
BIN_PATH = Path(__file__).parent.joinpath(Path("bin")).resolve()
6465

6566

6667
class BaseView(UserControl):
@@ -177,60 +178,58 @@ def close_developer_options_dlg(self, e):
177178
self.page.update()
178179

179180
def search_devices(self, e):
181+
"""Search the device when the button is clicked."""
182+
logger.info("Search devices...")
180183
try:
181184
# read device properties
182185
# TODO: This is not windows ready...
183-
if PLATFORM in ("linux", "MacOS"):
186+
if PLATFORM in ("linux", "darwin"):
184187
output = check_output(
185188
[
186-
"adb",
189+
str(BIN_PATH.joinpath(Path("adb"))),
187190
"shell",
188-
"dumpsys",
189-
"bluetooth_manager",
191+
"getprop",
190192
"|",
191193
"grep",
192-
"'name:'",
193-
"|",
194-
"cut",
195-
"-c9-",
194+
"ro.product.device"
196195
],
197196
stderr=STDOUT,
198197
).decode()
199198
elif PLATFORM == "windows":
200199
output = check_output(
201200
[
202-
"adb",
201+
str(BIN_PATH.joinpath(Path("adb"))),
203202
"shell",
204-
"dumpsys",
205-
"bluetooth_manager",
203+
"getprop",
206204
"|",
207205
"findstr",
208-
"'name:'",
209-
"|",
210-
"-split",
211-
"-c9-",
206+
"ro.product.device"
212207
],
213208
stderr=STDOUT,
214209
).decode()
215210
else:
216211
raise Exception(f"Unknown platform {PLATFORM}.")
217212

213+
output = output.split("[")[-1][:-2]
214+
logger.info(f"Detected {output}")
215+
# write the device code to the text shown in the box
218216
self.device_name.value = output.strip()
219217
# load config from file
220-
# path = f"{CONFIG_PATH}/{output.strip()}.yaml"
221218
path = CONFIG_PATH.joinpath(Path(f"{output.strip()}.yaml"))
222219
load_config_success = self.load_config(path)
220+
# display success in the application
223221
if load_config_success:
224222
self.config_found_box.value = True
225223
self.continue_button.disabled = False
224+
# overwrite the text field with the real name from the config
225+
self.device_name.value = f"{load_config_success} (code: {output.strip()})"
226226
else:
227227
# show alternative configs here
228228
# select a new path and load again
229229
pass
230230
except CalledProcessError:
231231
if DEVELOPMENT:
232232
path = CONFIG_PATH.joinpath(Path(f"{DEVELOPMENT_CONFIG}.yaml"))
233-
# path = f"{CONFIG_PATH}/{DEVELOPMENT_CONFIG}.yaml"
234233
load_config_success = self.load_config(path)
235234
if load_config_success:
236235
self.config_found_box.value = True
@@ -428,7 +427,7 @@ def load_config(self, path: str):
428427
try:
429428
self.config = InstallerConfig.from_file(path)
430429
self.num_total_steps = len(self.config.steps)
431-
return True
430+
return self.config.metadata.get("devicename", "No device name in config.")
432431
except FileNotFoundError:
433432
return False
434433

@@ -501,6 +500,11 @@ def build(self):
501500
return self.view
502501

503502
def call_to_phone(self, e, command: str):
503+
# TODO: use proper windows paths
504+
command = command.replace("adb", str(BIN_PATH.joinpath(Path("adb"))))
505+
command = command.replace("fastboot", str(BIN_PATH.joinpath(Path("fastboot"))))
506+
command = command.replace("heimdall", str(BIN_PATH.joinpath(Path("heimdall"))))
507+
504508
command = command.replace("<recovery>", self.recovery_path)
505509
command = command.replace("<image>", self.image_path)
506510
command = command.replace("<inputtext>", self.inputtext.value)

openandroidinstaller/widgets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
# Author: Tobias Sterbak
1515

1616
from functools import partial
17-
from os import path
1817
from typing import Callable
1918

20-
from flet import Column, Container, ElevatedButton, Image, Row, Text, alignment, icons
19+
from flet import Column, Container, ElevatedButton, Row, Text, alignment, icons
2120

2221

2322
def get_title(title: str):

0 commit comments

Comments
 (0)