Remove unnecessary logging statements across various components to clean up code and improve readability. This includes removing debug, error, and warning logs from attachment handling, image processing, media loading, and profile management functionalities. Additionally, a script has been added to automate the removal of log statements from Kotlin files.

This commit is contained in:
2026-01-31 05:20:32 +05:00
parent 430c7d9007
commit c249278421
28 changed files with 0 additions and 506 deletions

View File

@@ -1,7 +1,6 @@
package com.rosetta.messenger.utils
import android.content.Context
import android.util.Log
import com.rosetta.messenger.crypto.CryptoManager
import java.io.File
import java.security.MessageDigest
@@ -53,12 +52,10 @@ object AttachmentFileManager {
): Boolean {
return try {
if (blob.isEmpty()) {
Log.w(TAG, "💾 Empty blob, skipping save")
return false
}
val filePath = generatePath(attachmentId, publicKey)
Log.d(TAG, "💾 Saving attachment: $attachmentId -> $filePath")
// Шифруем данные приватным ключом (как в desktop)
val encrypted = CryptoManager.encryptWithPassword(blob, privateKey)
@@ -73,7 +70,6 @@ object AttachmentFileManager {
subDir.mkdirs()
val file = File(subDir, parts[1])
file.writeText(encrypted)
Log.d(TAG, "💾 Saved to: ${file.absolutePath} (${encrypted.length} bytes)")
} else {
val file = File(dir, filePath)
file.writeText(encrypted)
@@ -81,7 +77,6 @@ object AttachmentFileManager {
true
} catch (e: Exception) {
Log.e(TAG, "❌ Error saving attachment", e)
false
}
}
@@ -106,17 +101,14 @@ object AttachmentFileManager {
val file = File(dir, filePath)
if (!file.exists()) {
Log.d(TAG, "📖 File not found: $filePath")
return null
}
val encrypted = file.readText()
val decrypted = CryptoManager.decryptWithPassword(encrypted, privateKey)
Log.d(TAG, "📖 Read attachment: $attachmentId (${decrypted?.length ?: 0} bytes)")
decrypted
} catch (e: Exception) {
Log.e(TAG, "❌ Error reading attachment", e)
null
}
}
@@ -153,7 +145,6 @@ object AttachmentFileManager {
true
}
} catch (e: Exception) {
Log.e(TAG, "❌ Error deleting attachment", e)
false
}
}
@@ -165,10 +156,8 @@ object AttachmentFileManager {
return try {
val dir = File(context.filesDir, ATTACHMENTS_DIR)
dir.deleteRecursively()
Log.d(TAG, "🗑️ Cache cleared")
true
} catch (e: Exception) {
Log.e(TAG, "❌ Error clearing cache", e)
false
}
}

View File

