Update restore progress banner UI/UX and job behavior.

This commit is contained in:
Cody Henthorne
2024-10-02 09:49:28 -04:00
committed by Greyson Parrelli
parent 320d51707d
commit 93609106b0
20 changed files with 491 additions and 229 deletions

View File

@@ -10,11 +10,12 @@ import org.thoughtcrime.securesms.jobmanager.ConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobMigration;
import org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.BatteryNotLowConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.CellServiceConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.ChangeNumberConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.ChangeNumberConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.ChargingConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.ChargingConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.ChargingAndBatteryIsNotLowConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.DataRestoreConstraint;
import org.thoughtcrime.securesms.jobmanager.impl.DataRestoreConstraintObserver;
import org.thoughtcrime.securesms.jobmanager.impl.DecryptionsDrainedConstraint;
@@ -364,6 +365,7 @@ public final class JobManagerFactories {
public static Map<String, Constraint.Factory> getConstraintFactories(@NonNull Application application) {
return new HashMap<String, Constraint.Factory>() {{
put(AutoDownloadEmojiConstraint.KEY, new AutoDownloadEmojiConstraint.Factory(application));
put(BatteryNotLowConstraint.KEY, new BatteryNotLowConstraint.Factory());
put(ChangeNumberConstraint.KEY, new ChangeNumberConstraint.Factory());
put(ChargingConstraint.KEY, new ChargingConstraint.Factory());
put(DataRestoreConstraint.KEY, new DataRestoreConstraint.Factory());
@@ -379,7 +381,7 @@ public final class JobManagerFactories {
public static List<ConstraintObserver> getConstraintObservers(@NonNull Application application) {
return Arrays.asList(CellServiceConstraintObserver.getInstance(application),
new ChargingConstraintObserver(application),
new ChargingAndBatteryIsNotLowConstraintObserver(application),
new NetworkConstraintObserver(application),
new SqlCipherMigrationConstraintObserver(),
new DecryptionsDrainedConstraintObserver(),

View File

@@ -19,7 +19,8 @@ import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.events.PartProgressEvent
import org.thoughtcrime.securesms.jobmanager.Job
import org.thoughtcrime.securesms.jobmanager.JobLogger.format
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.jobmanager.impl.BatteryNotLowConstraint
import org.thoughtcrime.securesms.jobmanager.impl.WifiConstraint
import org.thoughtcrime.securesms.jobs.protos.RestoreAttachmentJobData
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.mms.MmsException
@@ -107,9 +108,9 @@ class RestoreAttachmentJob private constructor(
private constructor(messageId: Long, attachmentId: AttachmentId, manual: Boolean, queue: String) : this(
Parameters.Builder()
.setQueue(queue)
.addConstraint(NetworkConstraint.KEY)
.addConstraint(WifiConstraint.KEY)
.addConstraint(BatteryNotLowConstraint.KEY)
.setLifespan(TimeUnit.DAYS.toMillis(30))
.setMaxAttempts(3)
.build(),
messageId,
attachmentId,
@@ -129,7 +130,7 @@ class RestoreAttachmentJob private constructor(
}
@Throws(Exception::class)
public override fun onRun() {
override fun onRun() {
doWork()
if (!SignalDatabase.messages.isStory(messageId)) {
@@ -170,7 +171,7 @@ class RestoreAttachmentJob private constructor(
} else {
Log.w(TAG, format(this, "onFailure() messageId: $messageId attachmentId: $attachmentId"))
markFailed(messageId, attachmentId)
markFailed(attachmentId)
}
}
@@ -255,7 +256,7 @@ class RestoreAttachmentJob private constructor(
}
} catch (e: InvalidAttachmentException) {
Log.w(TAG, "Experienced exception while trying to download an attachment.", e)
markFailed(messageId, attachmentId)
markFailed(attachmentId)
} catch (e: NonSuccessfulResponseCodeException) {
if (SignalStore.backup.backsUpMedia) {
if (e.code == 404 && !forceTransitTier && attachment.remoteLocation?.isNotBlank() == true) {
@@ -269,30 +270,30 @@ class RestoreAttachmentJob private constructor(
}
Log.w(TAG, "Experienced exception while trying to download an attachment.", e)
markFailed(messageId, attachmentId)
markFailed(attachmentId)
} catch (e: MmsException) {
Log.w(TAG, "Experienced exception while trying to download an attachment.", e)
markFailed(messageId, attachmentId)
markFailed(attachmentId)
} catch (e: MissingConfigurationException) {
Log.w(TAG, "Experienced exception while trying to download an attachment.", e)
markFailed(messageId, attachmentId)
markFailed(attachmentId)
} catch (e: InvalidMessageException) {
Log.w(TAG, "Experienced an InvalidMessageException while trying to download an attachment.", e)
if (e.cause is InvalidMacException) {
Log.w(TAG, "Detected an invalid mac. Treating as a permanent failure.")
markPermanentlyFailed(messageId, attachmentId)
markPermanentlyFailed(attachmentId)
} else {
markFailed(messageId, attachmentId)
markFailed(attachmentId)
}
}
}
private fun markFailed(messageId: Long, attachmentId: AttachmentId) {
SignalDatabase.attachments.setTransferProgressFailed(attachmentId, messageId)
private fun markFailed(attachmentId: AttachmentId) {
SignalDatabase.attachments.setRestoreTransferState(attachmentId, AttachmentTable.TRANSFER_PROGRESS_FAILED)
}
private fun markPermanentlyFailed(messageId: Long, attachmentId: AttachmentId) {
SignalDatabase.attachments.setTransferProgressPermanentFailure(attachmentId, messageId)
private fun markPermanentlyFailed(attachmentId: AttachmentId) {
SignalDatabase.attachments.setRestoreTransferState(attachmentId, AttachmentTable.TRANSFER_PROGRESS_PERMANENT_FAILURE)
}
class Factory : Job.Factory<RestoreAttachmentJob?> {