Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect/detect database restore on Android device?

I have an app for Android, that saves data to sqlite database in a common way. As the user works with the application, the data is changed etc. So far no problem...

But when the user use some back-up software (like Titanium Backup or others), make a backup of the application, he can restore the data to old state. I need the way to protect application from this or to detect the restoration and handle it.

The simple workflow:

  1. Install APP
  2. Work with APP
  3. Reach the STATE1 of APP's database
  4. Back-up the APP (with any backup/restore application, the device can be rooted)
  5. Work with APP
  6. Reach the STATE2 of APP's database
  7. Restores the APP (or just data) to STATE1 - this is the point I need to deny or detect on the next execution of the APP.

So far I played with the Access-time detection and comparsion, but it seems to be really un-reliable through different devices and ROMs.

Thank you.

like image 219
Ejzy Avatar asked Jan 30 '26 17:01

Ejzy


1 Answers

To do this you need to save some state off the device, or at least outside of the data directory. The easiest way is probably to save the fingerprint of the DB file in some 'hidden' directory on external storage (SD card). Or if your app has Web login, etc. store the fingerprint for each user.

In any case, the user has full control over the device so you can't prevent this 100%. Your app needs to gracefully handle any changes in the DB or simply fail if it detects a fatal inconsistency.

like image 145
Nikolay Elenkov Avatar answered Feb 02 '26 06:02

Nikolay Elenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!