In general my understanding is that Android is trying to move away from giving apps access to the full filesystem, so we should try to move to using the app-specific path given by `getExternalFilesDir`, but unfortunately I don't think Android gives you access to this value outside of the app itself, so it's a little bit tricky to resolve it dynamically in our use case. I think our best bet would be to hard-code `/storage/emulated/0/Android/data/<app_id>/files` (which is the output of `getExternalFilesDir`), this folder should work for most devices and will continue to work for the foreseeable future. Alternatively we could output this path in the logs, grab it, restart the app? That would be the safest way I think, but I'm honestly not sure how many devices don't work with the path above. > Using adb shell echo $EXTERNAL_STORAGE the value is empty, but logging into the shell via adb shell first, and then calling echo $EXTERNAL_STORAGE actually returns /sdcard. Do you know why that happens? At least geckodriver doesn't seem to have an issue with that (anymore?) Are you properly escaping `$`? If you literally run `adb shell echo $EXTERNAL_STORAGE` I think your terminal will try to resolve `$EXTERNAL_STORAGE` in your host machine, so it would end up running `adb shell echo ""` (I only realized that because you mentioned that the two values are different :) ). `adb shell echo "\$EXTERNAL_STORAGE"` does the right thing for me. > What if external storage is not available? Where should we fallback to? (Maybe in such a case the environment variable is empty?) The output of `Context#getExternalFilesDir(java.lang.String)`. From what I can gather there is no way to get that value from `adb` or anything similar, but I think we could hard-code some paths that we can try to use in case `EXTERNAL_STORAGE` is missing. > I can see that people reporting that the environment variable and Environment.getExternalStorageDirectory() could contain different values. Which one do we trust? Neither, `getExternalStorageDirectory` is deprecated, we should use `getExternalFilesDir` which will give you an app-specific external path that is safe to use.
Bug 1700559 Comment 7 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
In general my understanding is that Android is trying to move away from giving apps access to the full filesystem, so we should try to move to using the app-specific path given by `getExternalFilesDir`, but unfortunately I don't think Android gives you access to this value outside of the app itself, so it's a little bit tricky to resolve it dynamically in our use case. I think our best bet would be to hard-code `/storage/emulated/0/Android/data/<app_id>/files` (which is the output of `getExternalFilesDir`), this folder should work for most devices and will continue to work for the foreseeable future. Alternatively we could output this path in the logs, grab it, restart the app? That would be the safest way I think, but I'm honestly not sure how many devices don't work with the path above. > Using adb shell echo $EXTERNAL_STORAGE the value is empty, but logging into the shell via adb shell first, and then calling echo $EXTERNAL_STORAGE actually returns /sdcard. Do you know why that happens? At least geckodriver doesn't seem to have an issue with that (anymore?) Are you properly escaping `$`? If you literally run `adb shell echo $EXTERNAL_STORAGE`, your terminal will try to resolve `$EXTERNAL_STORAGE` in your host machine, so it would end up running `adb shell echo ""` (I only realized that because you mentioned that the two values are different :) ). `adb shell echo "\$EXTERNAL_STORAGE"` does the right thing for me. > What if external storage is not available? Where should we fallback to? (Maybe in such a case the environment variable is empty?) The output of `Context#getExternalFilesDir(java.lang.String)`. From what I can gather there is no way to get that value from `adb` or anything similar, but I think we could hard-code some paths that we can try to use in case `EXTERNAL_STORAGE` is missing. > I can see that people reporting that the environment variable and Environment.getExternalStorageDirectory() could contain different values. Which one do we trust? Neither, `getExternalStorageDirectory` is deprecated, we should use `getExternalFilesDir` which will give you an app-specific external path that is safe to use.