Fix ContentResolver opening with O_DIRECT

To ensure upper and lower fs cache consistency, when we return fds to
the lower fs via ContentResolver, we hold a lock on the file so that
subsequent file path opens will use direct_io and the latest writes
will be visible across upper and lower fs, see:
I7726a75a51869c0e3ea3856103dd501b1aa19d14

Ideally, we only need to hold a read lock but we cannot grab a read
lock when the fd is opened 'w' only.

Previously, we would grab a read lock for 'r' or 'rw' and a write lock
for 'w' only.

Now, we convert 'w' to 'rw'. This allows us always grab a read lock
and fixes the following scenario:

1. App opens file for 'w' via ContentResolver: Gets fd to the lower fs
2. App opens file for 'w' again. Gets fd to FUSE but with
O_DIRECT (because we set the write) lock in (1). This second fd cannot
be used with mmap(PROT_SHARED) for instance.

Test: atest ScopedStorageTest#testVfsCacheConsistency
Bug: 158226779
Change-Id: Iaf8054bf56bdc3bb1f71a1ee543ebb261fd58fbd
1 file changed