From feb9e1d513e3be8753d053b0524a54c0ab28f830 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 16 Oct 2018 22:54:29 -0700 Subject: [PATCH] Post startService() in onPause() as a possible fix to an Android P bug. We already did it for onResume(), and while it fixed the crash there, the crash just moved to onPause(). Let's see if the same magic works. --- .../PassphraseRequiredActionBarActivity.java | 13 +++++++------ .../thoughtcrime/securesms/WebRtcCallActivity.java | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java index 0dbf3e7c85..8a1dc89176 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java @@ -61,6 +61,7 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA protected void onResume() { Log.i(TAG, "onResume()"); super.onResume(); + isVisible = true; // Android P has a bug in foreground timings where starting a service in onResume() can still crash Util.postToMain(() -> { @@ -69,19 +70,19 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this); else ApplicationContext.getInstance(this).getJobManager().add(new PushNotificationReceiveJob(this)); }); - - isVisible = true; } @Override protected void onPause() { Log.i(TAG, "onPause()"); super.onPause(); - KeyCachingService.registerPassphraseActivityStopped(this); - - if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this); - isVisible = false; + + // Android P has a bug in foreground timings where starting a service in onPause() can still crash + Util.postToMain(() -> { + KeyCachingService.registerPassphraseActivityStopped(this); + if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this); + }); } @Override diff --git a/src/org/thoughtcrime/securesms/WebRtcCallActivity.java b/src/org/thoughtcrime/securesms/WebRtcCallActivity.java index 3112079317..9ce0d8547c 100644 --- a/src/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/src/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -115,8 +115,12 @@ public class WebRtcCallActivity extends Activity { public void onPause() { Log.i(TAG, "onPause"); super.onPause(); - if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this); EventBus.getDefault().unregister(this); + + // Android P has a bug in foreground timings where starting a service in onPause() can still crash + Util.postToMain(() -> { + if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStopped(this); + }); } @Override