@@ -36,23 +36,16 @@ object AvatarFileManager {
* @return Путь к файлу (формат: "a/md5hash")
*/
fun saveAvatar(context: Context, base64Image: String, entityId: String): String {
android.util.Log.d("AvatarFileManager", "💾 saveAvatar called")
android.util.Log.d("AvatarFileManager", "📊 Base64 length: ${base64Image.length}")
android.util.Log.d("AvatarFileManager", "👤 Entity ID: ${entityId.take(16)}...")
// Генерируем путь как в desktop версии
val filePath = generateMd5Path(base64Image, entityId)
android.util.Log.d("AvatarFileManager", "🔗 Generated file path: $filePath")
// Шифруем данные с паролем "rosetta-a"
android.util.Log.d("AvatarFileManager", "🔐 Encrypting with password...")
val encrypted = CryptoManager.encryptWithPassword(base64Image, AVATAR_PASSWORD)
android.util.Log.d("AvatarFileManager", "✅ Encrypted length: ${encrypted.length}")
// Сохраняем в файловую систему
val dir = File(context.filesDir, AVATAR_DIR)
dir.mkdirs()
android.util.Log.d("AvatarFileManager", "📁 Base dir: ${dir.absolutePath}")
// Путь формата "a/md5hash" -> создаем подпапку "a"
val parts = filePath.split("/")
@@ -61,14 +54,11 @@ object AvatarFileManager {
subDir.mkdirs()
val file = File(subDir, parts[1])
file.writeText(encrypted)
android.util.Log.d("AvatarFileManager", "💾 Saved to: ${file.absolutePath}")
} else {
val file = File(dir, filePath)
file.writeText(encrypted)
android.util.Log.d("AvatarFileManager", "💾 Saved to: ${file.absolutePath}")
}
android.util.Log.d("AvatarFileManager", "✅ Avatar saved successfully")
return filePath
}
@@ -163,7 +153,6 @@ object AvatarFileManager {
subDir.mkdirs()
val file = File(subDir, parts[1])
file.writeText(encrypted)
android.util.Log.d("AvatarFileManager", "💾 Avatar saved to: ${file.absolutePath}")
}
return path
@@ -232,19 +221,14 @@ object AvatarFileManager {
return try {
// Check for data URI prefix
val actualBase64 = if (base64.contains(",")) {
android.util.Log.d("AvatarFileManager", "🔍 Removing data URI prefix, orig len=${base64.length}")
base64.substringAfter(",")
} else {
base64
}
android.util.Log.d("AvatarFileManager", "🔍 Decoding base64, len=${actualBase64.length}, prefix=${actualBase64.take(50)}")
val imageBytes = Base64.decode(actualBase64, Base64.NO_WRAP)
android.util.Log.d("AvatarFileManager", "🔍 Decoded bytes=${imageBytes.size}")
val bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
android.util.Log.d("AvatarFileManager", "🔍 Bitmap result=${bitmap != null}, size=${bitmap?.width}x${bitmap?.height}")
bitmap
} catch (e: Exception) {
android.util.Log.e("AvatarFileManager", "❌ base64ToBitmap error: ${e.message}")
null
}
}

View File

@@ -2,7 +2,6 @@ package com.rosetta.messenger.utils
import android.content.Context
import android.os.Build
import android.util.Log
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
@@ -34,7 +33,6 @@ class CrashReportManager private constructor(private val context: Context) : Thr
if (INSTANCE == null) {
INSTANCE = CrashReportManager(context.applicationContext)
Thread.setDefaultUncaughtExceptionHandler(INSTANCE)
Log.d(TAG, "Crash reporter initialized")
}
}
}
@@ -87,7 +85,6 @@ class CrashReportManager private constructor(private val context: Context) : Thr
try {
saveCrashReport(thread, throwable)
} catch (e: Exception) {
Log.e(TAG, "Error saving crash report", e)
}
// Вызываем дефолтный handler (чтобы система тоже обработала краш)
@@ -111,7 +108,6 @@ class CrashReportManager private constructor(private val context: Context) : Thr
val report = buildCrashReport(thread, throwable)
crashFile.writeText(report)
Log.d(TAG, "Crash report saved: $fileName")
// Удаляем старые файлы если их слишком много
cleanupOldCrashFiles(crashDir)
@@ -199,7 +195,6 @@ class CrashReportManager private constructor(private val context: Context) : Thr
if (files.size > MAX_CRASH_FILES) {
files.drop(MAX_CRASH_FILES).forEach { file ->
file.delete()
Log.d(TAG, "Deleted old crash file: ${file.name}")
}
}
}

View File

