There is a Git repository on GitHub called platform_frameworks_base containing part of the Android source code.
I wrote an application that replies on all the .aidl files from that project, so it downloads them all on first start.
Until now I did that by downloading the file Android.bp from the project root, extracting all file paths ending in .aidl from that file and then explicitly downloading them one by one.
For example if I found this file path:
media/java/android/media/IAudioService.aidl
I knew I could download it like this:
wget https://raw.githubusercontent.com/aosp-mirror/platform_frameworks_base/android-10.0.0_r47/media/java/android/media/IAudioService.aidl
This works fine until Android 10 (git tag: android-10.0.0_r47
).
Starting with Android 11 (e.g. git tag: android-11.0.0_r33
), the file paths use wildwards instead of complete paths. See this Android.bp.
It now just contains wildcard/glob file paths like:
media/java/**/*.aidl
location/java/**/*.aidl
etc...
My current "solution":
Clone the repo (only the last commit of the branch we care about):
git clone --depth=1 -b android-11.0.0_r33 https://github.com/aosp-mirror/platform_frameworks_base.git
Extract the wildcard/glob paths from Android.bp.
cat Android.bp | grep '\.aidl"' | cut -d'"' -f2
Find all the files matching the wildcard/glob paths.
e.g.
shopt -s globstar && echo media/java/**/*.aidl
But the download process takes waaaaay to long because the repository contains over a gigabyte of binary files. Even if I just clone the last commit of the branch I care about.
Now my actual question is either:
How can I just download the .aidl
files that I actually care about? (Ideally without parsing the HTML of every folder in GitHub.)
Or
How can I download/clone the repository without all the binary files? (probably not possible with git?)
Edit:
I tried using the GitHub API to recursively go through all directories, but I immediately get an API rate limit exceeded error:
g_aidlFiles=""
# Recursively go through all directories and the paths to all found .aidl files in the global g_aidlFile variable
GetAidlFilesFromGithub() {
l_dirUrl="${1-}"
if [ "$l_dirUrl" == "" ]; then
echo "ERROR: Directory URL not provided in GetAidlFilesFromGithub"
exit 1
fi
echo "l_dirUrl: ${l_dirUrl}"
l_rawRes="$(curl -s -i $l_dirUrl)"
l_statusCode="$(echo "$l_rawRes" | grep HTTP | head -1 | cut -d' ' -f2)"
l_resBody="$(echo "$l_rawRes" | sed '1,/^\s*$/d')"
if [[ $l_statusCode == 4* ]] || [[ $l_statusCode == 5* ]]; then
echo "ERROR: Request failed!"
echo "Response status: $l_statusCode"
echo "Reponse body:"
echo "$l_resBody"
exit 1
fi
l_currentDirJson="$(echo "$l_resBody")"
if [ "$l_currentDirJson" == "" ]; then
echo "ERROR: l_currentDirJson is empty"
exit 1
fi
l_newAidlFiles="$(echo "$l_currentDirJson" | jq '.[] | select(.type=="file") | select(.path | endswith(".aidl")) | .path')"
if [ "$l_newAidlFiles" != "" ]; then
echo "l_newAidlFiles: ${l_newAidlFiles}"
g_aidlFiles="${g_aidlFiles}\n${l_newAidlFiles}"
fi
l_subDirUrls="$(echo "$l_currentDirJson" | jq '.[] | select(.type=="dir") | .url')"
if [ "$l_subDirUrls" != "" ]; then
echo "$l_subDirUrls" | while IFS= read -r l_subDirUrl ; do
(GetAidlFilesFromGithub "$l_subDirUrl")
done
else
echo "No subdirs found."
fi
}
GetAidlFilesFromGithub "https://api.github.com/repos/aosp-mirror/platform_frameworks_base/contents?ref=android-11.0.0_r33"
From what I understand all my users would have to create a GitHub account and create an OAUTH secret to raise the limit. That's definitely not an option for me. I want my application to be easy to use.