Fix CacheManager to correctly write CacheFiles to disk.

There are two problems with the CacheManager -
1. Need to null terminate the file path used for the cache file on
disk.
2. A race condition between starting the background task to write
the file and updating internal state variables.

These were causing a CTS test to fail.

Bug: 5619303
Change-Id: I61f06d50b7ef560ede2f1141fc51d92255d4efbd
2 files changed