diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 2f5d5e6..0b01148 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import argparse from logging import Logger from stuffs.android_id import Android_id diff --git a/stuffs/general.py b/stuffs/general.py index 72d8bbe..5de2895 100644 --- a/stuffs/general.py +++ b/stuffs/general.py @@ -4,8 +4,8 @@ import re import zipfile import hashlib from tools import images -from tools.helper import download_file, get_download_dir, run, upgrade -from tools.container import DBusContainerService +from tools.helper import download_file, get_download_dir +from tools import container from tools.logger import Logger class General: @@ -19,27 +19,11 @@ class General: @property def copy_dir(self): - if self.use_overlayfs: + if container.use_overlayfs(): return "/var/lib/waydroid/overlay" else: return "/tmp/waydroid" - @property - def use_dbus(self): - try: - DBusContainerService() - except: - return False - return True - - @property - def use_overlayfs(self): - with open("/var/lib/waydroid/waydroid.cfg") as f: - cont=f.read() - if re.search("mount_overlays[ \t]*=[ \t]*True", cont): - return True - return False - def download(self): Logger.info("Downloading {} now to {} .....".format(self.dl_file_name, self.download_loc)) loc_md5 = "" @@ -96,41 +80,46 @@ class General: images.umount(mount_point) def stop(self): - if self.use_dbus: - self.session = DBusContainerService().GetSession() - if self.session: - DBusContainerService().Stop(False) - else: - run(["waydroid", "container", "stop"]) + if container.use_dbus(): + self.session = container.get_session() + container.stop() def start(self): - if self.use_dbus and self.session: - DBusContainerService().Start(self.session) + if container.use_dbus() and self.session: + container.start(self.session) else: - run(["systemctl", "restart", "waydroid-container.service"]) - upgrade() + container.start() def restart(self): self.stop() self.start() - upgrade() def copy(self): pass - def extra(self): + def extra1(self): + pass + + def extra2(self): pass + # def install(self): + # if DBusContainerService().GetSession(): + # print("running") + # else: + # print("stopped") + # run("waydroid session start".split()) def install(self): - if self.use_overlayfs: + if container.use_overlayfs(): self.download() if not self.skip_extract: self.extract() self.copy() - self.extra() + self.extra1() if hasattr(self, "apply_props"): self.add_props() self.restart() + self.extra2() else: self.stop() self.download() @@ -139,9 +128,10 @@ class General: self.resize() self.mount() self.copy() - self.extra() + self.extra1() if hasattr(self, "apply_props"): self.add_props() self.umount() self.start() + self.extra2() Logger.info("Installation finished") diff --git a/stuffs/smartdock.py b/stuffs/smartdock.py index 4b21e15..de9b2f9 100644 --- a/stuffs/smartdock.py +++ b/stuffs/smartdock.py @@ -1,6 +1,9 @@ import os import shutil +from time import sleep from stuffs.general import General +from tools import container +from tools.helper import run class Smartdock(General): dl_link = "https://github.com/ayasa520/smartdock/releases/download/v1.9.6/smartdock.zip" @@ -8,14 +11,25 @@ class Smartdock(General): extract_to = "/tmp/smartdockunpack" dl_file_name = "smartdock.zip" act_md5 = "ad0cc5e023ac6ee97e7b013b9b0defee" + apply_props = { "qemu.hw.mainkeys" : "1" } def copy(self): if not os.path.exists(os.path.join(self.copy_dir, self.partition, "priv-app", "SmartDock")): os.makedirs(os.path.join(self.copy_dir, self.partition, "priv-app", "SmartDock")) + if not os.path.exists(os.path.join(self.copy_dir, self.partition, "etc", "permissions")): + os.makedirs(os.path.join(self.copy_dir, self.partition, "etc", "permissions")) shutil.copyfile(os.path.join(self.extract_to, "app-release.apk"), os.path.join(self.copy_dir, self.partition, "priv-app", "SmartDock", "smartdock.apk")) shutil.copyfile(os.path.join(self.extract_to, "permissions_cu.axel.smartdock.xml"), os.path.join(self.copy_dir, self.partition, "etc", "permissions", "permissions_cu.axel.smartdock.xml")) - def extra(self): - return super().extra() + def extra2(self): + index = 0 + while not container.is_running(): + list = ["\\", "|", "/", "—"] + sleep(0.5) + print("\r\tPlease start WayDroid for further setup {}".format(list[index%4]), end="") + index += 1 + sleep(5) + print() + run(["waydroid", "shell", "cmd", "package", "set-home-activity", "cu.axel.smartdock/.activities.LauncherActivity"]) diff --git a/tools/container.py b/tools/container.py index ee65673..d5fcd4c 100644 --- a/tools/container.py +++ b/tools/container.py @@ -1,10 +1,52 @@ -try: - import dbus -except ModuleNotFoundError: - pass +import re +import dbus +from tools.helper import run def DBusContainerService(object_path="/ContainerManager", intf="id.waydro.ContainerManager"): return dbus.Interface(dbus.SystemBus().get_object("id.waydro.Container", object_path), intf) def DBusSessionService(object_path="/SessionManager", intf="id.waydro.SessionManager"): return dbus.Interface(dbus.SessionBus().get_object("id.waydro.Session", object_path), intf) + +def use_dbus(): + try: + DBusContainerService() + except: + return False + return True + +def use_overlayfs(): + # with open("/var/lib/waydroid/waydroid.cfg") as f: + # cont=f.read() + # if re.search("mount_overlays[ \t]*=[ \t]*True", cont): + # return True + # return False + return False + +def get_session(): + return DBusContainerService().GetSession() + +def stop(): + if use_dbus(): + session = DBusContainerService().GetSession() + if session: + DBusContainerService().Stop(False) + else: + run(["waydroid", "container", "stop"]) + +def start(*session): + if use_dbus() and session: + DBusContainerService().Start(session[0]) + else: + run(["systemctl", "restart", "waydroid-container.service"]) + +def is_running(): + if use_dbus(): + if DBusContainerService().GetSession(): + return True + return False + else: + return "Session:\tRUNNING" in run(["waydroid", "status"]).stdout.decode() + + +