Ported from: https://github.com/CyanogenMod/android_frameworks_base