]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/services/user_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
7 import tools
.helpers
.net
8 from tools
.interfaces
import IUserMonitor
9 from tools
.interfaces
import IPlatform
13 def start(args
, session
, unlocked_cb
=None):
14 waydroid_data
= session
["waydroid_data"]
15 apps_dir
= session
["xdg_data_home"] + "/applications/"
17 def makeDesktopFile(appInfo
):
22 for cat
in appInfo
["categories"]:
23 if cat
.strip() == "android.intent.category.LAUNCHER":
28 packageName
= appInfo
["packageName"]
30 desktop_file_path
= apps_dir
+ "/waydroid." + packageName
+ ".desktop"
31 if not os
.path
.exists(desktop_file_path
):
32 with open(desktop_file_path
, "w") as desktop_file
:
33 desktop_file
.write(f
"""\
36 Name={appInfo["name"]}
37 Exec=waydroid app launch {packageName}
38 Icon={waydroid_data}/icons/{packageName}.png
39 Categories=X-WayDroid-App;
40 X-Purism-FormFactor=Workstation;Mobile;
43 [Desktop Action app_settings]
45 Exec=waydroid app intent android.settings.APPLICATION_DETAILS_SETTINGS package:{packageName}
46 Icon={waydroid_data}/icons/com.android.settings.png
50 def makeWaydroidDesktopFile(hide
):
51 desktop_file_path
= apps_dir
+ "/Waydroid.desktop"
52 # If the user has set the desktop file as read-only, we won't replace it
53 if os
.path
.isfile(desktop_file_path
) and not os
.access(desktop_file_path
, os
.W_OK
):
54 logging
.info(f
"Desktop file '{desktop_file_path}' is not writeable, not updating it")
56 if os
.path
.isfile(desktop_file_path
):
57 os
.remove(desktop_file_path
)
58 with open(desktop_file_path
, "w") as desktop_file
:
59 desktop_file
.write(f
"""\
63 Exec=waydroid show-full-ui
64 Categories=X-WayDroid-App;Utility;
65 X-Purism-FormFactor=Workstation;Mobile;
67 NoDisplay={str(hide).lower()}
70 def userUnlocked(uid
):
71 cfg
= tools
.config
.load(args
)
72 logging
.info("Android with user {} is ready".format(uid
))
74 if cfg
["waydroid"]["auto_adb"] == "True":
75 tools
.helpers
.net
.adb_connect(args
)
77 platformService
= IPlatform
.get_service(args
)
79 if not os
.path
.exists(apps_dir
):
80 os
.mkdir(apps_dir
, 0o700)
81 appsList
= platformService
.getAppsInfo()
84 multiwin
= platformService
.getprop("persist.waydroid.multi_windows", "false")
85 makeWaydroidDesktopFile(multiwin
== "true")
89 def packageStateChanged(mode
, packageName
, uid
):
90 platformService
= IPlatform
.get_service(args
)
92 appInfo
= platformService
.getAppInfo(packageName
)
93 desktop_file_path
= apps_dir
+ "/waydroid." + packageName
+ ".desktop"
96 makeDesktopFile(appInfo
)
98 if os
.path
.isfile(desktop_file_path
):
99 os
.remove(desktop_file_path
)
101 if os
.path
.isfile(desktop_file_path
):
102 if makeDesktopFile(appInfo
) == -1:
103 os
.remove(desktop_file_path
)
105 def service_thread():
107 IUserMonitor
.add_service(args
, userUnlocked
, packageStateChanged
)
111 args
.user_manager
= threading
.Thread(target
=service_thread
)
112 args
.user_manager
.start()
118 if args
.userMonitorLoop
:
119 args
.userMonitorLoop
.quit()
120 except AttributeError:
121 logging
.debug("UserMonitor service is not even started")