Skip to content

Commit

Permalink
Fix potential bug with the in-app updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Nov 16, 2023
1 parent 8c25525 commit 750825b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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(
Expand Down

1 comment on commit 750825b

@iasdeoupxe
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a potential fix for #13261

Please sign in to comment.