comparison cagou/core/platform_/android.py @ 381:eb3f622d8791

android: create/clean a temporary directory on startup: directory returned by tempfiles on Android is actually the root directory of the application, so it is not cleaned. To work around that a `/tmp` directory inside it is now created, and cleaned on startup if it already exists.
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents 9d3481663964
children c7f1176cd2a9
comparison
equal deleted inserted replaced
380:9d3481663964 381:eb3f622d8791
20 import os 20 import os
21 import socket 21 import socket
22 import json 22 import json
23 from functools import partial 23 from functools import partial
24 from urllib.parse import urlparse 24 from urllib.parse import urlparse
25 from pathlib import Path
26 import shutil
25 from jnius import autoclass, cast 27 from jnius import autoclass, cast
26 from android import activity 28 from android import activity
27 from sat.core.i18n import _ 29 from sat.core.i18n import _
28 from sat.core import log as logging 30 from sat.core import log as logging
29 from sat_frontends.tools import jid 31 from sat_frontends.tools import jid
75 service.start(mActivity, argument) 77 service.start(mActivity, argument)
76 78
77 activity.bind(on_new_intent=self.on_new_intent) 79 activity.bind(on_new_intent=self.on_new_intent)
78 self.cache.append((self.on_new_intent, mActivity.getIntent())) 80 self.cache.append((self.on_new_intent, mActivity.getIntent()))
79 host.addListener('profilePlugged', self.onProfilePlugged) 81 host.addListener('profilePlugged', self.onProfilePlugged)
82 local_dir = Path(host.getConfig('', 'local_dir')).resolve()
83 self.tmp_dir = local_dir / 'tmp'
84 # we assert to avoid disaster if `/ 'tmp'` is removed by mistake on the line
85 # above
86 assert self.tmp_dir.resolve() != local_dir
87 # we reset tmp dir on each run, to be sure that there is no residual file
88 if self.tmp_dir.exists():
89 shutil.rmtree(self.tmp_dir)
90 self.tmp_dir.mkdir(0o700)
80 91
81 def on_initFrontendState(self): 92 def on_initFrontendState(self):
82 # XXX: we use a separated socket instead of bridge because if we 93 # XXX: we use a separated socket instead of bridge because if we
83 # try to call a bridge method in on_pause method, the call data 94 # try to call a bridge method in on_pause method, the call data
84 # is not written before the actual pause 95 # is not written before the actual pause