简体   繁体   中英

How to limit access to files on my android device?

The idea is that.

My application allows user to listen to music and watch videos from the social network. User can save these files in cache to be able to play them offline. This data is saved to SD-card and can be accessed by file managers e tc

I want to limit access to these files to other application. The most obvious solution is data encryption.

Can you please recommend me some libraries or frameworks for quick file encryption/decription? It is very desirable to encrypt files "on the fly" during the are loading.

Would this procedure be too slow and resource intensive?

May be there exist some other ways - protected folder in the SD filesystem or something like that?

Yes there is a more standard way to do this.

By using openFileInput on your Context and setting the MODE_PRIVATE flag, you will be able to create files and even folders within your application. Also, these resources will be completely private to your application.

EDIT :

Most of the time, these files will be stored in /data/data/<app_package_name>/files . That is, on the phone memory most of the time, although this is implementation specific.

Regarding the comment of @Carlos mentionning file spamming, yeah you can flood the NAND with multiple files, but /data will be in most cases mounted on a dedicated partition. So you'll be hitting the virtual size of the partition at some point. Please look at this post , the accepted answer gives more details about this. In fewer words, this is implementation specific (depends on the manufacturer).

Your only option would be to use Encryption, if you want to keep using the external storage. SpongyCastle can help with that. It is an android version of the BouncyCastle APIs.

Apart from that, you could move your files to the internal storage, which may not be feasible in your case as media files tend to be big, and internal storage on most devices is very limited. Even if you do move them to internal storage, any rooted user can access them (or any app with root privileges).

Protecting the folder isn't an option, as anything on the external storage is available to any app with permission to access the external storage. There is nothing you can do about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM