Backported/extended Android stuff using reflection and other hacks