Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to sentrylog #1037

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/src/main/java/com/infomaniak/drive/data/api/UploadTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.infomaniak.drive.data.api

import android.content.Context
import android.net.Uri
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.work.workDataOf
Expand All @@ -41,6 +40,7 @@ import com.infomaniak.lib.core.api.ApiController.gson
import com.infomaniak.lib.core.models.ApiError
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.networking.HttpUtils
import com.infomaniak.lib.core.utils.SentryLog
import io.sentry.Breadcrumb
import io.sentry.Sentry
import io.sentry.SentryLevel
Expand Down Expand Up @@ -147,21 +147,21 @@ class UploadTask(
level = SentryLevel.INFO
})

Log.d("kDrive", " upload task started with total chunk: $totalChunks, valid: $uploadedChunks")
SentryLog.d("kDrive", " upload task started with total chunk: $totalChunks, valid: $uploadedChunks")

val validChunksIds = uploadedChunks?.validChunksIds
previousChunkBytesWritten = uploadedChunks?.uploadedSize ?: 0

for (chunkNumber in 1..totalChunks) {
requestSemaphore.acquire()
if (validChunksIds?.contains(chunkNumber) == true && !isNewUploadSession) {
Log.d("kDrive", "chunk:$chunkNumber ignored")
SentryLog.d("kDrive", "chunk:$chunkNumber ignored")
input.skip(chunkSize.toLong())
requestSemaphore.release()
continue
}

Log.i("kDrive", "Upload > ${uploadFile.fileName} chunk:$chunkNumber has permission")
SentryLog.i("kDrive", "Upload > ${uploadFile.fileName} chunk:$chunkNumber has permission")
var data = ByteArray(chunkSize)
val count = input.read(data, 0, chunkSize)
if (count == -1) {
Expand All @@ -172,7 +172,7 @@ class UploadTask(
data = if (count == chunkSize) data else data.copyOf(count)

val url = uploadFile.uploadUrl(chunkNumber = chunkNumber, currentChunkSize = count)
Log.d("kDrive", "Upload > Start upload ${uploadFile.fileName} to $url data size:${data.size}")
SentryLog.d("kDrive", "Upload > Start upload ${uploadFile.fileName} to $url data size:${data.size}")

waitingCoroutines.add(
coroutineScope.uploadChunkRequest(requestSemaphore, data.toRequestBody(), url)
Expand Down Expand Up @@ -268,7 +268,7 @@ class UploadTask(
private fun manageApiResponse(response: Response) {
response.use {
val bodyResponse = it.body?.string()
Log.i("UploadTask", "response successful ${it.isSuccessful}")
SentryLog.i("UploadTask", "response successful ${it.isSuccessful}")
if (!it.isSuccessful) {
notificationManagerCompat.cancel(CURRENT_UPLOAD_ID)
val apiResponse = try {
Expand Down Expand Up @@ -298,7 +298,7 @@ class UploadTask(
scope.setExtra("chunk size", "$chunkSize")
Sentry.captureMessage("Chunk total size exceed fileSize 😢")
}
Log.d(
SentryLog.d(
"UploadWorker",
"progress >> ${uploadFile.fileName} exceed with ${uploadFile.fileSize}/${previousChunkBytesWritten}"
)
Expand All @@ -325,7 +325,7 @@ class UploadTask(
launch { shareProgress(currentProgress) }
}

Log.i(
SentryLog.i(
"kDrive",
" upload >> ${currentProgress}%, totalBytesWritten:$totalBytesWritten, fileSize:${uploadFile.fileSize}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ class FileMigration : RealmMigration {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return true
return javaClass == other?.javaClass
}

override fun hashCode(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.os.*
import android.provider.DocumentsContract
import android.provider.DocumentsProvider
import android.provider.Settings
import android.util.Log
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri
import androidx.core.os.bundleOf
Expand All @@ -53,6 +52,7 @@ import com.infomaniak.drive.utils.isPositive
import com.infomaniak.lib.core.api.ApiController
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.utils.NotificationUtilsCore
import com.infomaniak.lib.core.utils.SentryLog
import io.realm.Realm
import io.sentry.Sentry
import io.sentry.SentryLevel
Expand All @@ -71,7 +71,7 @@ class CloudStorageProvider : DocumentsProvider() {
private lateinit var cacheDir: java.io.File

override fun onCreate(): Boolean {
Log.d(TAG, "onCreate")
SentryLog.d(TAG, "onCreate")

var result = false
runBlocking {
Expand All @@ -85,7 +85,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun queryRoots(projection: Array<out String>?): Cursor {
Log.d(TAG, "queryRoots")
SentryLog.d(TAG, "queryRoots")
val cursor = MatrixCursor(projection ?: DEFAULT_ROOT_PROJECTION)

AccountUtils.getAllUsersSync().forEach { user ->
Expand All @@ -102,7 +102,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun queryDocument(documentId: String, projection: Array<out String>?): Cursor {
Log.d(TAG, "queryDocument(), documentId=$documentId")
SentryLog.d(TAG, "queryDocument(), documentId=$documentId")

return MatrixCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION).apply {
val userId = getUserId(documentId)
Expand Down Expand Up @@ -139,15 +139,15 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun queryChildDocuments(parentDocumentId: String, projection: Array<out String>?, sortOrder: String?): Cursor {
Log.d(TAG, "queryChildDocuments(), parentDocumentId=$parentDocumentId, sort=$sortOrder")
SentryLog.d(TAG, "queryChildDocuments(), parentDocumentId=$parentDocumentId, sort=$sortOrder")

val cursor = DocumentCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION)

val uri = DocumentCursor.createUri(context, parentDocumentId)
val isNewJob = uri != oldQueryChildUri || needRefresh
val isLoading = uri == oldQueryChildUri && oldQueryChildCursor?.job?.isCompleted == false || isNewJob

Log.i(TAG, "queryChildDocuments(), isLoading=$isLoading, isNew=$isNewJob")
SentryLog.i(TAG, "queryChildDocuments(), isLoading=$isLoading, isNew=$isNewJob")

cursor.extras = bundleOf(DocumentsContract.EXTRA_LOADING to isLoading)
cursor.setNotificationUri(context?.contentResolver, uri)
Expand Down Expand Up @@ -230,7 +230,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun openDocument(documentId: String, mode: String, signal: CancellationSignal?): ParcelFileDescriptor? {
Log.d(TAG, "openDocument(), id=$documentId, mode=$mode, signalIsCancelled: ${signal?.isCanceled}")
SentryLog.d(TAG, "openDocument(), id=$documentId, mode=$mode, signalIsCancelled: ${signal?.isCanceled}")
val context = context ?: return null

val isWrite = mode.indexOf('w') != -1
Expand All @@ -249,7 +249,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun querySearchDocuments(rootId: String, query: String, projection: Array<out String>?): Cursor {
Log.d(TAG, "querySearchDocuments(), rootId=$rootId, query=$query, projection=$projection, $currentParentDocumentId")
SentryLog.d(TAG, "querySearchDocuments(), rootId=$rootId, query=$query, projection=$projection, $currentParentDocumentId")

val cursor = DocumentCursor(projection ?: DEFAULT_DOCUMENT_PROJECTION)

Expand Down Expand Up @@ -296,7 +296,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun openDocumentThumbnail(documentId: String, sizeHint: Point?, signal: CancellationSignal?): AssetFileDescriptor {
Log.d(TAG, "openDocumentThumbnail(), id=$documentId, signalIsCancelled: ${signal?.isCanceled}")
SentryLog.d(TAG, "openDocumentThumbnail(), id=$documentId, signalIsCancelled: ${signal?.isCanceled}")

val fileId = getFileIdFromDocumentId(documentId)
val userId = getUserId(documentId)
Expand Down Expand Up @@ -344,7 +344,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun createDocument(parentDocumentId: String, mimeType: String, displayName: String): String {
Log.d(TAG, "createDocument(), parentId=$parentDocumentId, mimeType=$mimeType, name=$displayName")
SentryLog.d(TAG, "createDocument(), parentId=$parentDocumentId, mimeType=$mimeType, name=$displayName")

return if (mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR, true)) {
createNewFolder(parentDocumentId, displayName) // If we want to create a new folder
Expand All @@ -354,7 +354,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun deleteDocument(documentId: String) {
Log.d(TAG, "deleteDocument(), id=$documentId")
SentryLog.d(TAG, "deleteDocument(), id=$documentId")

val context = context ?: throw IllegalStateException("Delete document failed: missing Android Context")

Expand All @@ -380,7 +380,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun renameDocument(documentId: String, displayName: String): String? {
Log.d(TAG, "renameDocument(), id=$documentId, name=$displayName")
SentryLog.d(TAG, "renameDocument(), id=$documentId, name=$displayName")

FileController.getRealmInstance(createUserDrive(documentId)).use { realm ->
FileController.getFileProxyById(getFileIdFromDocumentId(documentId), customRealm = realm)?.let { file ->
Expand All @@ -402,7 +402,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun copyDocument(sourceDocumentId: String, targetParentDocumentId: String): String {
Log.d(TAG, "copyDocument(), sourceId=$sourceDocumentId, targetParentId=$targetParentDocumentId")
SentryLog.d(TAG, "copyDocument(), sourceId=$sourceDocumentId, targetParentId=$targetParentDocumentId")

return FileController.getRealmInstance(createUserDrive(sourceDocumentId)).use { realm ->

Expand All @@ -427,7 +427,7 @@ class CloudStorageProvider : DocumentsProvider() {
}

override fun moveDocument(sourceDocumentId: String, sourceParentDocumentId: String, targetParentDocumentId: String): String {
Log.d(
SentryLog.d(
TAG, "moveDocument(), " +
"sourceId=$sourceDocumentId, " +
"sourceParentId=$sourceParentDocumentId, " +
Expand Down Expand Up @@ -572,7 +572,7 @@ class CloudStorageProvider : DocumentsProvider() {
fileUrl = ApiRoutes.downloadFile(file),
okHttpClient = okHttpClient
) { progress ->
Log.i(TAG, "open currentProgress: $progress")
SentryLog.i(TAG, "open currentProgress: $progress")
}

if (response.isSuccessful) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.infomaniak.drive.data.services
import android.content.Context
import android.content.Intent
import android.os.ParcelFileDescriptor.AutoCloseOutputStream
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
Expand All @@ -43,6 +42,7 @@ import com.infomaniak.lib.core.api.ApiController
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.networking.HttpClient
import com.infomaniak.lib.core.networking.HttpUtils
import com.infomaniak.lib.core.utils.SentryLog
import io.sentry.Sentry
import kotlinx.coroutines.*
import okhttp3.Interceptor
Expand Down Expand Up @@ -135,7 +135,7 @@ class DownloadWorker(context: Context, workerParams: WorkerParameters) : Corouti
launch(Dispatchers.Main) {
setProgress(workDataOf(PROGRESS to progress, FILE_ID to file.id))
}
Log.d(TAG, "download $progress%")
SentryLog.d(TAG, "download $progress%")
downloadNotification.apply {
setContentText("$progress%")
setProgress(100, progress, false)
Expand Down Expand Up @@ -218,7 +218,7 @@ class DownloadWorker(context: Context, workerParams: WorkerParameters) : Corouti
outputStream: AutoCloseOutputStream? = null,
onFinish: (() -> Unit)? = null
) {
Log.d(TAG, "save remote data to ${outputFile?.path}")
SentryLog.d(TAG, "save remote data to ${outputFile?.path}")
BufferedInputStream(response.body?.byteStream()).use { input ->
val stream = outputStream ?: outputFile?.outputStream()
stream?.use { output ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package com.infomaniak.drive.data.services

import android.content.Context
import android.os.CountDownTimer
import android.util.Log
import androidx.lifecycle.LiveData
import com.infomaniak.drive.data.models.IpsToken
import com.infomaniak.drive.data.models.MqttAction
import com.infomaniak.drive.data.models.MqttNotification
import com.infomaniak.drive.utils.BulkOperationsUtils.isBulkOperationActive
import com.infomaniak.drive.utils.isPositive
import com.infomaniak.lib.core.api.ApiController.gson
import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.core.utils.Utils
import info.mqtt.android.service.MqttAndroidClient
import org.eclipse.paho.client.mqttv3.*
Expand Down Expand Up @@ -88,7 +88,7 @@ object MqttClientWrapper : MqttCallback, LiveData<MqttNotification>() {
try {
client.connect(options, null, object : IMqttActionListener {
override fun onSuccess(asyncActionToken: IMqttToken?) {
Log.i("MQTT connection", "Success : true")
SentryLog.i("MQTT connection", "Success : true")
currentToken?.let {
subscribe(topicFor(it))
completion()
Expand All @@ -108,7 +108,7 @@ object MqttClientWrapper : MqttCallback, LiveData<MqttNotification>() {

override fun onFailure(asyncActionToken: IMqttToken?, exception: Throwable?) {
exception?.printStackTrace()
Log.i("MQTT connection", "Success : false")
SentryLog.i("MQTT connection", "Success : false")
}

})
Expand All @@ -133,7 +133,7 @@ object MqttClientWrapper : MqttCallback, LiveData<MqttNotification>() {
}

override fun connectionLost(cause: Throwable?) {
Log.e("MQTT Error", "Connection has been lost. Stacktrace below.")
SentryLog.e("MQTT Error", "Connection has been lost. Stacktrace below.")
cause?.printStackTrace()
}

Expand Down
Loading