0

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 t.c.

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?

Carlos
  • 349
  • 1
  • 3
  • 17

2 Answers2

3

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).

Community
  • 1
  • 1
Halim Qarroum
  • 13,985
  • 4
  • 46
  • 71
  • 1
    Note that `MODE_PRIVATE` is the default, so simply using internal storage (whether via `openFileInput()` or `getFilesDir()`) should be sufficient. – CommonsWare Apr 03 '13 at 13:41
  • Yes this is right. Although it is set by default , it's always safe to set it anyway to ensure compatibility with further versions. – Halim Qarroum Apr 03 '13 at 13:42
  • As I understand it, the internal storage is in the phone memory. If so, a media content will spam all this memory rather quickly. And finally user won't be able to install new applications or simply receive sms. – Carlos Apr 03 '13 at 14:46
0

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.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • "and internal storage on most devices is very limited" -- not since Android 3.0, which means at this point a majority of devices have as much space for internal storage as external storage. – CommonsWare Apr 03 '13 at 13:41
  • @CommonsWare Huh. Don't think I've come across that change. Do you have a link to a changelog? Or is it mentioned in the CTS? I still see many (new, released within ~6 months) devices with small internal storage. – Raghav Sood Apr 03 '13 at 13:43
  • "I still see many (new, released within ~6 months) devices with small internal storage." -- the change in Android 3.0 was to switch from USB Mass Storage Mode to MTP for USB connections. This allowed them to have external storage and internal storage be on the same partition, just as separate directories (USB Mass Storage Mode required a dedicated FAT32 partition). I have never seen an Android 3.0+ device using dedicated partitions for internal vs. external storage. Manufacturers that continue to use dedicated partitions have some explaining to do. – CommonsWare Apr 03 '13 at 13:57
  • If you could name some devices that you see that have less internal storage than external storage, I can do some more research. – CommonsWare Apr 03 '13 at 13:57
  • @CommonsWare Ah yes. That change I'm well aware of. You even did a guest post for my site on it :P I don't remember the names of the top of my head, but my friends have a couple of those. I'll get back to you with the device names. – Raghav Sood Apr 03 '13 at 13:58
  • Yeah, drop me an email or chime back in here or something if you come across devices that have this limitation. I assumed, perhaps incorrectly, that all manufacturers would use the single partition, as I would expect that to be easier, let alone more flexible for the users. If some are not, that's good information to publicize. – CommonsWare Apr 03 '13 at 14:08