How to securely delete DB on Android? - android

My app uses SQLite DB in Android to keep some logs. I understand this is saved in my app dir on Android as DBName.db. I need a way to truncate/delete/damage/empty the database so it is unrecoverable.
What is the best approach?
Does Android keep some shadow copies on the device?
Does Android keep synced backup in cloud by default (like settings are kept)?
If the app is running, is the whole db cached in RAM? If so, id like to clean that too.
Thanks :)

To overwrite all data, enable the secure_delete option, and DELETE FROM all your tables.
Android does not make copies of (database) files unless you explicitly configure it to do so.
There is a RAM cache.
The only safe way to clear it is to exit your own process.

Related

Preserving SQLite db data on App Update/Reinstall Rollout Xamarin

I have Xamarin.Forms shared project that I am testing on Android phone currently.
The sqlite db is stored in System.Environment.SpecialFolder.Personal as of now.
I want to make sure that user input data stored in db is preserved:
1 upon each next upgrade I am planning for an app, as well as
2 In additional situation where user removes his app totally and makes a fresh install
(I guess these are two totally different situations, but I might be wrong)
I would like to know whether an update of an App via Google Play Store Update will overwrite db file too, therefore all data be lost? Or will the data be preserved?
What would be the option if a user wanted to preserve his/her data even after an app Uninstall/Reinstall?
In second case, I am considering manual/automatic backup of SpecialFolder.Personal db version in use and storing it as a separate file outside of the package using External_STORAGE permissions.
Then the user will be able to Import data from external db file copy into the one that comes in the package.
Also, how should the Import look like?
Can I simply replace the file with external one?
Any advice on this topic will be very appreciated.
An update from Google Play will not overwrite the db file
If a user uninstalls the application, he will want to delete everything related with the application. So my best solution is to have a synchronize method within your API so that, when the user installs again the application, it will fill the local DB with the requested data.

How to alert users on new update to local database?

I'd like to receive some advice from all of you.
What is the best way for me to alert users on an update to my app? My app is a very knowledge-based & it works like a dictionary, so there will always be updates to it.
The database I have used is by DB Browser for SQLite, and they are all local database where it is uploaded into the assets folder in Android Studio.
Currently, the limitations are that:
1) it's obviously not real-time because it's stored locally;
2) every update I make to the database structure, I am required to upload the new database into the assets folder again, followed by uninstalling the old app on my phone, then run the app to install in my phone again so that the new database is overwritten.
I have read (How can I regularly update a database of content on an Android app?) & some others, and it seemed like I have to have a server, a cloud-based database & live app in market, to solve the limitations?
Is there really no way for me to overcome the limitations if I want to stick to a local database? At the same time, I kinda wish to avoid setting up a server because I am not intending to make the app live on market, and also this is just a school project I am working on and as such, I have very limited skill sets & knowledge about it and would like to make it on a school-project-based level.
Thanks in advance.
One way to do it is to connect to your local DB through local network instead of assets folder. Therefore, you can update the information by querying the local DB.
As for syncing the information between DB and your application, you should create a trigger or watcher that notify your application when the DB is updated. Therefore, your application can know when to query the DB for the updates. Another way is to just query the database periodically.
Bonus: you could move your database to a cloud-based database. Usually there are several providers that provide free database hosting up to a certain size, which should be enough for your project.

Under what circumstance will the SQLite database file got lost or destroyed?

I know that one instance where an App's SQLite file may be removed from the System is when the user uninstall the Application. Apart from this situation, under what circumstance(s) will the SQLite file get lost or be destroyed in the Android System?
Again, under what circumstance will the SQLite database file loose all it's content even if the App is not uninstalled?
Will there be an instance where the Android System does this?
Settings -> App -> Data -> Clear Data would also delete the SQL. Also rooted phone can do whatever he likes with the SQLite files.
There is no way that the Android system will erase or remove your file. Database files are stored, along with other app data, under {package_name}/data/data folder so no one except your app can touch it (ignore rooted devices).
Only the following can happen:
1. your code cleared/corrupted the db file
2. user has cleared app data from device settings

How to properly backup a database in case a user reinstalls or switches devices (Android)

My app tracks school grades, calculates averages, etc. and stores all of this in a SQLite database. If a user has to reinstall or gets a new phone, I'd like to be able to restore their data.
It looks like most developers do this either by backing up to SD card or by using Android Backup Service through Google. I'm not sure which is the better method. I'd like restoring to be simple but reliable. I welcome any comments on this.
One thing I'm trying to understand is why Google says to extend BackupAgent instead of BackupAgentHelper if using a database.
If you have an SQLite database that you want to restore when the user re-installs your application, you need to build a custom BackupAgent that reads the appropriate data during a backup operation, then create your table and insert the data during a restore operation.
Why can't I just back up the database as a file and then restore the file? My SQLiteOpenHelper class already handles upgrades if db versions are different. I guess I could just abort on a downgrade.
Why can't I just back up the database as a file and then restore the
file? My SQLiteOpenHelper class already handles upgrades if db
versions are different. I guess I could just abort on a downgrade.
Reason: same database file may not work on different device models(even though most of the cases, it should work, there are cases where it will fail). It depends on parameters like page size etc set at sqlite engine level. Ideal way is to backup the data rather than copying the whole file
It's suggested that you avoid backing up the whole db file all the time mostly because that's a lot of redundant data traffic, especially if you've only changed one record in a large db. Being able to write per-record updates to the backup system is much more efficient (though of course is not nearly as simple to implement).

Android updating a database

I there a way I can set up my app so that things like the database and images can be optionally downloaded/updated when when I make changes to the data, without updating the app. i.e. a kind of syncing with the new data?
I would have the database and images on my server and the user can update or not without having an icon on their phone saying there are updates available.
As far as I know, Android databases are just sqlite.db files. You should be able to have a button in your app that downloads a new sqlite.db file from your server. Have it replace the file that is already on the device and you should be good to go!
If you have a localized database you can modify, add to, and delete as needed based on server response. Create a robust enough Database Helper and you can use it to make the database whatever is needed, in a run time environment.

Categories

Resources