diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-12-11 14:38:43 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-05-09 09:33:26 +0100 |
commit | f3feb1ec785b19925a4ea79fd49813a4171f2fb2 (patch) | |
tree | 755af6b8ec1cf551f0692abf74c28e21ed97ec91 /vcl | |
parent | 3830053a76401e9219047cc3aaa2d63070e9ac19 (diff) |
android: add abstraction to allow us to DetachThread sensibly.
If we fail to do this after runLoop - some Android VMs can get really
upset if we quit a thread without doing this, also ensure that we
AttachThread to new polling loop threads as we come in for good
measure - duplicate Attach's are NOPs.
Change-Id: I32454773af4e02c97df0b6c02f61b1dc74df80b0
Reviewed-on: https://gerrit.libreoffice.org/84956
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
(cherry picked from commit 7241382ccc0a028c5f08304090a6344e582db068)
Reviewed-on: https://gerrit.libreoffice.org/84969
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/android/androidinst.cxx | 17 | ||||
-rw-r--r-- | vcl/inc/android/androidinst.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/salinst.hxx | 3 | ||||
-rw-r--r-- | vcl/source/app/svapp.cxx | 5 |
4 files changed, 28 insertions, 0 deletions
diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx index d8f234ccc7f5..ddc6e92d55f3 100644 --- a/vcl/android/androidinst.cxx +++ b/vcl/android/androidinst.cxx @@ -57,10 +57,12 @@ AndroidSalInstance *AndroidSalInstance::getInstance() AndroidSalInstance::AndroidSalInstance( std::unique_ptr<SalYieldMutex> pMutex ) : SvpSalInstance( std::move(pMutex) ) { + // FIXME: remove when uniPoll & runLoop is the only android entry poit. int res = (lo_get_javavm())->AttachCurrentThread(&m_pJNIEnv, NULL); LOGI("AttachCurrentThread res=%d env=%p", res, m_pJNIEnv); } +// This is never called on Android until app exit. AndroidSalInstance::~AndroidSalInstance() { int res = (lo_get_javavm())->DetachCurrentThread(); @@ -78,6 +80,21 @@ bool AndroidSalInstance::AnyInput( VclInputFlags nType ) return SvpSalInstance::s_pDefaultInstance->HasUserEvents(); } +void AndroidSalInstance::updateMainThread() +{ + int res = (lo_get_javavm())->AttachCurrentThread(&m_pJNIEnv, NULL); + LOGI("updateMainThread AttachCurrentThread res=%d env=%p", res, m_pJNIEnv); + SvpSalInstance::updateMainThread(); +} + +void AndroidSalInstance::releaseMainThread() +{ + int res = (lo_get_javavm())->DetachCurrentThread(); + LOGI("releaseMainThread DetachCurrentThread res=%d", res); + + SvpSalInstance::releaseMainThread(); +} + class AndroidSalSystem : public SvpSalSystem { public: AndroidSalSystem() : SvpSalSystem() {} diff --git a/vcl/inc/android/androidinst.hxx b/vcl/inc/android/androidinst.hxx index 49758f3efd70..526174b14951 100644 --- a/vcl/inc/android/androidinst.hxx +++ b/vcl/inc/android/androidinst.hxx @@ -38,6 +38,9 @@ public: // mainloop pieces virtual bool AnyInput( VclInputFlags nType ); + + virtual void updateMainThread(); + virtual void releaseMainThread(); }; #endif // INCLUDED_VCL_INC_ANDROID_ANDROIDINST_HXX diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx index f8935baf218a..c9c0fcccdc0e 100644 --- a/vcl/inc/salinst.hxx +++ b/vcl/inc/salinst.hxx @@ -196,7 +196,10 @@ public: virtual void jobStartedPrinterUpdate() {} virtual void jobEndedPrinterUpdate() {} + /// Set the app's (somewhat) magic/main-thread to this one. virtual void updateMainThread() {} + /// Disconnect that - good for detatching from the JavaVM on Android. + virtual void releaseMainThread() {} /// get information about underlying versions virtual OUString getOSVersion() { return "-"; } diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index c4c3be9699e3..988fdb01aaaf 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -1644,6 +1644,11 @@ void unregisterPollCallbacks() ImplSVData * pSVData = ImplGetSVData(); if (pSVData) { + // Not hyper-elegant - but in the case of Android & unipoll we need to detach + // this thread from the JVM's clutches to avoid a crash closing document + if (pSVData->mpPollClosure && pSVData->mpDefInst) + pSVData->mpDefInst->releaseMainThread(); + // Just set mpPollClosure to null as that is what calling this means, that the callback data // points to an object that no longer exists. In particular, don't set // pSVData->mpPollCallback to nullptr as that is used to detect whether Unipoll is in use in |