mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 12:38:33 +00:00
parent
f066a9cab2
commit
1baf03f51a
@ -41,7 +41,7 @@ public class FcmJobService extends JobService {
|
|||||||
public boolean onStartJob(JobParameters params) {
|
public boolean onStartJob(JobParameters params) {
|
||||||
Log.d(TAG, "onStartJob()");
|
Log.d(TAG, "onStartJob()");
|
||||||
|
|
||||||
if (ApplicationContext.getInstance(getApplicationContext()).isAppVisible()) {
|
if (MessageRetriever.shouldIgnoreFetch(this)) {
|
||||||
Log.i(TAG, "App is foregrounded. No need to run.");
|
Log.i(TAG, "App is foregrounded. No need to run.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.util.PowerManagerCompat;
|
import org.thoughtcrime.securesms.util.PowerManagerCompat;
|
||||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
|
||||||
import org.thoughtcrime.securesms.util.WakeLockUtil;
|
import org.thoughtcrime.securesms.util.WakeLockUtil;
|
||||||
|
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
@ -34,7 +34,7 @@ public class MessageRetriever {
|
|||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public boolean retrieveMessages(@NonNull Context context, Strategy... strategies) {
|
public boolean retrieveMessages(@NonNull Context context, Strategy... strategies) {
|
||||||
if (ApplicationContext.getInstance(context).isAppVisible()) {
|
if (shouldIgnoreFetch(context)) {
|
||||||
Log.i(TAG, "Skipping retrieval -- app is in the foreground.");
|
Log.i(TAG, "Skipping retrieval -- app is in the foreground.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public class MessageRetriever {
|
|||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
for (Strategy strategy : strategies) {
|
for (Strategy strategy : strategies) {
|
||||||
if (ApplicationContext.getInstance(context).isAppVisible()) {
|
if (shouldIgnoreFetch(context)) {
|
||||||
Log.i(TAG, "Stopping further strategy attempts -- app is in the foreground." + logSuffix(startTime));
|
Log.i(TAG, "Stopping further strategy attempts -- app is in the foreground." + logSuffix(startTime));
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
@ -95,6 +95,15 @@ public class MessageRetriever {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if there is no need to execute a message fetch, because the websocket will take
|
||||||
|
* care of it.
|
||||||
|
*/
|
||||||
|
public static boolean shouldIgnoreFetch(@NonNull Context context) {
|
||||||
|
return ApplicationContext.getInstance(context).isAppVisible() &&
|
||||||
|
!ApplicationDependencies.getSignalServiceNetworkAccess().isCensored(context);
|
||||||
|
}
|
||||||
|
|
||||||
private static String logSuffix(long startTime) {
|
private static String logSuffix(long startTime) {
|
||||||
return " (" + (System.currentTimeMillis() - startTime) + " ms elapsed)";
|
return " (" + (System.currentTimeMillis() - startTime) + " ms elapsed)";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user