Exemple #1
0
func GetString() (string, error) {
	strSize := int(C.android_get_prop_value_max())
	verStr := (*C.char)(C.malloc(C.size_t(strSize)))
	defer C.free(unsafe.Pointer(verStr))
	C.android_get_release(verStr)
	return C.GoString(verStr), nil
}
Exemple #2
0
func GetHumanReadable() (string, error) {
	// First get the semantic versioning scheme
	verStr, err := GetString()
	if err != nil {
		return verStr, err
	}

	// Then get the release name
	strSize := int(C.android_get_prop_value_max())
	apiStr := (*C.char)(C.malloc(C.size_t(strSize)))
	defer C.free(unsafe.Pointer(apiStr))
	C.android_get_api(apiStr)

	i, err := strconv.ParseUint(C.GoString(apiStr), 10, 16)
	if err != nil {
		return verStr, err
	}

	if i > 22 {
		return verStr, errors.New("Unknown Android API version")
	}

	return fmt.Sprintf("%s %s", versions[i-1], verStr), nil
}