Refactor public_libraries.cpp more

- *_public_libraries() are now thread-safe
- removed some of the duplicated code

Bug: 130388701
Test: build & pass presubmit tests
Change-Id: I34b5149f75e28bb892cffe8fd9070be886d2f9bd
1 file changed