Backport from android.