Fix crash when running shortcut update job on older APIs.
This commit is contained in:
parent
b58b0fd7a8
commit
dc6045ca8b
3 changed files with 16 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
package org.thoughtcrime.securesms.jobs;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
|
@ -7,6 +9,7 @@ import org.signal.core.util.logging.Log;
|
|||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
@ -18,6 +21,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.ConversationUtil.CONVERSATION_SUPPORT_VERSION;
|
||||
|
||||
/**
|
||||
* On some devices, interacting with the ShortcutManager can take a very long time (several seconds).
|
||||
* So, we interact with it in a job instead, and keep it in one queue so it can't starve the other
|
||||
|
@ -29,7 +34,13 @@ public class ConversationShortcutUpdateJob extends BaseJob {
|
|||
|
||||
public static final String KEY = "ConversationShortcutUpdateJob";
|
||||
|
||||
public ConversationShortcutUpdateJob() {
|
||||
public static void enqueue() {
|
||||
if (Build.VERSION.SDK_INT >= CONVERSATION_SUPPORT_VERSION) {
|
||||
ApplicationDependencies.getJobManager().add(new ConversationShortcutUpdateJob());
|
||||
}
|
||||
}
|
||||
|
||||
private ConversationShortcutUpdateJob() {
|
||||
this(new Parameters.Builder()
|
||||
.setQueue("ConversationShortcutUpdateJob")
|
||||
.setLifespan(TimeUnit.MINUTES.toMillis(15))
|
||||
|
@ -52,7 +63,7 @@ public class ConversationShortcutUpdateJob extends BaseJob {
|
|||
}
|
||||
|
||||
@Override
|
||||
@RequiresApi(ConversationUtil.CONVERSATION_SUPPORT_VERSION)
|
||||
@RequiresApi(CONVERSATION_SUPPORT_VERSION)
|
||||
protected void onRun() throws Exception {
|
||||
if (TextSecurePreferences.isScreenLockEnabled(context)) {
|
||||
Log.i(TAG, "Screen lock enabled. Clearing shortcuts.");
|
||||
|
|
|
@ -57,6 +57,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
|||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.ConversationUtil;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
@ -241,7 +242,7 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||
intent.setAction(KeyCachingService.LOCK_TOGGLED_EVENT);
|
||||
getContext().startService(intent);
|
||||
|
||||
ApplicationDependencies.getJobManager().add(new ConversationShortcutUpdateJob());
|
||||
ConversationUtil.refreshRecipientShortcuts();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -58,9 +58,7 @@ public final class ConversationUtil {
|
|||
* Enqueues a job to update the list of shortcuts.
|
||||
*/
|
||||
public static void refreshRecipientShortcuts() {
|
||||
if (Build.VERSION.SDK_INT >= CONVERSATION_SUPPORT_VERSION) {
|
||||
ApplicationDependencies.getJobManager().add(new ConversationShortcutUpdateJob());
|
||||
}
|
||||
ConversationShortcutUpdateJob.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue