Is it possible that system remove data from ExternalCacheDir of application? - android

My Android app uses ExternalCacheDir to save some files downloaded from my server which are used to show to user inside app (images, videos etc.).
In Google Play Store there's 3 comments with low grade that says after turning off application or device files are no longer available in app. All 3 users/devices with Android 7.0. But I've tested app in few Android 7.0 phones and few with other versions and nothing like this happend. Also there are many high grades and other people doesn't have that problem.
Is it possible that system at some point removes them? E.g. in case of low disk (external storage) space?
I'm using ExternalCacheDir not just ExternalStorageDir to hide files a little bit from user (files are also saved with shadowed random names).

Is it possible that system at some point removes them?
Yes, where by "system" it could be the OS itself or, more likely, stuff added into the device by the manufacturer. Also, users can remove them and other apps can remove them.
I'm using ExternalCacheDir not just ExternalStorageDir to hide files a little bit from user (files are also saved with shadowed random names).
Anything on external storage is visible to the user and to other apps.
If you specifically do not want users to have access to the files, use internal storage.

Related

How to protect my app files being read/ write by other apps, in non-root device?

I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices
Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir
But, some of my users complain that, they are still able to see images in 3rd party gallery app.
I am not sure whether they are using root phone. So far, I cannot access my app getExternalFilesDir from Google Photo app.
Based on https://developer.android.com/training/data-storage, it seems that only getFilesDir will prevent other apps from accessing the files.
But, is it appropriate for an app to store user data file in getFilesDir? (My app is a note taking app which needs to store user attachment images, audio, ...)
From discussion of Android getExternalFilesDir vs getFilesDir() for big files , it seems like getFilesDir is not designed to store user data files?
I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices
Store your data in internal storage (mostly getFilesDir() and getCacheDir()).
Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir
The only reason to use that location is if you want the user to be able to use your content from outside of your app, whether via other apps or via an attached desktop computer.
In the long term, getExternalFilesDir() and getExternalCacheDir() will be off-limits to other apps — you will start seeing this on Android 11 in particular. However, it will take years for Android 11+ to dominate the Android device ecosystem.
But, some of my users complain that, they are still able to see images in 3rd party gallery app.
Such apps might be augmenting the MediaStore by scanning external storage for images.
But, is it appropriate for an app to store user data file in getFilesDir?
Yes. Everything should be in internal storage, unless there is a specific need for the user to be able to use the content outside of your app. Internal storage should be your default choice, with external storage or the Storage Access Framework being explicit choices made to go against that default.
From discussion of Android getExternalFilesDir vs getFilesDir() for big files , it seems like getFilesDir is not designed to store user data files?
Um, no.
A decade ago, internal storage and external storage were separate partitions, in part because external storage typically was implemented as removable storage (micro SD card). Since Android 3.0 in 2011, though, internal storage and external storage are almost always separate directories on the same partition. The primary distinction between the two is what processes could access the files, with your portion of internal storage being locked down to just your app, and external storage being accessible by anything.

Sharing Config Files Across Apps - Android 10 and Beyond

My company has three different Android apps that provide functionality for sales reps. We opted to separate the apps into "modules" because not all reps need all the modules. Up to now we have been using a JSON file in a directory on the SD card of the devices to set some configuration data for the apps. However, it appears that with Android 10 and beyond this will no longer be possible.
Currently we use getExternalStorageDirectory() to access the SDCARD and then open a file inside a directory our app creates.
Since we want the file access to not be something the sales reps have any control over we want it to happen transparently. However it does not seem this will be possible going forward.
Will using a custom FileProvider or even a DocumentsProvider be a way to continue to share data between our apps?
Another question, although not as important, is, can we change the default location of the DB files our app creates as we do now in earlier versions of Android?
Thanks
Rich

How do I write to the SD card on Nougat/Android 7.0 (VR friendly)?

