Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ayasa520 committed May 27, 2023
1 parent 6922bdb commit 48ea54f
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 307 deletions.
353 changes: 205 additions & 148 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

import argparse
from logging import Logger
import os
from typing import List
from stuffs.android_id import AndroidId
from stuffs.gapps import Gapps
from stuffs.general import General
from stuffs.hidestatusbar import HideStatusBar
from stuffs.houdini import Houdini
from stuffs.magisk import Magisk
Expand All @@ -13,159 +15,203 @@
from stuffs.smartdock import Smartdock
from stuffs.widevine import Widevine
import tools.helper as helper

from tools import container
from tools import images

import argparse

# def main():
# def get_certified():
# print("Calling android_get_certified function")

# def install_app(app_name):
# print(f"Installing {app_name}")

# def remove_app(app_name):
# print(f"Removing {app_name}")

# def hack_option(option_name):
# print(f"Enabling {option_name}")

# parser = argparse.ArgumentParser(description='''
# Does stuff like installing Gapps, installing Magisk, installing NDK Translation and getting Android ID for device registration.
# Use -h flag for help!''')

# subparsers = parser.add_subparsers(dest='command')

# # android command
# certified = subparsers.add_parser('certified', help='Get device ID to obtain Play Store certification')
# certified.set_defaults(func=get_certified)

# install_choices=["gapps", "microg", "libndk", "libhoudini", "magisk", "smartdock", "widevine"],
# hack_choices = ["nodataperm", "hidestatusbar"]
# remove_choices=install_choices

# arg_template = {
# "dest": "app",
# "type": str,
# "nargs": '+',
# "metavar":"",
# }

# install_help = """
# gapps: Install Open GApps (Android 11) or MindTheGapps (Android 13)
# microg: Add microG, Aurora Store and Aurora Droid to WayDriod
# libndk: Add libndk arm translation, better for AMD CPUs
# libhoudini: Add libhoudini arm translation, better for Intel CPUs
# magisk: Install Magisk Delta to WayDroid
# smartdock: A desktop mode launcher for Android
# widevine: Add support for widevine DRM L3
# """
# # install and its aliases
# install_parser = subparsers.add_parser('install', aliases=['-i'], formatter_class=argparse.RawTextHelpFormatter, help='Install an app')
# install_parser.add_argument(**arg_template, help=install_help)
# install_parser.set_defaults(func=install_app)

# # remove and its aliases
# remove_parser = subparsers.add_parser('remove', aliases=['-r'], help='Remove an app')
# remove_parser.add_argument(**arg_template, help='Name of app to remove')
# remove_parser.set_defaults(func=remove_app)

# # hack and its aliases
# hack_parser = subparsers.add_parser('hack', aliases=['-h'], help='Hack the system')
# hack_parser.add_argument('option_name', choices=["nodataperm", "hidestatus"], help='Name of hack option')
# hack_parser.set_defaults(func=hack_option)

# args = parser.parse_args()
# if hasattr(args, 'func'):
# args_dict = vars(args)
# if 'app_name' in args_dict:
# args.func(args_dict['app_name'])
# else:
# args.func(args_dict['option_name'])
# else:
# parser.print_help()





def install(args):
app = args.app
if "gapps" in app:
Gapps(args.android_version).install()
if "libndk" in app and "houdini" not in app:
arch = helper.host()[0]
if arch == "x86_64":
Ndk(args.android_version).install()
else:
Logger.warn("libndk is not supported on your CPU")
if "libhoudini" in app and "ndk" not in app:
arch = helper.host()[0]
if arch == "x86_64":
Houdini(args.android_version).install()
else:
Logger.warn("libhoudini is not supported on your CPU")
if "magisk" in app:
Magisk().install()
if "widevine" in app:
Widevine(args.android_version).install()
if "smartdock" in app:
Smartdock().install()
if "nodataperm" in app:
Nodataperm().install()
if "microg" in app:
MicroG().install()
if "hidestatus" in app:
HideStatusBar().install()

def uninstall(args):
app = args.app
if "gapps" in app:
Gapps(args.android_version).uninstall()
if "libndk" in app:
Ndk(args.android_version).uninstall()
if "libhoudini" in app:
Houdini(args.android_version).uninstall()
if "magisk" in app:
Magisk().uninstall()
if "widevine" in app:
Widevine(args.android_version).uninstall()
if "smartdock" in app:
Smartdock().uninstall()
if "nodataperm" in app:
Nodataperm().uninstall()
if "microg" in app:
MicroG().uninstall()
if "hidestatus" in app:
HideStatusBar().uninstall()
from tools.logger import Logger


def get_certified():
AndroidId.get_id()


def mount(partition, copy_dir):
img = os.path.join(images.get_image_dir(), partition+".img")
mount_point = ""
if partition == "system":
mount_point = os.path.join(copy_dir)
else:
mount_point = os.path.join(copy_dir, partition)
Logger.info("Mounting {} to {}".format(img, mount_point))
images.mount(img, mount_point)


def resize(partition):
img = os.path.join(images.get_image_dir(), partition+".img")
img_size = int(os.path.getsize(img)/(1024*1024))
new_size = "{}M".format(img_size+500)
Logger.info("Resizing {} to {}".format(img, new_size))
images.resize(img, new_size)


def umount(partition, copy_dir):
mount_point = ""
if partition == "system":
mount_point = os.path.join(copy_dir)
else:
mount_point = os.path.join(copy_dir, partition)
Logger.info("Umounting {}".format(mount_point))
images.umount(mount_point)


