Also refactors common code. Bug: 166845383 Test: Compile only (VTS test coming up in future CL) Change-Id: Iae6cf09e2fffb854af61c29e6004ceb062a892b3