Refactor "avoid bad wifi" logic into a utility class am: 95ecfee674
am: 567fc7861d

Change-Id: Id670d13b99ab6935b67335e19d2389e5b4f61111