Add a system to improve app foreground observation.

There was previously a crash that occurred when multiple threads tried to use ProcessLifecycleOwner, and this will hopefully resolve that.
This commit is contained in:
Greyson Parrelli
2021-02-08 15:37:45 -05:00
committed by GitHub
parent a160af2d11
commit 3bdf2e7e2c
13 changed files with 147 additions and 49 deletions

View File

@@ -107,7 +107,7 @@ public class BackgroundMessageRetriever {
* care of it.
*/
public static boolean shouldIgnoreFetch(@NonNull Context context) {
return ApplicationContext.getInstance(context).isAppVisible() &&
return ApplicationDependencies.getAppForegroundObserver().isForegrounded() &&
!ApplicationDependencies.getSignalServiceNetworkAccess().isCensored(context);
}

View File

@@ -13,9 +13,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ProcessLifecycleOwner;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
@@ -27,6 +24,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.messages.IncomingMessageProcessor.Processor;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.util.AppForegroundObserver;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.InvalidVersionException;
import org.whispersystems.libsignal.util.guava.Optional;
@@ -71,14 +69,14 @@ public class IncomingMessageObserver {
ContextCompat.startForegroundService(context, new Intent(context, ForegroundService.class));
}
ProcessLifecycleOwner.get().getLifecycle().addObserver(new DefaultLifecycleObserver() {
ApplicationDependencies.getAppForegroundObserver().addListener(new AppForegroundObserver.Listener() {
@Override
public void onStart(@NonNull LifecycleOwner owner) {
public void onForeground() {
onAppForegrounded();
}
@Override
public void onStop(@NonNull LifecycleOwner owner) {
public void onBackground() {
onAppBackgrounded();
}
});