]>
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 from tools
.interfaces
import IUserMonitor
8 from tools
.interfaces
import IPlatform
12 def makeDesktopFile(appInfo
):
14 for cat
in appInfo
["categories"]:
15 if cat
.strip() == "android.intent.category.LAUNCHER":
20 packageName
= appInfo
["packageName"]
22 desktop_file_path
= args
.host_user
+ \
23 "/.local/share/applications/" + packageName
+ ".desktop"
24 if not os
.path
.exists(desktop_file_path
):
25 lines
= ["[Desktop Entry]", "Type=Application"]
26 lines
.append("Name=" + appInfo
["name"])
27 lines
.append("Exec=waydroid app launch " + packageName
)
28 lines
.append("Icon=" + args
.waydroid_data
+ "/icons/" + packageName
+ ".png")
29 desktop_file
= open(desktop_file_path
, "w")
31 desktop_file
.write(line
+ "\n")
33 os
.chmod(desktop_file_path
, 0o755)
36 def makeWaydroidDesktopFile():
37 desktop_file_path
= args
.host_user
+ \
38 "/.local/share/applications/Waydroid.desktop"
39 if not os
.path
.exists(desktop_file_path
):
40 lines
= ["[Desktop Entry]", "Type=Application"]
41 lines
.append("Name=Waydroid")
42 lines
.append("Exec=waydroid show-full-ui")
43 lines
.append("Icon=" + tools
.config
.tools_src
+ "/data/AppIcon.png")
44 desktop_file
= open(desktop_file_path
, "w")
46 desktop_file
.write(line
+ "\n")
48 os
.chmod(desktop_file_path
, 0o755)
50 def userUnlocked(uid
):
51 logging
.info("Android with user {} is ready".format(uid
))
52 session_cfg
= tools
.config
.load_session()
53 args
.waydroid_data
= session_cfg
["session"]["waydroid_data"]
54 args
.host_user
= session_cfg
["session"]["host_user"]
56 platformService
= IPlatform
.get_service(args
)
58 appsList
= platformService
.getAppsInfo()
61 multiwin
= platformService
.getprop("persist.waydroid.multi_windows", "false")
62 if multiwin
== "false":
63 makeWaydroidDesktopFile()
65 desktop_file_path
= args
.host_user
+ \
66 "/.local/share/applications/Waydroid.desktop"
67 if os
.path
.isfile(desktop_file_path
):
68 os
.remove(desktop_file_path
)
70 def packageStateChanged(mode
, packageName
, uid
):
71 platformService
= IPlatform
.get_service(args
)
73 appInfo
= platformService
.getAppInfo(packageName
)
74 desktop_file_path
= args
.host_user
+ \
75 "/.local/share/applications/" + packageName
+ ".desktop"
78 makeDesktopFile(appInfo
)
80 if os
.path
.isfile(desktop_file_path
):
81 os
.remove(desktop_file_path
)
83 if os
.path
.isfile(desktop_file_path
):
84 if makeDesktopFile(appInfo
) == -1:
85 os
.remove(desktop_file_path
)
88 IUserMonitor
.add_service(args
, userUnlocked
, packageStateChanged
)
90 args
.user_manager
= threading
.Thread(target
=service_thread
)
91 args
.user_manager
.start()
95 if args
.userMonitorLoop
:
96 args
.userMonitorLoop
.quit()
97 except AttributeError:
98 logging
.debug("UserMonitor service is not even started")