Import from aosp https://android.googlesource.com/a/platform/tools/base