]>
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 os
.path
.isfile(desktop_file_path
):
53 os
.remove(desktop_file_path
)
54 with open(desktop_file_path
, "w") as desktop_file
:
55 desktop_file
.write(f
"""\
59 Exec=waydroid show-full-ui
60 Categories=X-WayDroid-App;
61 X-Purism-FormFactor=Workstation;Mobile;
63 NoDisplay={str(hide).lower()}
66 def userUnlocked(uid
):
67 logging
.info("Android with user {} is ready".format(uid
))
69 tools
.helpers
.net
.adb_connect(args
)
71 platformService
= IPlatform
.get_service(args
)
73 if not os
.path
.exists(apps_dir
):
74 os
.mkdir(apps_dir
, 0o700)
75 appsList
= platformService
.getAppsInfo()
78 multiwin
= platformService
.getprop("persist.waydroid.multi_windows", "false")
79 makeWaydroidDesktopFile(multiwin
== "true")
83 def packageStateChanged(mode
, packageName
, uid
):
84 platformService
= IPlatform
.get_service(args
)
86 appInfo
= platformService
.getAppInfo(packageName
)
87 desktop_file_path
= apps_dir
+ "/waydroid." + packageName
+ ".desktop"
90 makeDesktopFile(appInfo
)
92 if os
.path
.isfile(desktop_file_path
):
93 os
.remove(desktop_file_path
)
95 if os
.path
.isfile(desktop_file_path
):
96 if makeDesktopFile(appInfo
) == -1:
97 os
.remove(desktop_file_path
)
101 IUserMonitor
.add_service(args
, userUnlocked
, packageStateChanged
)
105 args
.user_manager
= threading
.Thread(target
=service_thread
)
106 args
.user_manager
.start()
112 if args
.userMonitorLoop
:
113 args
.userMonitorLoop
.quit()
114 except AttributeError:
115 logging
.debug("UserMonitor service is not even started")