From a2b3301c5be8e7b77a3d65a581de9d393b212358 Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Thu, 12 Sep 2024 01:41:24 -0700 Subject: [PATCH] Fix: Fix crash due to new SequencedCollection API in Android 15 --- .../java/me/zhanghai/android/files/compat/KotlinCompat.kt | 6 ++++++ .../me/zhanghai/android/files/filejob/FileJobService.kt | 3 ++- .../android/files/provider/common/ByteStringListPath.kt | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/me/zhanghai/android/files/compat/KotlinCompat.kt b/app/src/main/java/me/zhanghai/android/files/compat/KotlinCompat.kt index b9066c1dc..cadc64136 100644 --- a/app/src/main/java/me/zhanghai/android/files/compat/KotlinCompat.kt +++ b/app/src/main/java/me/zhanghai/android/files/compat/KotlinCompat.kt @@ -6,5 +6,11 @@ package me.zhanghai.android.files.compat import kotlin.comparisons.reversed as kotlinReversed +import kotlin.collections.removeFirst as kotlinRemoveFirst +import kotlin.collections.removeLast as kotlinRemoveLast fun Comparator.reversedCompat(): Comparator = kotlinReversed() + +fun MutableList.removeFirstCompat(): T = kotlinRemoveFirst() + +fun MutableList.removeLastCompat(): T = kotlinRemoveLast() diff --git a/app/src/main/java/me/zhanghai/android/files/filejob/FileJobService.kt b/app/src/main/java/me/zhanghai/android/files/filejob/FileJobService.kt index 962255620..faa013ac4 100644 --- a/app/src/main/java/me/zhanghai/android/files/filejob/FileJobService.kt +++ b/app/src/main/java/me/zhanghai/android/files/filejob/FileJobService.kt @@ -20,6 +20,7 @@ import me.zhanghai.android.files.util.WakeWifiLock import me.zhanghai.android.files.util.removeFirst import java.util.concurrent.Executors import java.util.concurrent.Future +import me.zhanghai.android.files.compat.removeFirstCompat class FileJobService : Service() { private lateinit var wakeWifiLock: WakeWifiLock @@ -39,7 +40,7 @@ class FileJobService : Service() { instance = this while (pendingJobs.isNotEmpty()) { - startJob(pendingJobs.removeFirst()) + startJob(pendingJobs.removeFirstCompat()) } } diff --git a/app/src/main/java/me/zhanghai/android/files/provider/common/ByteStringListPath.kt b/app/src/main/java/me/zhanghai/android/files/provider/common/ByteStringListPath.kt index d31cf30c4..733ad01d5 100644 --- a/app/src/main/java/me/zhanghai/android/files/provider/common/ByteStringListPath.kt +++ b/app/src/main/java/me/zhanghai/android/files/provider/common/ByteStringListPath.kt @@ -7,18 +7,19 @@ package me.zhanghai.android.files.provider.common import android.os.Parcel import android.os.Parcelable +import java.net.URI import java8.nio.file.InvalidPathException import java8.nio.file.Path import java8.nio.file.ProviderMismatchException +import kotlin.math.min import me.zhanghai.android.files.compat.readBooleanCompat +import me.zhanghai.android.files.compat.removeLastCompat import me.zhanghai.android.files.compat.writeBooleanCompat import me.zhanghai.android.files.compat.writeParcelableListCompat import me.zhanghai.android.files.util.endsWith import me.zhanghai.android.files.util.hash import me.zhanghai.android.files.util.readParcelableListCompat import me.zhanghai.android.files.util.startsWith -import java.net.URI -import kotlin.math.min abstract class ByteStringListPath> : AbstractPath, Parcelable { protected val separator: Byte @@ -132,8 +133,7 @@ abstract class ByteStringListPath> : AbstractPath, if (normalizedSegments.last() == BYTE_STRING_DOT_DOT) { normalizedSegments += segment } else { - @OptIn(ExperimentalStdlibApi::class) - normalizedSegments.removeLast() + normalizedSegments.removeLastCompat() } } } else {