Code is duplicated in a couple of places. Bug: 178410946 Test: atest Change-Id: I1385a03a098ed7fdee7254c4752df6cbaae4a7a2