@@ -5,7 +5,6 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.util.Base64
import android.util.Log
import com.vanniktech.blurhash.BlurHash
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@@ -33,7 +32,6 @@ object MediaUtils {
*/
suspend fun uriToBase64Image(context: Context, uri: Uri): String? = withContext(Dispatchers.IO) {
try {
Log.d(TAG, "📸 Converting image to Base64: $uri")
// Открываем InputStream
val inputStream: InputStream = context.contentResolver.openInputStream(uri)
@@ -44,11 +42,9 @@ object MediaUtils {
inputStream.close()
if (originalBitmap == null) {
Log.e(TAG, "📸 Failed to decode image")
return@withContext null
}
Log.d(TAG, "📸 Original size: ${originalBitmap.width}x${originalBitmap.height}")
// Масштабируем если слишком большое
val scaledBitmap = scaleDownBitmap(originalBitmap, MAX_IMAGE_SIZE)
@@ -56,7 +52,6 @@ object MediaUtils {
originalBitmap.recycle()
}
Log.d(TAG, "📸 Scaled size: ${scaledBitmap.width}x${scaledBitmap.height}")
// Конвертируем в PNG Base64
val outputStream = ByteArrayOutputStream()
@@ -67,10 +62,8 @@ object MediaUtils {
scaledBitmap.recycle()
Log.d(TAG, "📸 ✅ Image converted to Base64, length: ${base64.length}")
base64
} catch (e: Exception) {
Log.e(TAG, "📸 ❌ Failed to convert image to Base64", e)
null
}
}
@@ -80,7 +73,6 @@ object MediaUtils {
*/
suspend fun generateBlurhash(context: Context, uri: Uri): String = withContext(Dispatchers.IO) {
try {
Log.d(TAG, "🎨 Generating blurhash for: $uri")
val inputStream = context.contentResolver.openInputStream(uri)
?: return@withContext ""
@@ -93,7 +85,6 @@ object MediaUtils {
inputStream.close()
if (bitmap == null) {
Log.e(TAG, "🎨 Failed to decode image for blurhash")
return@withContext ""
}
@@ -101,10 +92,8 @@ object MediaUtils {
val blurhash = BlurHash.encode(bitmap, 4, 3)
bitmap.recycle()
Log.d(TAG, "🎨 ✅ Blurhash generated: $blurhash")
blurhash ?: ""
} catch (e: Exception) {
Log.e(TAG, "🎨 ❌ Failed to generate blurhash", e)
""
}
}
@@ -114,7 +103,6 @@ object MediaUtils {
*/
suspend fun uriToBase64File(context: Context, uri: Uri): String? = withContext(Dispatchers.IO) {
try {
Log.d(TAG, "📄 Converting file to Base64: $uri")
val inputStream = context.contentResolver.openInputStream(uri)
?: return@withContext null
@@ -124,10 +112,8 @@ object MediaUtils {
val base64 = Base64.encodeToString(bytes, Base64.NO_WRAP)
Log.d(TAG, "📄 ✅ File converted to Base64, length: ${base64.length}")
base64
} catch (e: Exception) {
Log.e(TAG, "📄 ❌ Failed to convert file to Base64", e)
null
}
}
@@ -158,7 +144,6 @@ object MediaUtils {
}
}
} catch (e: Exception) {
Log.e(TAG, "Failed to get file name", e)
}
return name
}
@@ -212,7 +197,6 @@ object MediaUtils {
}
hash ?: ""
} catch (e: Exception) {
Log.e(TAG, "Failed to generate blurhash from bitmap", e)
""
}
}
@@ -244,10 +228,8 @@ object MediaUtils {
}
}
Log.d(TAG, "📐 Image dimensions: ${width}x${height}")
Pair(width, height)
} catch (e: Exception) {
Log.e(TAG, "📐 Failed to get image dimensions", e)
Pair(0, 0)
}
}
@@ -270,10 +252,8 @@ object MediaUtils {
}
BitmapFactory.decodeByteArray(bytes, 0, bytes.size, options)
Log.d(TAG, "📐 Image dimensions from base64: ${options.outWidth}x${options.outHeight}")
Pair(options.outWidth, options.outHeight)
} catch (e: Exception) {
Log.e(TAG, "📐 Failed to get image dimensions from base64", e)
Pair(0, 0)
}
}