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

Crash after launch fixed #3508

Merged
merged 6 commits into from
Sep 20, 2024
Merged

Crash after launch fixed #3508

merged 6 commits into from
Sep 20, 2024

Conversation

Aleem92
Copy link
Contributor

@Aleem92 Aleem92 commented Sep 18, 2024

IMPORTANT: Where possible all PRs must be linked to a Github issue

Fixes [link to issue]

Engineer Checklist

  • I have written Unit tests for any new feature(s) and edge cases for bug fixes
  • I have added any strings visible on UI components to the strings.xml file
  • I have updated the CHANGELOG.md file for any notable changes to the codebase
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the project's style guide
  • I have built and run the FHIRCore app to verify my change fixes the issue and/or does not break the app
  • I have checked that this PR does NOT introduce breaking changes that require an update to Content and/or Configs? If it does add a sample here or a link to exactly what changes need to be made to the content.

Code Reviewer Checklist

  • I have verified Unit tests have been written for any new feature(s) and edge cases
  • I have verified any strings visible on UI components are in the strings.xml file
  • I have verifed the CHANGELOG.md file has any notable changes to the codebase
  • I have verified the solution has been implemented in a configurable and generic way for reuseable components
  • I have built and run the FHIRCore app to verify the change fixes the issue and/or does not break the app

@Aleem92 Aleem92 self-assigned this Sep 18, 2024
tools:ignore="UnusedAttribute,LockedOrientationActivity"
tools:replace="android:theme">
tools:replace="android:allowBackup,android:theme">
Copy link
Collaborator

Choose a reason for hiding this comment

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

We disallowed backup @Aleem92 for privacy & security reasons. This backup is stored in the Android logged-in user drive, compromising the confidentiality of the data collected via the app.

Copy link
Contributor Author

@Aleem92 Aleem92 Sep 18, 2024

Choose a reason for hiding this comment

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

We disallowed backup @Aleem92 for privacy & security reasons. This backup is stored in the Android logged-in user drive, compromising the confidentiality of the data collected via the app.

1- allowBackup="false" and fullBackupContent="false" are disabling the backup system entirely.

2- dataExtractionRules="@xml/data_extraction_rules" is pointing to the XML file that would prevent any data from being backed up or transferred. This is now the recommended way to control backups for newer Android versions.

3- tools:replace="android:allowBackup" does the following:

  • Overrides the android:allowBackup value from any libraries.
  • Ensures the currently mentioned android:allowBackup setting in the manifest takes priority.

