Skip to content

Conversation

@khyativyasargus
Copy link
Collaborator

Handled recapture case when we reopen media capture form for an existing patient without submitting the previous form - fixes for UNIQUE constraint failure exception in such case

For Example :

android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: CaptureInfoEntity.captureFolder (code 2067 SQLITE_CONSTRAINT_UNIQUE[2067]) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:1293) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:89) at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.kt:42) at androidx.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.kt:52) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl$3.call(CaptureInfoDao_Impl.java:106) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl$3.call(CaptureInfoDao_Impl.java:101) at androidx.room.CoroutinesRoom$Companion.execute(CoroutinesRoom.kt:57) at androidx.room.CoroutinesRoom.execute(Unknown Source:2) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl.insertCaptureInfoEntity(CaptureInfoDao_Impl.java:101) at com.google.android.sensing.db.impl.dao.CaptureInfoDao.insertCaptureInfo$suspendImpl(CaptureInfoDao.kt:36) at com.google.android.sensing.db.impl.dao.CaptureInfoDao.insertCaptureInfo(Unknown Source:0) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl.access$601(CaptureInfoDao_Impl.java:36) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl.lambda$insertCaptureInfo$0$com-google-android-sensing-db-impl-dao-CaptureInfoDao_Impl(CaptureInfoDao_Impl.java:119) at com.google.android.sensing.db.impl.dao.CaptureInfoDao_Impl$$ExternalSyntheticLambda0.invoke(Unknown Source:6) at androidx.room.RoomDatabaseKt$withTransaction$transactionBlock$1.invokeSuspend(RoomDatabaseExt.kt:56) at androidx.room.RoomDatabaseKt$withTransaction$transactionBlock$1.invoke(Unknown Source:8) at androidx.room.RoomDatabaseKt$withTransaction$transactionBlock$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at androidx.room.RoomDatabaseKt$startTransactionCoroutine$2$1$1.invokeSuspend(RoomDatabaseExt.kt:97) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59) at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1) at androidx.room.RoomDatabaseKt$startTransactionCoroutine$2$1.run(RoomDatabaseExt.kt:93) at androidx.room.TransactionExecutor.execute$lambda$1$lambda$0(TransactionExecutor.kt:36) at androidx.room.TransactionExecutor.$r8$lambda$AympDHYBb78s7_N_9gRsXF0sHiw(Unknown Source:0) at androidx.room.TransactionExecutor$$ExternalSyntheticLambda0.run(Unknown Source:4) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@29afe57, Dispatchers.IO]

… patient without submitting previous form - fixes for UNIQUE constraint failure exception in such case
Copy link
Collaborator

@chandrashekar-s chandrashekar-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes @khyativyasargus. In general, the changes looks fine. There are a couple of questions, can you please have a look.

// delete Participant's folder if there are no data
if (parentFile?.list()?.isEmpty() == true) {
parentFile.delete()
if (isRecapture) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is the data deleted under the folders only in case of recapture?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in case of recapture , captured media is being stored at cacheDir, else at filesDir. so only in case of recapture we have to delete folders at filesDir.
Reference : in CaptureViewModel.kt ->
private val internalStorageFolder: File
get() =
if (captureInfo.recapture == true) getApplication().cacheDir
else getApplication().filesDir

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, can you please verify if the FilesDir is not containing the older entries as well that are captured with previous try.

return deleted
}
return deleted
return false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What does this return flag signify?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no return flag is required as we are not processing anything further based on delete success flag so can eliminate it by changing return type of that method,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for the clarification, Please go ahead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants