Manual cherrypick from CL ag/2968176 (Automatic failed since master changed)

Test: This CL adds tests. All the UT and other tests pass.
Change-Id: I5e6bf86f439fd86977a7f9ddc027a65d9c11d5ca
15 files changed