From 646ceaf4cba4f5a8b0a8daa1a6ede8b160d4145c Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Wed, 10 Jan 2024 18:48:13 +1100 Subject: [PATCH 1/2] refactor: add more debugging logs. Signed-off-by: KaiserBh --- .../sync/service/GoogleDriveSyncService.kt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt index af757463a..145375e68 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt @@ -114,23 +114,39 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync val drive = googleDriveService.driveService if (drive == null) { - logcat(LogPriority.ERROR) { "Google Drive service not initialized" } + logcat(LogPriority.DEBUG) { "Google Drive service not initialized" } throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in)) } val fileList = getAppDataFileList(drive) if (fileList.isEmpty()) { + logcat(LogPriority.INFO) { "No files found in app data" } return null } + val gdriveFileId = fileList[0].id + logcat(LogPriority.DEBUG) { "Google Drive File ID: $gdriveFileId" } val outputStream = ByteArrayOutputStream() - drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream) + try { + drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream) + logcat(LogPriority.DEBUG) { "File downloaded successfully" } + } catch (e: Exception) { + logcat(LogPriority.ERROR) { "Error downloading file: ${e.message}" } + return null + } return withContext(Dispatchers.IO) { - val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray())) - val gson = Gson() - gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java) + try { + val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray())) + val gson = Gson() + val syncData = gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java) + logcat(LogPriority.DEBUG) { "JSON deserialized successfully" } + syncData + } catch (e: Exception) { + logcat(LogPriority.ERROR) { "Failed to convert json to sync data: ${e.message}" } + throw Exception(e.message) + } } } From 3c73891c44a3f0c8ca6d7642c865203ebc440be1 Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Wed, 10 Jan 2024 18:51:02 +1100 Subject: [PATCH 2/2] chore(R8): Keep the backup models. Gson will fail with gson.internal.linkedtreemap cannot be cast to class. Mainly because it's removed or obfuscated by R8. Signed-off-by: KaiserBh --- app/proguard-rules.pro | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index a4eb2c039..31e2c39fd 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -80,4 +80,7 @@ -keep class com.google.api.services.** { *; } # Google OAuth --keep class com.google.api.client.** { *; } \ No newline at end of file +-keep class com.google.api.client.** { *; } + +# Keep backup models, otherwise gson fails on release builds. +-keep class eu.kanade.tachiyomi.data.backup.models.** { *; } \ No newline at end of file