]>
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 cfg
= tools
.config
.load(args
)
68 logging
.info("Android with user {} is ready".format(uid
))
70 if cfg
["waydroid"]["auto_adb"] == "True":
71 tools
.helpers
.net
.adb_connect(args
)
73 platformService
= IPlatform
.get_service(args
)
75 if not os
.path
.exists(apps_dir
):
76 os
.mkdir(apps_dir
, 0o700)
77 appsList
= platformService
.getAppsInfo()
80 multiwin
= platformService
.getprop("persist.waydroid.multi_windows", "false")
81 makeWaydroidDesktopFile(multiwin
== "true")
85 def packageStateChanged(mode
, packageName
, uid
):
86 platformService
= IPlatform
.get_service(args
)
88 appInfo
= platformService
.getAppInfo(packageName
)
89 desktop_file_path
= apps_dir
+ "/waydroid." + packageName
+ ".desktop"
92 makeDesktopFile(appInfo
)
94 if os
.path
.isfile(desktop_file_path
):
95 os
.remove(desktop_file_path
)
97 if os
.path
.isfile(desktop_file_path
):
98 if makeDesktopFile(appInfo
) == -1:
99 os
.remove(desktop_file_path
)
101 def service_thread():
103 IUserMonitor
.add_service(args
, userUnlocked
, packageStateChanged
)
107 args
.user_manager
= threading
.Thread(target
=service_thread
)
108 args
.user_manager
.start()
114 if args
.userMonitorLoop
:
115 args
.userMonitorLoop
.quit()
116 except AttributeError:
117 logging
.debug("UserMonitor service is not even started")