def main():
about = """
WayDroid Helper script v0.3

def install_app(args):
install_list: List[General] = []
app = args.app
if "gapps" in app:
install_list.append(Gapps(args.android_version))
if "libndk" in app and "houdini" not in app:
arch = helper.host()[0]
if arch == "x86_64":
install_list.append(Ndk(args.android_version))
else:
Logger.warn("libndk is not supported on your CPU")
if "libhoudini" in app and "ndk" not in app:
arch = helper.host()[0]
if arch == "x86_64":
install_list.append(Houdini(args.android_version))
else:
Logger.warn("libhoudini is not supported on your CPU")
if "magisk" in app:
install_list.append(Magisk())
if "widevine" in app:
install_list.append(Widevine(args.android_version))
if "smartdock" in app:
install_list.append(Smartdock())
if "microg" in app:
install_list.append(MicroG(args.android_version))

if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()

resize_system, resize_vendor = False, False
for item in install_list:
if item.partition == "system":
resize_system = True
elif item.partition == "vendor":
resize_vendor = True

if resize_system:
resize("system")
if resize_vendor:
resize("vendor")

mount("system", copy_dir)
mount("vendor", copy_dir)

for item in install_list:
item.install()

if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)

container.upgrade()

def remove_app(args):
remove_list: List[General] = []
app = args.app
if "gapps" in app:
remove_list.append(Gapps(args.android_version))
if "libndk" in app and "houdini" not in app:
remove_list.append(Ndk(args.android_version))
if "libhoudini" in app and "ndk" not in app:
remove_list.append(Houdini(args.android_version))
if "magisk" in app:
remove_list.append(Magisk())
if "widevine" in app:
remove_list.append(Widevine(args.android_version))
if "smartdock" in app:
remove_list.append(Smartdock())
if "microg" in app:
remove_list.append(MicroG(args.android_version))
if "nodataperm" in app:
remove_list.append(Nodataperm(args.android_version))
if "hidestatusbar" in app:
remove_list.append(HideStatusBar())

if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()

for item in remove_list:
item.uninstall()

if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)

container.upgrade()

def hack_option(args):
Logger.warning("If these hacks cause any problems, run `sudo python main.py remove <hack_option>` to remove")

hack_list: List[General] = []
options = args.option_name
if "nodataperm" in options:
hack_list.append(Nodataperm())
if "hidestatusbar" in options:
hack_list.append(HideStatusBar())

if not container.use_overlayfs():
copy_dir = "/tmp/waydroid"
container.stop()

resize_system, resize_vendor = False, False
for item in hack_list:
if item.partition == "system":
resize_system = True
elif item.partition == "vendor":
resize_vendor = True

if resize_system:
resize("system")
if resize_vendor:
resize("vendor")

mount("system", copy_dir)
mount("vendor", copy_dir)

for item in hack_list:
item.install()

if not container.use_overlayfs():
umount("vendor", copy_dir)
umount("system", copy_dir)

container.upgrade()

parser = argparse.ArgumentParser(description='''
Does stuff like installing Gapps, installing Magisk, installing NDK Translation and getting Android ID for device registration.
Use -h flag for help!
"""
helper.check_root()
Use -h flag for help!''')

parser = argparse.ArgumentParser(prog=about)
parser.set_defaults(app="")
subparsers = parser.add_subparsers(title="coomand", dest='command')
parser.add_argument('-a', '--android-version',
dest='android_version',
help='Specify the Android version',
default="11",
choices=["11","13"])
subparsers = parser.add_subparsers(title="subcommands", help="operations")
choices=["11", "13"])

# android command
certified = subparsers.add_parser(
'certified', help='Get device ID to obtain Play Store certification')
certified.set_defaults(func=get_certified)

google_id_parser=subparsers.add_parser('google',
help='grab device id for unblocking Google Apps')
google_id_parser.set_defaults(func=AndroidId().get_id)
# create the parser for the "a" command
install_choices = ["gapps", "microg", "libndk",
"libhoudini", "magisk", "smartdock", "widevine"]
hack_choices = ["nodataperm", "hidestatusbar"]
micrg_variants = ["Standard", "NoGoolag", "UNLP", "Minimal", "MinimalIAP"]
remove_choices = install_choices

arg_template = {
"dest": "app",
"type": str,
"nargs": '+',
"metavar":"",
# "metavar":"",
}

install_help = """
Expand All @@ -177,22 +223,33 @@ def main():
smartdock: A desktop mode launcher for Android
widevine: Add support for widevine DRM L3
"""

install_parser = subparsers.add_parser("install",formatter_class=argparse.RawTextHelpFormatter, help='install something')
install_parser.set_defaults(func=install)
install_parser.add_argument(**arg_template,help=install_help)

uninstall_parser = subparsers.add_parser("uninstall", help='uninstall something')
uninstall_parser.set_defaults(func=uninstall)
uninstall_parser.add_argument(**arg_template)
# install and its aliases
install_parser = subparsers.add_parser(
'install', formatter_class=argparse.RawTextHelpFormatter, help='Install an app')
install_parser.add_argument(
**arg_template, choices=install_choices, help=install_help)
install_parser.set_defaults(func=install_app)

# remove and its aliases
remove_parser = subparsers.add_parser('remove',aliases=["uninstall"], help='Remove an app')
remove_parser.add_argument(
**arg_template, choices=[*remove_choices,* hack_choices], help='Name of app to remove')
remove_parser.set_defaults(func=remove_app)

# hack and its aliases
hack_parser = subparsers.add_parser('hack', help='Hack the system')
hack_parser.add_argument(
'option_name',nargs="+" , choices=hack_choices, help='Name of hack option')
hack_parser.set_defaults(func=hack_option)

args = parser.parse_args()
if args.app:
if hasattr(args, 'func'):
args_dict = vars(args)
helper.check_root()
args.func(args)
else:
args.func()
parser.print_help()



if __name__ == "__main__":
main()
Loading

0 comments on commit 48ea54f

Please sign in to comment.