cloned from android/platform/frameworks/native