Fix writing to external storage

Change-Id: I1d9663de25dfa12280d3db0d868c35cd5a76dd5e