Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28058] Android: Change Ti.Filesystem "temp" APIs to use app's cache folder

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-11-20T15:14:14.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.3.0
ComponentsAndroid
Labelsandroid, file, filesystem, storage, tempdir
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-07-30T04:09:15.000+0000
Updated2020-11-20T15:14:14.000+0000

Description

*Summary:* The following APIs need to use app's scoped storage and avoid external storage. * Ti.Filesystem.createTempDirectory() * Ti.Filesystem.createTempFile() * Ti.Filesystem.tempDirectory *Note 1:* We should write temp files according to Google's docs in the link below. They expect us to explicitly set the temp directory to the app's cache directory. https://developer.android.com/training/data-storage/app-specific#internal-create-cache *Note 2:* Our Ti.Filesystem.tempDirectory property return...
./<AppCacheDir>/_tmp
Our Ti.Filesystem.createTempFile() and Ti.Filesystem.createTempDirectory() methods should change their base directory to the below to avoid collision with the above folder.
./<AppCacheDir>/.titanium/tmp
*Note 3:* Our [TiTempFileHelper.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/java/org/appcelerator/kroll/util/TiTempFileHelper.java) code (used to acquire a temp directory path) will use getExternalCacheDir() or getCacheDir() depending on if it has access to external storage or not. This may not be a good idea since the temp directory can suddenly change at runtime due to... * End-user granting permission, making it dynamically switch to external storage. * End-user ejects SD card, which makes temp path switch to internal storage. It would be better for the path to be consistent for the app's lifetime. So, it should be hardcoded to internal storage via getCacheDir() like Google's examples. *Note 4:* Our HTTP response cache should favor internal storage's cache directory for improved security/privacy. That is what Google suggests in the link below and is what the Chrome browser app does. External storage is best used for large files intended to be shared (like downloaded files). https://developer.android.com/reference/android/net/http/HttpResponseCache If we do this, then we can remove our startExternalStorageMonitor() related code in [TiApplication.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiApplication.java) and hard-code our TiResponseCache to always be the default. This means HTTP response caching will alway be enabled, even if you don't have external storage permission.

Comments

  1. Joshua Quick 2020-10-07

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12161
  2. Satyam Sekhri 2020-10-19

    FR Passed. Waiting for Jenkins build.
  3. Christopher Williams 2020-10-19

    Merged to master for 9.3.0 target
  4. Samir Mohammed 2020-11-20

    *Closing ticket*. Improvement verified in SDK version 9.3.0.v20201119063936. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/12161

JSON Source