I'm looking for a way to make my VR Android app (for Samsung Galaxy S7 and S9) able to write files to the SD card (e.g. by downloading a .zip file and unzipping it there).
The app is mostly going to be used by people, who don't know a lot about Android/smartphones and don't want to have to deal with anything complicated (not necessarily seniors but close enough), that's why I want to make it as easy as possible for them, which also includes making choices myself (and setting it up for them) instead of showing complicated dialogs.
Special requirements:
The files must not be deleted when the app is uninstalled - that's why I can's use getExternalFilesDirs() (Storage Volume).
The folder everything happens in has to be easily accessable, so the zip files can be transfered to the SD card on your PC too (instead of downloading them through the app in case they are too big) without having to go down a huge amount of levels and remembering a long folder path.
Using Storage Access Framework isn't a good alternative either because not only is picking folders nothing that's especially VR friendly but it also requires knowledge about folders most of the users simply won't have and/or won't want to deal with every time they open my app. But: If there was a way to only show this once (on the very first start after installing the app) and maybe even set the root folder to the folder I chose, so the users only have to hit "accept", that would be worth a try (unless there's an easier way).
Yes, I did set the android.permission.WRITE_EXTERNAL_STORAGE permission and also enabled the "force allow apps on external storage" developer setting but trying to write to the SD card still throws an "Access Denied" exception.
Are there any others ways to write to the SD card that are VR friendly?

How does the multi-user feature work in terms of paths on Android?

background
Starting with version 4.2 , Android supports multi-user (link here and here).
Each user has its apps and their private data is visible just for the user.
The question
How does the encapsulation of the data per user work in terms of paths and accessing files?
I mean, what will be the paths per each user for:
the private, internal storage.
the emulated external storage (built in external storage)
the "real" external storage (sd cards)
?
I guess users can see the data stored on the sd cards that belong to other users, but what about the emulated external storage? And can they also write other users' files or just read them?
Does each user get its own special path automatically? or should the developer handle this?
If the developer needs to handle it, what should be used as the ID of the user?
The documentation says:
No matter which of these APIs you use to save data for a given user,
the data will not be accessible while running as a different user.
But that's all assuming you use the APIs for your own path. Could apps somehow bypass this by going to other paths?
What can an app query about each installation of itself on the same device? Can they get the size of apps of other users? Can they even get the list of apps of other users?
Does multiple installation of the same app also take multiple size?
what will be the paths per each user
If you care, you're doing it wrong. Use the Android SDK APIs for determining base directories, and work from there. So, for example:
getFilesDir() will return the right location for internal storage for the current user
getExternalFilesDir() and the methods on Environment will return the right locations for external storage for the current user
I guess users can see the data stored on the sd cards that belong to other users
That is outside the bounds of the Android SDK, generally.
but what about the emulated external storage?
Each user gets their own space.
And can they also write other users' files or just read them?
Neither, barring bugs in the device.
Does each user get its own special path automatically?
Yes, if you are using the Android SDK APIs for determining base directories.
Could apps somehow bypass this by going to other paths?
No, because they will have neither read nor write access, barring bugs.
What can an app query about each installation of itself on the same device?
AFAIK, nothing. From the app's standpoint, the fact that there are several installations on one device is indistinguishable from being installed on several devices.
Can they get the size of apps of other users?
I do not know what you mean by "size of apps", sorry.
Can they even get the list of apps of other users?
That's a fine question. I have not experimented with PackageManager to see what it exposes when used by apps run by secondary users. In theory, it should only report things that are available to the current user, particularly given Android's restricted profiles.
Does multiple installation of the same app also take multiple size?
The APK and the pieces of it that are unpacked (e.g., DEX files) are shared, as I understand it.

Android: from Copy Protection to Application Licensing

MY app on Android has a new major module added to it which changes the app size from ~10Mb to ~100Mb. The plan is to implement "Application Licensing" and allow app to a) be installed on SD card, b) download heavy bits (video) from inside the app when needed after installation. My question is: what will happen to previous users? On their devices the app is installed in internal memory from the start due to Copy Protection. Will an update automatically move the app to SD?
If you are downloading the bits after installation, you can allow the user to continue to choose where to put the application (I assume it remains 10MB for the base application?), and any additional content is downloaded to the SD card by you in-app. As long as you hold a reference to the location of the video, so as you know whether it exists or not (by doing a check of the file system at the expected location), you can determine whether it needs downloading or not.
Might also be worth, for complete understanding, to have a look at the features that the Play Store offers for large applications - you can set applications to require additional downloads hosted by Google Play, with the user being informed of the total application size.
Of course, if you are going to increase the size of the main application and have it left on the internal memory, some users may have problems with the new file size. They will be informed that it couldn't be installed when it updates, and will have to move it to SD card.

Categories

Resources