Apexd: populate database on startup

On startup, APEX database is populated from /proc/mounts.

/apex/<package-id> can be mounted from
- /dev/block/loopX : loop device
- /dev/block/dm-X : dm-verity
- <flattened> : bind-mount

In case of loop device, it is from a non-flattened
APEX file. This original APEX file can be tracked
by /sys/block/loopX/loop/backing_file.

In case of dm-verity, it is mapped to a loop device.
This mapped loop device can be traced by
/sys/block/dm-X/slaves/ directory which contains
a symlink to /sys/block/loopY, which leads to
the original APEX file.
Device name can be retrieved from
/sys/block/dm-Y/dm/name.

In case of <flattened>, it is --bind mounted to a flattened
APEX directory. This is allowed only for system/product
partitions. So, original APEX directory can be found
by comparing dev/inode pair with candidates.

By synchronizing the mounts info with Database on startup,
Apexd serves the correct package list even on the devices
which are not ro.apex.updatable.
(Previously it doesn't list bootstrap packages even though
they are mounted and accessable.)

And in case of crash, re-started apexd can maintain
correct list of mounted packages.

Bug: 129525859
Test: atest apexservice_test
Test: adb shell pm list packages --apex-only
 check list on device with ro.apex.updatable=false
 check list after apexd's restart

Change-Id: I272cb2029d398bd60f6f89e8580b348db5543f87
7 files changed
tree: fab27c81d565fa16a29fcf9dd395f10b88b120ba
  1. apexd/
  2. apexer/
  3. proto/
  4. shim/
  5. tests/
  6. CleanSpec.mk
  7. OWNERS
  8. PREUPLOAD.cfg