Some cherry picks from Botje's android branch

This stuff all seems good to merge to me. Should help a little bit with getting android mainlined.