I updated the code and split that check in 2 methods:

https://github.com/mozilla-b2g/gaia/pull/12477/files#diff-b8faa448e334a8d976777976057a90d6R28
and
https://github.com/mozilla-b2g/gaia/pull/12477/files#diff-b8faa448e334a8d976777976057a90d6R38