diff --git a/README.md b/README.md index 095570a4f..9896d79bc 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ and [Dynamic Color](https://m3.material.io/styles/color/dynamic-color/overview) | OSS | FOSS dependencies** | | GMS | Proprietary GMS component | -\* Archives and GIFs are not supported +\* May not support some archives ** Fall back to OkHttp on devices that don't support [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c9135ff1a..ead682e70 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -101,11 +101,6 @@ android { minSdk = 23 applicationIdSuffix = ".m" versionNameSuffix = "-M" - externalNativeBuild { - cmake { - arguments("-DMARSHMALLOW=1") - } - } compileOptions { isCoreLibraryDesugaringEnabled = true } diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 236679c95..43bd769e9 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -76,10 +76,5 @@ FetchContent_MakeAvailable(libarchive) include_directories(${libarchive_SOURCE_DIR}/libarchive) # Build and link our app's native lib -if (MARSHMALLOW) - add_library(${PROJECT_NAME} SHARED border.c) - target_link_libraries(${PROJECT_NAME} jnigraphics) -else () - add_library(${PROJECT_NAME} SHARED archive.c border.c gifutils.c natsort/strnatcmp.c) - target_link_libraries(${PROJECT_NAME} archive_static log jnigraphics) -endif () +add_library(${PROJECT_NAME} SHARED archive.c border.c gifutils.c natsort/strnatcmp.c) +target_link_libraries(${PROJECT_NAME} archive_static log jnigraphics) diff --git a/app/src/main/cpp/archive.c b/app/src/main/cpp/archive.c index 4a62ca740..209adc2e7 100644 --- a/app/src/main/cpp/archive.c +++ b/app/src/main/cpp/archive.c @@ -86,6 +86,8 @@ const char supportExt[10][6] = { }; static inline int filename_is_playable_file(const char *name) { + if (!name) + return false; const char *dotptr = strrchr(name, '.'); if (!dotptr++) return false; @@ -105,7 +107,7 @@ static inline int compare_entries(const void *a, const void *b) { static long archive_map_entries_index(archive_ctx *ctx) { long count = 0; while (archive_read_next_header(ctx->arc, &ctx->entry) == ARCHIVE_OK) { - const char *name = archive_entry_pathname(ctx->entry); + const char *name = archive_entry_pathname_utf8(ctx->entry); if (filename_is_playable_file(name)) { entries[count].filename = strdup(name); entries[count].index = count; @@ -164,7 +166,7 @@ static void mempool_release_pages(void *addr, size_t size) { static long archive_list_all_entries(archive_ctx *ctx) { long count = 0; while (archive_read_next_header(ctx->arc, &ctx->entry) == ARCHIVE_OK) - if (filename_is_playable_file(archive_entry_pathname(ctx->entry))) + if (filename_is_playable_file(archive_entry_pathname_utf8(ctx->entry))) count++; if (!count) LOGE("%s", archive_error_string(ctx->arc)); @@ -212,7 +214,7 @@ static int archive_alloc_ctx(archive_ctx **ctxptr) { static int archive_skip_to_index(archive_ctx *ctx, int index) { while (archive_read_next_header(ctx->arc, &ctx->entry) == ARCHIVE_OK) { - if (!filename_is_playable_file(archive_entry_pathname(ctx->entry))) + if (!filename_is_playable_file(archive_entry_pathname_utf8(ctx->entry))) continue; if (ctx->next_index++ == index) { return ctx->next_index - 1; @@ -431,7 +433,7 @@ Java_com_hippo_ehviewer_jni_ArchiveKt_providePassword(JNIEnv *env, jclass thiz, archive_alloc_ctx(&ctx); void *tmpBuf = alloca(4096); while (archive_read_next_header(ctx->arc, &entry) == ARCHIVE_OK) { - if (!filename_is_playable_file(archive_entry_pathname(entry))) + if (!filename_is_playable_file(archive_entry_pathname_utf8(entry))) continue; if (!archive_entry_is_encrypted(entry)) continue; @@ -456,7 +458,7 @@ Java_com_hippo_ehviewer_jni_ArchiveKt_getFilename(JNIEnv *env, jclass thiz, ret = archive_get_ctx(&ctx, index); if (ret) return NULL; - jstring str = (*env)->NewStringUTF(env, archive_entry_pathname(ctx->entry)); + jstring str = (*env)->NewStringUTF(env, archive_entry_pathname_utf8(ctx->entry)); ctx->using = 0; return str; } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/gallery/ArchivePageLoader.kt b/app/src/main/kotlin/com/hippo/ehviewer/gallery/ArchivePageLoader.kt index b52305bd8..cc971bc0e 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/gallery/ArchivePageLoader.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/gallery/ArchivePageLoader.kt @@ -13,16 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@file:RequiresApi(Build.VERSION_CODES.P) - package com.hippo.ehviewer.gallery import android.content.Context import android.net.Uri -import android.os.Build import android.os.ParcelFileDescriptor import android.util.Log -import androidx.annotation.RequiresApi import com.hippo.ehviewer.Settings.archivePasswds import com.hippo.ehviewer.image.ByteBufferSource import com.hippo.ehviewer.image.Image diff --git a/app/src/main/kotlin/com/hippo/ehviewer/jni/Archive.kt b/app/src/main/kotlin/com/hippo/ehviewer/jni/Archive.kt index 1f8ad07ad..f5b5b83a7 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/jni/Archive.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/jni/Archive.kt @@ -1,9 +1,5 @@ -@file:RequiresApi(Build.VERSION_CODES.P) - package com.hippo.ehviewer.jni -import android.os.Build -import androidx.annotation.RequiresApi import java.nio.ByteBuffer external fun releaseByteBuffer(buffer: ByteBuffer) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/jni/GifUtils.kt b/app/src/main/kotlin/com/hippo/ehviewer/jni/GifUtils.kt index 245866fc0..feb520aea 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/jni/GifUtils.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/jni/GifUtils.kt @@ -1,9 +1,5 @@ -@file:RequiresApi(Build.VERSION_CODES.P) - package com.hippo.ehviewer.jni -import android.os.Build -import androidx.annotation.RequiresApi import java.nio.ByteBuffer external fun isGif(fd: Int): Boolean diff --git a/app/src/main/kotlin/com/hippo/unifile/RawFile.kt b/app/src/main/kotlin/com/hippo/unifile/RawFile.kt index b93ee4e43..fe3308da4 100644 --- a/app/src/main/kotlin/com/hippo/unifile/RawFile.kt +++ b/app/src/main/kotlin/com/hippo/unifile/RawFile.kt @@ -15,14 +15,11 @@ */ package com.hippo.unifile -import android.graphics.ImageDecoder import android.net.Uri -import android.os.Build import android.os.ParcelFileDescriptor import android.os.ParcelFileDescriptor.open import android.os.ParcelFileDescriptor.parseMode import android.webkit.MimeTypeMap -import androidx.annotation.RequiresApi import eu.kanade.tachiyomi.util.system.logcat import java.io.File import java.util.Locale @@ -129,9 +126,6 @@ class RawFile(parent: UniFile?, private var file: File) : UniFile(parent) { } override fun openFileDescriptor(mode: String): ParcelFileDescriptor = open(file, parseMode(mode)) - - @RequiresApi(Build.VERSION_CODES.P) - override fun asImageSource() = ImageDecoder.createSource(file) } private fun getTypeForName(name: String): String { diff --git a/app/src/main/kotlin/com/hippo/unifile/UniFile.kt b/app/src/main/kotlin/com/hippo/unifile/UniFile.kt index 212cdf275..ddd27524a 100644 --- a/app/src/main/kotlin/com/hippo/unifile/UniFile.kt +++ b/app/src/main/kotlin/com/hippo/unifile/UniFile.kt @@ -17,11 +17,8 @@ package com.hippo.unifile import android.content.ContentResolver import android.content.Intent -import android.graphics.ImageDecoder import android.net.Uri -import android.os.Build import android.provider.DocumentsContract -import androidx.annotation.RequiresApi import androidx.core.net.toFile import androidx.core.provider.DocumentsContractCompat import java.io.File @@ -206,9 +203,6 @@ abstract class UniFile internal constructor(private val parent: UniFile?) { open fun openFileDescriptor(mode: String) = appCtx.contentResolver.openFileDescriptor(uri, mode) ?: error("Can't open ParcelFileDescriptor") - @RequiresApi(Build.VERSION_CODES.P) - open fun asImageSource() = ImageDecoder.createSource(appCtx.contentResolver, uri) - /** * Test there is a file with the display name in the directory. * diff --git a/app/src/main/kotlin/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/kotlin/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 843ff0ccc..8c93ab17d 100644 --- a/app/src/main/kotlin/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/kotlin/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -168,42 +168,38 @@ class ReaderActivity : EhActivity() { if (ACTION_EH == mAction) { mGalleryInfo?.let { mGalleryProvider = EhPageLoader(it) } } else if (Intent.ACTION_VIEW == mAction) { - if (isAtLeastP) { - if (mUri != null) { - try { - grantUriPermission( - BuildConfig.APPLICATION_ID, - mUri, - Intent.FLAG_GRANT_READ_URI_PERMISSION, - ) - } catch (e: Exception) { - Toast.makeText(this, R.string.error_reading_failed, Toast.LENGTH_SHORT).show() - } + if (mUri != null) { + try { + grantUriPermission( + BuildConfig.APPLICATION_ID, + mUri, + Intent.FLAG_GRANT_READ_URI_PERMISSION, + ) + } catch (e: Exception) { + Toast.makeText(this, R.string.error_reading_failed, Toast.LENGTH_SHORT).show() + } - mGalleryProvider = ArchivePageLoader( - appCtx, - mUri!!, - ) { invalidator -> - runCatching { - dialogState.awaitInputText( - title = getString(R.string.archive_need_passwd), - hint = getString(R.string.archive_passwd), - ) { - if (it.isBlank()) { - getString(R.string.passwd_cannot_be_empty) - } else if (invalidator(it)) { - null - } else { - getString(R.string.passwd_wrong) - } + mGalleryProvider = ArchivePageLoader( + appCtx, + mUri!!, + ) { invalidator -> + runCatching { + dialogState.awaitInputText( + title = getString(R.string.archive_need_passwd), + hint = getString(R.string.archive_passwd), + ) { + if (it.isBlank()) { + getString(R.string.passwd_cannot_be_empty) + } else if (invalidator(it)) { + null + } else { + getString(R.string.passwd_wrong) } - }.onFailure { - finish() - }.getOrThrow() - } + } + }.onFailure { + finish() + }.getOrThrow() } - } else { - Toast.makeText(this, "Archives are not supported before Android P", Toast.LENGTH_LONG).show() } } } diff --git a/docs/README/zh-cn.md b/docs/README/zh-cn.md index c44876260..d4a956710 100644 --- a/docs/README/zh-cn.md +++ b/docs/README/zh-cn.md @@ -72,7 +72,7 @@ | OSS | FOSS 依赖项** | | GMS | 专有 GMS 组件 | -\* 不支持压缩包和 GIF +\* 可能不支持某些压缩包 ** 在不支持 [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) 的设备上回退到 OkHttp diff --git a/docs/README/zh-tw.md b/docs/README/zh-tw.md index cdc7f37de..fec8f6a98 100644 --- a/docs/README/zh-tw.md +++ b/docs/README/zh-tw.md @@ -72,7 +72,7 @@ | OSS | FOSS 依賴項** | | GMS | 專有 GMS 元件 | -\* 不支援壓縮包和 GIF +\* 可能不支援某些壓縮包 ** 在不支援 [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) 的裝置上回退到 OkHttp