@@ -55,7 +55,7 @@ class FhirEngineModule {
FhirEngineProvider.init(
FhirEngineConfiguration(
enableEncryptionIfSupported = !BuildConfig.DEBUG,
databaseErrorStrategy = DatabaseErrorStrategy.UNSPECIFIED,
databaseErrorStrategy = DatabaseErrorStrategy.RECREATE_AT_OPEN,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would be the implication for using this DatabaseErrorStrategy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would be the implication for using this DatabaseErrorStrategy?

The DatabaseErrorStrategy.RECREATE_AT_OPEN was implemented to solve a critical issue where the app crashes on startup after restoring a backup. The application is unable to read from the restored database due to this error:

FATAL EXCEPTION: main Process: org.smartregister.opensrp.eusm, PID: 18215 java.lang.RuntimeException: Unable to create application org.smartregister.fhircore.quest.QuestApplication: android.database.sqlite.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master; at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7003) at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8177) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) Caused by: android.database.sqlite.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master; at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method) at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:89) at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62) at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91) at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:50) at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60) at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2019) at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1905) at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2672) at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2602) at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1250) at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1325) at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:167) at com.google.android.fhir.db.impl.SQLCipherSupportHelper.getWritableDatabase(SQLCipherSupportHelper.kt:91) at com.google.android.fhir.db.impl.SQLCipherSupportHelper.<init>(SQLCipherSupportHelper.kt:122) at com.google.android.fhir.db.impl.SQLCipherSupportHelper.<init>(SQLCipherSupportHelper.kt:36) at com.google.android.fhir.db.impl.DatabaseImpl.lambda$2$lambda$1(DatabaseImpl.kt:97) at com.google.android.fhir.db.impl.DatabaseImpl$$ExternalSyntheticLambda0.create(D8$$SyntheticClass:0) at com.google.android.fhir.db.impl.ResourceDatabase_Impl.createOpenHelper(ResourceDatabase_Impl.java:378) at androidx.room.RoomDatabase.init(RoomDatabase.kt:186) at androidx.room.RoomDatabase$Builder.build(RoomDatabase.kt:1358) at com.google.android.fhir.db.impl.DatabaseImpl.<init>(DatabaseImpl.kt:116) at com.google.android.fhir.FhirServices$Builder.build(FhirServices.kt:83) at com.google.android.fhir.FhirEngineProvider.getOrCreateFhirService(FhirEngineProvider.kt:99) at com.google.android.fhir.FhirEngineProvider.getInstance(FhirEngineProvider.kt:63) at org.smartregister.fhircore.engine.di.FhirEngineModule.provideFhirEngine(FhirEngineModule.kt:82) at org.smartregister.fhircore.engine.di.FhirEngineModule_ProvideFhirEngineFactory.provideFhirEngine(FhirEngineModule_ProvideFhirEngineFactory.java:60) at org.smartregister.fhircore.quest.DaggerQuestApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get(DaggerQuestApplication_HiltComponents_SingletonC.java:1384) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) at org.smartregister.fhircore.quest.DaggerQuestApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get(DaggerQuestApplication_HiltComponents_SingletonC.java:1517) at dagger.internal.DoubleCheck.get(DoubleCheck.java:47) 2024-09-18 14:47:49.475 18215-18215 AndroidRuntime pid-18215 E at org.smartregister.fhircore.quest.DaggerQuestApplication_HiltComponents_SingletonC$SingletonCImpl.injectQuestApplication2(DaggerQuestApplication_HiltComponents_SingletonC.java:1347) at org.smartregister.fhircore.quest.DaggerQuestApplication_HiltComponents_SingletonC$SingletonCImpl.injectQuestApplication(DaggerQuestApplication_HiltComponents_SingletonC.java:1336) at org.smartregister.fhircore.quest.Hilt_QuestApplication.hiltInternalInject(Hilt_QuestApplication.java:52) at org.smartregister.fhircore.quest.Hilt_QuestApplication.onCreate(Hilt_QuestApplication.java:43) at org.smartregister.fhircore.quest.QuestApplication.onCreate(QuestApplication.kt:59) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6998) ... 9 more

This strategy ensures the app remains functional by resetting the database if it can't be read.

Copy link
Member

Choose a reason for hiding this comment

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

This strategy is NOT respected when opening a previously unencrypted database with an encrypted configuration or vice versa. An IllegalStateException is thrown instead.

Out of curiosity does the new version of the APK use the same encryption for the DB?

Copy link
Member

Choose a reason for hiding this comment

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

The PR fixes the problem at hanf. Good job on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity does the new version of the APK use the same encryption for the DB?

No changes were made to the encryption strategy in this PR.

Copy link
Member

@dubdabasoduba dubdabasoduba left a comment

Choose a reason for hiding this comment

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

@Aleem92 Just one comment then we can merge this

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 27.1%. Comparing base (2f8055b) to head (3530a33).
Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main   #3508     +/-   ##
=========================================
- Coverage     27.2%   27.1%   -0.1%     
- Complexity     749     753      +4     
=========================================
  Files          275     275             
  Lines        13940   13995     +55     
  Branches      2532    2545     +13     
=========================================
+ Hits          3794    3805     +11     
- Misses        9622    9664     +42     
- Partials       524     526      +2     
Flag Coverage Δ
engine 64.4% <100.0%> (+<0.1%) ⬆️
geowidget 11.5% <ø> (-1.1%) ⬇️
quest 5.5% <ø> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ter/fhircore/engine/util/SecureSharedPreference.kt 93.6% <100.0%> (+1.1%) ⬆️

... and 3 files with indirect coverage changes

dubdabasoduba
dubdabasoduba previously approved these changes Sep 20, 2024
@dubdabasoduba dubdabasoduba merged commit 041762f into main Sep 20, 2024
5 checks passed
@dubdabasoduba dubdabasoduba deleted the 3492-crash-after-launch branch September 20, 2024 12:19
asad-zaman pushed a commit that referenced this pull request Oct 16, 2024
* Crash after launch fixed

* Bump version

* reset version code

* Backup disabled

* Added the unit tests

---------

Co-authored-by: Benjamin Mwalimu <dubdabasoduba@gmail.com>
(cherry picked from commit 041762f)
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.

App force closes on launch after install. Clearing Data is a workaround
3 participants