From 750825b3c36a6f38b15067dae1ba237f2a427e1b Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 16 Nov 2023 16:19:28 -0500 Subject: [PATCH] Fix potential bug with the in-app updater. --- .../securesms/apkupdate/ApkUpdateInstaller.kt | 5 ++++- .../securesms/apkupdate/ApkUpdateNotifications.kt | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateInstaller.kt b/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateInstaller.kt index 1945561ebc..8d1079e1e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateInstaller.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateInstaller.kt @@ -15,6 +15,7 @@ import org.signal.core.util.StreamUtil import org.signal.core.util.getDownloadManager import org.signal.core.util.logging.Log import org.thoughtcrime.securesms.dependencies.ApplicationDependencies +import org.thoughtcrime.securesms.jobs.ApkUpdateJob import org.thoughtcrime.securesms.keyvalue.SignalStore import org.thoughtcrime.securesms.util.Environment import org.thoughtcrime.securesms.util.FileUtils @@ -38,7 +39,9 @@ object ApkUpdateInstaller { */ fun installOrPromptForInstall(context: Context, downloadId: Long, userInitiated: Boolean) { if (downloadId != SignalStore.apkUpdate().downloadId) { - Log.w(TAG, "DownloadId doesn't match the one we're waiting for! We likely have newer data. Ignoring.") + Log.w(TAG, "DownloadId doesn't match the one we're waiting for (current: $downloadId, expected: ${SignalStore.apkUpdate().downloadId})! We likely have newer data. Ignoring.") + ApkUpdateNotifications.dismissInstallPrompt(context) + ApplicationDependencies.getJobManager().add(ApkUpdateJob()) return } diff --git a/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateNotifications.kt b/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateNotifications.kt index 38782607c2..c985929f8a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateNotifications.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/apkupdate/ApkUpdateNotifications.kt @@ -30,6 +30,7 @@ object ApkUpdateNotifications { */ @SuppressLint("LaunchActivityFromNotification") fun showInstallPrompt(context: Context, downloadId: Long) { + Log.d(TAG, "Showing install prompt. DownloadId: $downloadId") ServiceUtil.getNotificationManager(context).cancel(NotificationIds.APK_UPDATE_FAILED_INSTALL) val pendingIntent = PendingIntent.getBroadcast( @@ -39,7 +40,7 @@ object ApkUpdateNotifications { action = ApkUpdateNotificationReceiver.ACTION_INITIATE_INSTALL putExtra(ApkUpdateNotificationReceiver.EXTRA_DOWNLOAD_ID, downloadId) }, - PendingIntentFlags.immutable() + PendingIntentFlags.updateCurrent() ) val notification = NotificationCompat.Builder(context, NotificationChannels.getInstance().APP_UPDATES) @@ -54,7 +55,13 @@ object ApkUpdateNotifications { ServiceUtil.getNotificationManager(context).notify(NotificationIds.APK_UPDATE_PROMPT_INSTALL, notification) } + fun dismissInstallPrompt(context: Context) { + Log.d(TAG, "Dismissing install prompt.") + ServiceUtil.getNotificationManager(context).cancel(NotificationIds.APK_UPDATE_PROMPT_INSTALL) + } + fun showInstallFailed(context: Context, reason: FailureReason) { + Log.d(TAG, "Showing failed notification. Reason: $reason") ServiceUtil.getNotificationManager(context).cancel(NotificationIds.APK_UPDATE_PROMPT_INSTALL) val pendingIntent = PendingIntent.getActivity(