Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android, utils): fix rare crash getting documents directory #5118

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ public Map<String, Object> getConstants() {

File externalDirectory = context.getExternalFilesDir(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if ( externalDirectory != null ) {
if (externalDirectory != null) {
constants.put(KEY_DOCUMENT_DIRECTORY, externalDirectory.getAbsolutePath());
} else {
// The external directory may be null if it is truly external *and*
// the device's external storage environment changes. We will use the regular
// Files directory as a backup and note in the documentation that the directory may
// vary under rare conditions
constants.put(KEY_DOCUMENT_DIRECTORY, context.getFilesDir().getAbsolutePath());
}
} else {
}

if (!constants.containsKey(KEY_DOCUMENT_DIRECTORY)) {
constants.put(KEY_DOCUMENT_DIRECTORY, context.getFilesDir().getAbsolutePath());
}

Expand Down
5 changes: 5 additions & 0 deletions packages/app/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export namespace Utils {
*
* Use this directory to place documents that have been created by the user.
*
* Normally this is the external files directory on Android but if no external storage directory found,
* e.g. removable media has been ejected by the user, it will fall back to internal storage. This may
* under rare circumstances where device storage environment changes cause the directory to be different
* between runs of the application
*
* ```js
* firebase.utils.FilePath.DOCUMENT_DIRECTORY;
* ```
Expand Down