Refactor "avoid bad wifi" logic into a utility class am: fc52be9643
am: f0582faceb

Change-Id: Id670d13b99ab6935b67335e19d2389e5b4f61111