Post startService() in onResume() as a possible fix to an Android P bug.

Got confirmation that the crash we're seeing is a bug, and this might be
a possible workaround.
This commit is contained in:
Greyson Parrelli 2018-10-16 11:47:58 -07:00
parent 92773b1a12
commit 7e485b8095
3 changed files with 19 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.service.MessageRetrievalService;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import java.util.Locale;
@ -60,10 +61,14 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
protected void onResume() {
Log.i(TAG, "onResume()");
super.onResume();
KeyCachingService.registerPassphraseActivityStarted(this);
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
else ApplicationContext.getInstance(this).getJobManager().add(new PushNotificationReceiveJob(this));
// Android P has a bug in foreground timings where starting a service in onResume() can still crash
Util.postToMain(() -> {
KeyCachingService.registerPassphraseActivityStarted(this);
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
else ApplicationContext.getInstance(this).getJobManager().add(new PushNotificationReceiveJob(this));
});
isVisible = true;
}

View File

@ -48,6 +48,7 @@ import org.thoughtcrime.securesms.service.MessageRetrievalService;
import org.thoughtcrime.securesms.service.WebRtcCallService;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.SignalProtocolAddress;
@ -88,7 +89,12 @@ public class WebRtcCallActivity extends Activity {
public void onResume() {
Log.i(TAG, "onResume()");
super.onResume();
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
// Android P has a bug in foreground timings where starting a service in onResume() can still crash
Util.postToMain(() -> {
if (!networkAccess.isCensored(this)) MessageRetrievalService.registerActivityStarted(this);
});
initializeScreenshotSecurity();
EventBus.getDefault().register(this);
}

View File

@ -384,6 +384,10 @@ public class Util {
}
}
public static void postToMain(final @NonNull Runnable runnable) {
handler.post(runnable);
}
public static void runOnMain(final @NonNull Runnable runnable) {
if (isMainThread()) runnable.run();
else handler.post(runnable);