refactor: strip release debug logs and drop hand-rolled catches

- Strip Log.d/Log.v in release via R8; remove the per-frame parallax log.
- Use runCatchingCancellable instead of manual cancellation rethrows.
- Remove an unreachable catch in AlbumViewViewModel.deleteSelected.
- Reduce AlbumRefreshWorker to the work itself; drop log-only counters.
- Replace a force-unwrap in HomeScreen with a local val.
This commit is contained in:
Anthonyy232 committed 2026-10-13 09:10:03 -07:00
1 parent 7dc1171678
commit 3b85cdb822
8 files changed
+38 -99

No files matched your search

+6
View File
@@ -1,2 +1,8 @@
# Library consumer rules preserve their runtime entry points. Keep release crash locations. # Library consumer rules preserve their runtime entry points. Keep release crash locations.
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable
# Strip debug and verbose logging from release builds.
-assumenosideeffects class android.util.Log {
public static int d(...);
public static int v(...);
}
@@ -2,14 +2,14 @@ package com.anthonyla.paperize.core.util
import android.content.ContentResolver import android.content.ContentResolver
import android.content.Context import android.content.Context
import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.os.CancellationSignal import android.os.CancellationSignal
import android.provider.DocumentsContract import android.provider.DocumentsContract
import com.anthonyla.paperize.core.constants.Constants import com.anthonyla.paperize.core.constants.Constants
import android.database.Cursor import com.anthonyla.paperize.core.runCatchingCancellable
import java.io.IOException import java.io.IOException
import java.util.UUID import java.util.UUID
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
@@ -35,18 +35,14 @@ fun Uri.isValid(contentResolver: ContentResolver): Boolean {
/** Only a successful, complete query with no rows proves that a document was removed. */ /** Only a successful, complete query with no rows proves that a document was removed. */
fun Uri.isDocumentMissing(contentResolver: ContentResolver): Boolean { fun Uri.isDocumentMissing(contentResolver: ContentResolver): Boolean {
if (scheme != ContentResolver.SCHEME_CONTENT) return false if (scheme != ContentResolver.SCHEME_CONTENT) return false
return try { // Offline providers, revoked permissions and query failures do not prove deletion.
return runCatchingCancellable {
contentResolver.query(this, arrayOf(android.provider.OpenableColumns.DISPLAY_NAME), null, null, null) contentResolver.query(this, arrayOf(android.provider.OpenableColumns.DISPLAY_NAME), null, null, null)
?.use { cursor -> ?.use { cursor ->
cursor.requireComplete() cursor.requireComplete()
!cursor.moveToFirst() !cursor.moveToFirst()
} ?: false } ?: false
} catch (e: CancellationException) { }.getOrDefault(false)
throw e
} catch (_: Exception) {
// Offline providers, revoked permissions and query failures do not prove deletion.
false
}
} }
private fun Cursor.requireComplete() { private fun Cursor.requireComplete() {
@@ -5,6 +5,7 @@ import com.anthonyla.paperize.core.EmptyAlbumException
import com.anthonyla.paperize.core.NoValidWallpaperException import com.anthonyla.paperize.core.NoValidWallpaperException
import com.anthonyla.paperize.core.ScreenType import com.anthonyla.paperize.core.ScreenType
import com.anthonyla.paperize.core.constants.Constants import com.anthonyla.paperize.core.constants.Constants
import com.anthonyla.paperize.core.runCatchingCancellable
import com.anthonyla.paperize.domain.model.PreparedWallpaper import com.anthonyla.paperize.domain.model.PreparedWallpaper
import com.anthonyla.paperize.domain.model.Wallpaper import com.anthonyla.paperize.domain.model.Wallpaper
import com.anthonyla.paperize.domain.repository.SettingsRepository import com.anthonyla.paperize.domain.repository.SettingsRepository
@@ -87,49 +88,26 @@ class ChangeWallpaperUseCase @Inject constructor(
wallpaperId: String, wallpaperId: String,
shuffle: Boolean shuffle: Boolean
) { ) {
try { runCatchingCancellable { wallpaperRepository.setCurrentWallpaper(albumId, screenType, wallpaperId) }
wallpaperRepository.setCurrentWallpaper( .onFailure {
albumId, Log.e(TAG, "Applied wallpaper could not be recorded as current", it)
screenType, return
wallpaperId }
)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Applied wallpaper could not be recorded as current", e)
return
}
try { runCatchingCancellable {
wallpaperRepository.ensureWallpaperQueue(albumId, screenType, shuffle) wallpaperRepository.ensureWallpaperQueue(albumId, screenType, shuffle)
// Build first when this is the first synchronized use of a screen queue, then remove // Build first when this is the first synchronized use of a screen queue, then remove
// the exact applied item. This prevents the just-applied wallpaper from being // the exact applied item. This prevents the just-applied wallpaper from being
// reintroduced at the head of a freshly built queue. // reintroduced at the head of a freshly built queue.
wallpaperRepository.removeWallpaperFromQueue( wallpaperRepository.removeWallpaperFromQueue(albumId, screenType, wallpaperId)
albumId, }.onFailure { Log.w(TAG, "Queue sync failed; it will rebuild on the next change", it) }
screenType,
wallpaperId
)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.w(TAG, "Queue sync failed; it will rebuild on the next change", e)
}
} }
/** Restore a prepared item after WallpaperManager rejected it. */ /** Restore a prepared item after WallpaperManager rejected it. */
suspend fun restore(prepared: PreparedWallpaper) { suspend fun restore(prepared: PreparedWallpaper) {
try { runCatchingCancellable {
wallpaperRepository.restoreWallpaperToQueueFront( wallpaperRepository.restoreWallpaperToQueueFront(prepared.albumId, prepared.screenType, prepared.wallpaperId)
prepared.albumId, }.onFailure { Log.e(TAG, "Failed to restore rejected wallpaper to its queue", it) }
prepared.screenType,
prepared.wallpaperId
)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Failed to restore rejected wallpaper to its queue", e)
}
} }
private companion object { private companion object {
@@ -168,11 +168,6 @@ class AlbumViewViewModel @Inject constructor(
.onSuccess { _selectedFolders.value -= folderId } .onSuccess { _selectedFolders.value -= folderId }
.onFailure { _message.value = R.string.delete_items_failed } .onFailure { _message.value = R.string.delete_items_failed }
} }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Error removing selected items", e)
_message.value = R.string.delete_items_failed
} finally { } finally {
_isDeleting.value = false _isDeleting.value = false
} }
@@ -97,14 +97,15 @@ fun HomeScreen(
) { index -> ) { index ->
when (index) { when (index) {
0 -> { 0 -> {
if (wallpaperMode == null) { val mode = wallpaperMode
if (mode == null) {
Box(modifier = Modifier.fillMaxSize()) Box(modifier = Modifier.fillMaxSize())
} else { } else {
WallpaperScreen( WallpaperScreen(
albums = albums, albums = albums,
persistedScheduleSettings = scheduleSettings, persistedScheduleSettings = scheduleSettings,
appSettings = appSettings, appSettings = appSettings,
wallpaperMode = wallpaperMode!!, wallpaperMode = mode,
onToggleChanger = viewModel::setChangerEnabled, onToggleChanger = viewModel::setChangerEnabled,
onSelectAlbum = viewModel::selectAlbum, onSelectAlbum = viewModel::selectAlbum,
onUpdateScheduleSettings = viewModel::updateScheduleSettings, onUpdateScheduleSettings = viewModel::updateScheduleSettings,
@@ -1,4 +1,5 @@
package com.anthonyla.paperize.presentation.screens.library package com.anthonyla.paperize.presentation.screens.library
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@@ -39,7 +40,6 @@ import com.anthonyla.paperize.presentation.common.theme.AppSpacing
import com.anthonyla.paperize.presentation.screens.library.components.AlbumItem import com.anthonyla.paperize.presentation.screens.library.components.AlbumItem
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
fun LibraryScreen( fun LibraryScreen(
albums: List<AlbumSummary>, albums: List<AlbumSummary>,
@@ -276,7 +276,6 @@ class PaperizeLiveWallpaperService : GLWallpaperService() {
yPixelOffset: Int yPixelOffset: Int
) { ) {
super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset) super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset)
Log.d(TAG, "onOffsetsChanged: xOffset=$xOffset, xOffsetStep=$xOffsetStep, xPixelOffset=$xPixelOffset")
renderer.setNormalOffsetX(xOffset) renderer.setNormalOffsetX(xOffset)
} }
@@ -10,7 +10,6 @@ import com.anthonyla.paperize.domain.repository.AlbumRepository
import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
@HiltWorker @HiltWorker
@@ -21,57 +20,22 @@ class AlbumRefreshWorker @AssistedInject constructor(
private val refreshFolderUseCase: RefreshFolderUseCase private val refreshFolderUseCase: RefreshFolderUseCase
) : CoroutineWorker(appContext, workerParams) { ) : CoroutineWorker(appContext, workerParams) {
/** Prune missing items and pick up new folder files. One failing album or folder does not stop the rest. */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
return try { albumRepository.getAlbumSummaries().first().forEach { album ->
Log.d(TAG, "Starting daily album refresh") runCatchingCancellable { albumRepository.pruneMissingEntries(album.id) }
.onFailure { Log.e(TAG, "Error validating album '${album.name}'", it) }
val albums = albumRepository.getAlbumSummaries().first() // Reload after validation, which may have removed folders from the snapshot.
albumRepository.getAlbumById(album.id).first()?.folders.orEmpty().forEach { folder ->
if (albums.isEmpty()) { runCatchingCancellable { refreshFolderUseCase(folder.id) }
Log.d(TAG, "No albums to refresh") .onFailure { Log.e(TAG, "Error refreshing folder '${folder.name}'", it) }
return Result.success()
} }
var totalRemoved = 0
var totalAdded = 0
var failedCount = 0
albums.forEach { album ->
runCatchingCancellable { albumRepository.pruneMissingEntries(album.id) }
.onSuccess { removedCount ->
totalRemoved += removedCount
if (removedCount > 0) {
Log.d(TAG, "Album '${album.name}': removed $removedCount invalid items")
}
}
.onFailure {
Log.e(TAG, "Error validating album '${album.name}'", it)
failedCount++
}
// Reload after validation, which may have removed folders from the snapshot.
val currentAlbum = albumRepository.getAlbumById(album.id).first()
currentAlbum?.folders.orEmpty().forEach { folder ->
runCatchingCancellable { refreshFolderUseCase(folder.id) }
.onSuccess { totalAdded += it }
.onFailure {
Log.e(TAG, "Error refreshing folder '${folder.name}'", it)
failedCount++
}
}
}
Log.d(TAG, "Daily album refresh completed: removed $totalRemoved items, added $totalAdded new wallpapers across ${albums.size} albums ($failedCount failures)")
Result.success()
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Error during album refresh", e)
Result.failure()
} }
return Result.success()
} }
companion object { private companion object {
private const val TAG = "AlbumRefreshWorker" const val TAG = "AlbumRefreshWorker"
} }
} }