Port https://github.com/CyanogenMod/android_frameworks_native/commit/a21f30e6fefbe7526d65ea2e1dbda3311f12d690