microg: use MinMicroG
parent
00714a5c0e
commit
6922bdba0d
@ -1,4 +1,4 @@
|
|||||||
tqdm
|
tqdm
|
||||||
requests
|
requests
|
||||||
aapt2
|
InquirerPy
|
||||||
dbus-python==1.2.18
|
dbus-python==1.2.18
|
||||||
|
@ -1,105 +1,178 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from time import sleep
|
import zipfile
|
||||||
from stuffs.general import General
|
from stuffs.general import General
|
||||||
from tools.helper import get_download_dir, host, run
|
from tools.helper import host
|
||||||
from aapt2 import aapt
|
|
||||||
from tools import container
|
|
||||||
from tools.logger import Logger
|
from tools.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
class MicroG(General):
|
class MicroG(General):
|
||||||
partition = "system"
|
partition = "system"
|
||||||
main_arch = host()[0]
|
dl_links = {
|
||||||
sub_arch = "x86" if main_arch == "x86_64" else "armeabi-v7a" if main_arch == "arm64-v8a" else ""
|
"Standard": [
|
||||||
fdroid = "https://f-droid.org/repo/"
|
"https://github.com/ayasa520/MinMicroG/releases/download/latest/MinMicroG-Standard-2.11.1-20230429100529.zip",
|
||||||
microg="https://microg.org/fdroid/repo/"
|
"0fe332a9caa3fbb294f2e2b50f720c6b"
|
||||||
fdroid_repo_apks = {
|
],
|
||||||
"com.aurora.store_41.apk": "9e6c79aefde3f0bbfedf671a2d73d1be",
|
"NoGoolag": [
|
||||||
"com.etesync.syncadapter_20300.apk": "997d6de7d41c454d39fc22cd7d8fc3c2",
|
"https://github.com/ayasa520/MinMicroG/releases/download/latest/MinMicroG-NoGoolag-2.11.1-20230429100545.zip",
|
||||||
"com.aurora.adroid_8.apk": "0010bf93f02c2d18daf9e767035fefc5",
|
"ff920f33f4c874eeae4c0444be427c68"
|
||||||
"org.fdroid.fdroid.privileged_2130.apk": "b04353155aceb36207a206d6dd14ba6a",
|
],
|
||||||
"org.microg.nlp.backend.ichnaea_20036.apk": "0b3cb65f8458d1a5802737c7392df903",
|
"UNLP": [
|
||||||
"org.microg.nlp.backend.nominatim_20042.apk": "88e7397cbb9e5c71c8687d3681a23383",
|
"https://github.com/ayasa520/MinMicroG/releases/download/latest/MinMicroG-UNLP-2.11.1-20230429100555.zip",
|
||||||
|
"6136b383153c2a6797d14fb4d7ca3f97"
|
||||||
|
],
|
||||||
|
"Minimal": [
|
||||||
|
"https://github.com/ayasa520/MinMicroG/releases/download/latest/MinMicroG-Minimal-2.11.1-20230429100521.zip"
|
||||||
|
"afb87eb64e7749cfd72c4760d85849da"
|
||||||
|
],
|
||||||
|
"MinimalIAP": [
|
||||||
|
"https://github.com/ayasa520/MinMicroG/releases/download/latest/MinMicroG-MinimalIAP-2.11.1-20230429100556.zip"
|
||||||
|
"cc071f4f776cbc16c4c1f707aff1f7fa"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
microg_apks= {
|
dl_link = ...
|
||||||
"com.google.android.gms-223616054.apk": "a945481ca5d33a03bc0f9418263c3228",
|
act_md5 = ...
|
||||||
"com.google.android.gsf-8.apk": "b2b4ea3642df6158e14689a4b2a246d4",
|
dl_file_name = ...
|
||||||
"com.android.vending-22.apk": "6815d191433ffcd8fa65923d5b0b0573",
|
sdk = ...
|
||||||
"org.microg.gms.droidguard-14.apk": "4734b41c1a6bc34a541053ddde7a0f8e"
|
extract_to = "/tmp/microg/extract"
|
||||||
}
|
copy_dir = "/var/lib/waydroid/overlay_rw/system"
|
||||||
priv_apps = ["com.google.android.gms", "com.android.vending"]
|
arch = host()
|
||||||
|
rc_content = '''
|
||||||
|
on property:sys.boot_completed=1
|
||||||
|
start microg_service
|
||||||
|
|
||||||
|
service microg_service /system/bin/sh /system/bin/npem
|
||||||
|
user root
|
||||||
|
group root
|
||||||
|
oneshot
|
||||||
|
'''
|
||||||
|
files = [
|
||||||
|
"priv-app/GoogleBackupTransport",
|
||||||
|
"priv-app/MicroGUNLP",
|
||||||
|
"priv-app/MicroGGMSCore",
|
||||||
|
"priv-app/MicroGGMSCore/lib/x86_64/libmapbox-gl.so",
|
||||||
|
"priv-app/MicroGGMSCore/lib/x86_64/libconscrypt_gmscore_jni.so",
|
||||||
|
"priv-app/MicroGGMSCore/lib/x86_64/libcronet.102.0.5005.125.so",
|
||||||
|
"priv-app/PatchPhonesky",
|
||||||
|
"priv-app/PatchPhonesky/lib/x86_64/libempty_x86_64.so",
|
||||||
|
"priv-app/AuroraServices",
|
||||||
|
"bin/npem",
|
||||||
|
"app/GoogleCalendarSyncAdapter",
|
||||||
|
"app/NominatimNLPBackend",
|
||||||
|
"app/MicroGGSFProxy",
|
||||||
|
"app/LocalGSMNLPBackend",
|
||||||
|
"app/DejaVuNLPBackend",
|
||||||
|
"app/MozillaUnifiedNLPBackend",
|
||||||
|
"app/AppleNLPBackend",
|
||||||
|
"app/AuroraDroid",
|
||||||
|
"app/LocalWiFiNLPBackend",
|
||||||
|
"app/GoogleContactsSyncAdapter",
|
||||||
|
"app/MicroGGSFProxy/MicroGGSFProxy",
|
||||||
|
"framework/com.google.widevine.software.drm.jar",
|
||||||
|
"framework/com.google.android.media.effects.jar",
|
||||||
|
"framework/com.google.android.maps.jar",
|
||||||
|
"lib64/libjni_keyboarddecoder.so",
|
||||||
|
"lib64/libjni_latinimegoogle.so",
|
||||||
|
"etc/default-permissions/microg-permissions.xml",
|
||||||
|
"etc/default-permissions/microg-permissions-unlp.xml",
|
||||||
|
"etc/default-permissions/gsync.xml",
|
||||||
|
"etc/sysconfig/nogoolag.xml",
|
||||||
|
"etc/sysconfig/nogoolag-unlp.xml",
|
||||||
|
"etc/init/microg.rc",
|
||||||
|
"etc/permissions/com.google.android.backuptransport.xml",
|
||||||
|
"etc/permissions/com.android.vending.xml",
|
||||||
|
"etc/permissions/com.google.android.gms.xml",
|
||||||
|
"etc/permissions/com.aurora.services.xml",
|
||||||
|
"etc/permissions/com.google.android.maps.xml",
|
||||||
|
"etc/permissions/com.google.widevine.software.drm.xml",
|
||||||
|
"etc/permissions/com.google.android.media.effects.xml",
|
||||||
|
"lib/libjni_keyboarddecoder.so",
|
||||||
|
"lib/libjni_latinimegoogle.so",
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, android_version="11", variant="Standard") -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.dl_link = self.dl_links[variant][0]
|
||||||
|
self.act_md5 = self.dl_links[variant][1]
|
||||||
|
self.dl_file_name = f'MinMicroG-{variant}.zip'
|
||||||
|
if android_version == "11":
|
||||||
|
self.sdk = 30
|
||||||
|
elif android_version == "13":
|
||||||
|
self.sdk = 33
|
||||||
|
|
||||||
|
def set_permissions(self, path):
|
||||||
|
if "bin" in path.split("/"):
|
||||||
|
perms = [0, 2000, 0o755, 0o777]
|
||||||
|
else:
|
||||||
|
perms = [0, 0, 0o755, 0o644]
|
||||||
|
|
||||||
def skip_extract(self):
|
mode = os.stat(path).st_mode
|
||||||
return True
|
|
||||||
|
|
||||||
def download(self):
|
if os.path.isdir(path):
|
||||||
for apk, md5 in self.fdroid_repo_apks.items():
|
mode |= perms[2]
|
||||||
self.dl_link = self.fdroid+apk
|
else:
|
||||||
self.act_md5 = md5
|
mode |= perms[3]
|
||||||
self.dl_file_name = apk
|
|
||||||
super().download()
|
os.chown(path, perms[0], perms[1])
|
||||||
for apk, md5 in self.microg_apks.items():
|
|
||||||
self.dl_link = self.microg+apk
|
|
||||||
self.act_md5 = md5
|
|
||||||
self.dl_file_name = apk
|
|
||||||
super().download()
|
|
||||||
|
|
||||||
def generate_permissions(self):
|
os.chmod(path, mode)
|
||||||
permissions = "<permissions>"
|
|
||||||
download_dir = get_download_dir()
|
|
||||||
for apk in {**self.fdroid_repo_apks, **self.microg_apks}.keys():
|
|
||||||
splitor = "_" if apk in self.fdroid_repo_apks.keys() else "-"
|
|
||||||
package = apk.split(splitor)[0]
|
|
||||||
permissions += '\n\t<privapp-permissions package="{}">\n'.format(package)
|
|
||||||
permission_list = aapt.get_apk_info(os.path.join(download_dir,apk))["permissions"]
|
|
||||||
permissions += "\n".join(['\t\t<permission name="{}"/>'.format(permission) for permission in permission_list])
|
|
||||||
permissions += "\n\t</privapp-permissions>"
|
|
||||||
permissions += "</permissions>"
|
|
||||||
return permissions
|
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
Logger.info("Copying MicroG and other files")
|
|
||||||
for apk in {**self.fdroid_repo_apks, **self.microg_apks}.keys():
|
|
||||||
splitor = "_" if apk in self.fdroid_repo_apks.keys() else "-"
|
|
||||||
package = apk.split(splitor)[0]
|
|
||||||
download_dir = get_download_dir()
|
|
||||||
apk_dir = "app" if package not in self.priv_apps else "priv-app"
|
|
||||||
if not os.path.exists(os.path.join(self.copy_dir, self.partition, apk_dir, package)):
|
|
||||||
os.makedirs(os.path.join(self.copy_dir, self.partition, apk_dir, package))
|
|
||||||
shutil.copyfile(os.path.join(download_dir, apk),
|
|
||||||
os.path.join(self.copy_dir, self.partition, apk_dir, package, apk))
|
|
||||||
permissions = self.generate_permissions()
|
|
||||||
permission_dir = os.path.join(self.copy_dir, self.partition, "etc", "permissions")
|
|
||||||
if not os.path.exists(permission_dir):
|
|
||||||
os.makedirs(permission_dir)
|
|
||||||
with open(os.path.join(permission_dir, "foss-permissions.xml"), "w") as f:
|
|
||||||
f.write(permissions)
|
|
||||||
|
|
||||||
def extra2(self):
|
Logger.info("Copying libs and apks...")
|
||||||
index = 0
|
dst_dir = os.path.join(self.copy_dir, self.partition)
|
||||||
while not container.is_running():
|
src_dir = os.path.join(self.extract_to, "system")
|
||||||
list = ["\\", "|", "/", "—"]
|
if "arm" in self.arch[0]:
|
||||||
sleep(0.5)
|
sub_arch = "arm"
|
||||||
print("\r\tPlease start WayDroid for further setup {}".format(list[index%4]), end="")
|
else:
|
||||||
index += 1
|
sub_arch = "x86"
|
||||||
sleep(5)
|
if 64 == self.arch[1]:
|
||||||
if index != 0:
|
arch = f"{sub_arch}{'' if sub_arch=='arm' else '_'}64"
|
||||||
print()
|
for root, dirs, files in os.walk(src_dir):
|
||||||
Logger.info("Signature spoofing")
|
flag = False
|
||||||
run("waydroid shell pm grant com.google.android.gms android.permission.FAKE_PACKAGE_SIGNATURE".split())
|
dir_name = os.path.basename(root)
|
||||||
run("waydroid shell pm grant com.android.vending android.permission.FAKE_PACKAGE_SIGNATURE".split())
|
# 遍历文件
|
||||||
|
if dir_name.startswith('-') and dir_name.endswith('-'):
|
||||||
|
archs, sdks = [], []
|
||||||
|
for i in dir_name.split("-"):
|
||||||
|
if i.isdigit():
|
||||||
|
sdks.append(i)
|
||||||
|
elif i:
|
||||||
|
archs.append(i)
|
||||||
|
if len(archs) != 0 and arch not in archs and sub_arch not in archs or len(sdks) != 0 and str(self.sdk) not in sdks:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
flag = True
|
||||||
|
|
||||||
def remove(self):
|
for file in files:
|
||||||
system_dir = os.path.join(self.copy_dir, self.partition)
|
src_file_path = os.path.join(root, file)
|
||||||
files = [key.split("_")[0] for key in self.fdroid_repo_apks.keys()]
|
self.set_permissions(src_file_path)
|
||||||
files += [key.split("-")[0] for key in self.microg_apks.keys()]
|
if not flag:
|
||||||
for f in files:
|
dst_file_path = os.path.join(dst_dir, os.path.relpath(
|
||||||
if f in self.priv_apps:
|
src_file_path, src_dir))
|
||||||
file = os.path.join(system_dir, "priv-app", f)
|
|
||||||
else:
|
else:
|
||||||
file = os.path.join(system_dir, "app", f)
|
dst_file_path = os.path.join(dst_dir, os.path.relpath(
|
||||||
if os.path.isdir(file):
|
os.path.join(os.path.dirname(root), file), src_dir))
|
||||||
shutil.rmtree(file)
|
if not os.path.exists(os.path.dirname(dst_file_path)):
|
||||||
elif os.path.isfile(file):
|
os.makedirs(os.path.dirname(dst_file_path))
|
||||||
os.remove(file)
|
# Logger.info(f"{src_file_path} -> {dst_file_path}")
|
||||||
|
shutil.copy2(src_file_path, dst_file_path)
|
||||||
|
if os.path.splitext(dst_file_path)[1].lower() == ".apk":
|
||||||
|
lib_dest_dir = os.path.dirname(dst_file_path)
|
||||||
|
with zipfile.ZipFile(dst_file_path, "r") as apk:
|
||||||
|
for file_info in apk.infolist():
|
||||||
|
file_name = file_info.filename
|
||||||
|
file_path = os.path.join(lib_dest_dir, file_name)
|
||||||
|
if file_info.filename.startswith(f"lib/{self.arch[0]}/") and file_name.endswith(".so"):
|
||||||
|
os.makedirs(os.path.dirname(
|
||||||
|
file_path), exist_ok=True)
|
||||||
|
with apk.open(file_info.filename) as src_file, open(file_path, "wb") as dest_file:
|
||||||
|
# Logger.info(f"{src_file} -> {dest_file}")
|
||||||
|
shutil.copyfileobj(src_file, dest_file)
|
||||||
|
|
||||||
|
rc_dir = os.path.join(dst_dir, "etc/init/microg.rc")
|
||||||
|
if not os.path.exists(os.path.dirname(rc_dir)):
|
||||||
|
os.makedirs(os.path.dirname(rc_dir))
|
||||||
|
with open(rc_dir, "w") as f:
|
||||||
|
f.write(self.rc_content)
|
||||||
|
self.set_permissions(rc_dir)
|
||||||
|
Loading…
Reference in New Issue