-
Notifications
You must be signed in to change notification settings - Fork 80
/
service.py
executable file
·65 lines (47 loc) · 1.95 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import os
import sys
from env_json import loadEnv
from os_platform import wrapSentry
env = loadEnv()
if env["platform"] == "android":
import android
from jnius import autoclass
ANDROID_VERSION = autoclass('android.os.Build$VERSION')
SDK_INT = ANDROID_VERSION.SDK_INT
Service = autoclass('org.kivy.android.PythonService').mService
notifi = autoclass("android.app.Notification$Builder")(Service)
notifi.setContentTitle("ZeroNet")
notifi.setContentText("ZeroNet is running")
if SDK_INT >= 26:
manager = autoclass('android.app.NotificationManager') # manager is NotificationManager
channel = autoclass('android.app.NotificationChannel')
managerID = autoclass('android.content.Context').NOTIFICATION_SERVICE
app_channel = channel( # val mChannel = NotificationChannel(CHANNEL_ID, name, importance)
"service_zn", "ZeroNet Background Service", manager.IMPORTANCE_MIN # val importance = NotificationManager.IMPORTANCE_DEFAULT
)
Service.getSystemService(managerID).createNotificationChannel(app_channel) # val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
# notificationManager.createNotificationChannel(mChannel)
notifi.setChannel("service_zn")
# if SDK_INT >= 28:
# Service.startForeground(233,notifi)
# else:
# notification = notifi.build()
# Service.startForeground(233,notification)
notification = notifi.build()
Service.startForeground(233,notification)
print "env %s" % env
sys.path.insert(1, env['srcdir'])
print "srcdir: %s" % env['srcdir']
print "sys.path: %s" % sys.path
os.chdir(env['srcdir'])
print "sys.argv: %s" % sys.argv
with open(env['pidfile'], "w") as f:
f.write(str(os.getpid()))
f.close()
if True: # so beautification does not move this to the top
import zeronet
def main():
zeronet.main()
if __name__ == '__main__':
wrapSentry(main)