Proper way to ensure process dies before restart it

The previous fixes would give up the global AM lock which could
result races. Now keep polling to make sure the process goes away
before restart it.

Bug: 141857656
Test: manual
Change-Id: I661f9d23ea579874632399585ad375b0892c6da7
2 files changed