android-sdk: install platform-27

This CL, in addition to the existing Android SDK, installs Android
platform-27 since it is required for some ARC tests.

BUG=b:174712817
TEST=emerge android-sdk
     Verified that platform-27 gets installed correctly in
     /opt/android-sdk/platform

Change-Id: I60935e6d0ab8fd075afd12528e6537b85b0b0dd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2570694
Tested-by: Ricardo Quesada <ricardoq@chromium.org>
Reviewed-by: Yury Khmel <khmel@chromium.org>
Reviewed-by: Saho Kobayashi <sahok@chromium.org>
Reviewed-by: Shuhei Takahashi <nya@chromium.org>
Auto-Submit: Ricardo Quesada <ricardoq@chromium.org>
Commit-Queue: Ricardo Quesada <ricardoq@chromium.org>
diff --git a/chromeos-base/android-sdk/Manifest b/chromeos-base/android-sdk/Manifest
index 90a366b..58d0d02 100644
--- a/chromeos-base/android-sdk/Manifest
+++ b/chromeos-base/android-sdk/Manifest
@@ -1 +1,2 @@
+DIST sdk-repo-linux-platforms-4953408.zip 72718200 BLAKE2B 50fd48d633944e23e20df646b7bf3fa3e6cade8cb9fc380523be765844b2361e5c52bde93904b04658a5b339cc4e89ed7c5d6bdeead69b83194f3c8e5e0128db SHA512 856631fca64f76b4a0b9eb92fd5d8b26ee29205e9dccc3a5e7b01157d67276334470935401ff798f5aedce07f520be53bfd0e9faada3e63295a1e8b3e1419f8a
 DIST android-sdk_5303910_linux-x86.zip 815121172 BLAKE2B bf625dae798b08276dc0e3a39bc9fd36b38293a47e2dd2186e085710baea262c6684a993ca97319342227a9e682eb1f1c027f24b19eff24a43206959039df373 SHA512 9ba5ddfea5ca07d4df4d8dad052e9b2235d37d2b3e87dec8b9b911501e07cc932523734b225db0baab0c018cf060fd47f6b9a87cd90a04e41b176fc713ac55f0
diff --git a/chromeos-base/android-sdk/android-sdk-5303910-r3.ebuild b/chromeos-base/android-sdk/android-sdk-5303910-r4.ebuild
similarity index 100%
rename from chromeos-base/android-sdk/android-sdk-5303910-r3.ebuild
rename to chromeos-base/android-sdk/android-sdk-5303910-r4.ebuild
diff --git a/chromeos-base/android-sdk/android-sdk-5303910.ebuild b/chromeos-base/android-sdk/android-sdk-5303910.ebuild
index dea3f73..55b369c 100644
--- a/chromeos-base/android-sdk/android-sdk-5303910.ebuild
+++ b/chromeos-base/android-sdk/android-sdk-5303910.ebuild
@@ -5,7 +5,11 @@
 
 DESCRIPTION="Android SDK"
 HOMEPAGE="http://developer.android.com"
-SRC_URI="https://ci.android.com/builds/submitted/${PV}/sdk/latest/android-sdk_${PV}_linux-x86.zip"
+
+# NOTE: Due to possible licensing issues, only use AOSP SDK:
+# https://ci.android.com/builds/branches/aosp-sdk-release/grid?
+SRC_URI="https://ci.android.com/builds/submitted/${PV}/sdk/latest/android-sdk_${PV}_linux-x86.zip
+	https://ci.android.com/builds/submitted/4953408/sdk/latest/sdk-repo-linux-platforms-4953408.zip"
 
 LICENSE="
 	Apache-2.0
@@ -47,11 +51,34 @@
 
 ANDROID_SDK_DIR="/opt/android-sdk"
 
-S="${WORKDIR}/${PN}_${PV}_linux-x86"
+S="${WORKDIR}"
 
 src_install() {
+	# NOTE: The two downloaded zips use "android-Q" for their directories.
+	# It seems that they take the name of the latest Android SDK at the
+	# moment it was built, even if they were compiled from a different
+	# branch. See build.prop: notice conflict between SDK version and name:
+	# https://ci.android.com/builds/submitted/5303910/sdk/latest/view/build.prop
+
+	# Zips to be installed:
+	#  - Android SDK 28: both build-tools and platforms
+	#  - Android SDK 27: only platforms
+
+	# TODO(ricardoq): Rename "android-Q" to "android-28" (and not 29!)
 	insinto "${ANDROID_SDK_DIR}"
-	doins -r platforms
+	doins -r ${PN}_${PV}_linux-x86/platforms
 	insopts "-m0755"
-	doins -r build-tools
+	doins -r ${PN}_${PV}_linux-x86/build-tools
+
+	# In addition to SDK P, some APKs need the older android-platform-27
+	# to compile correctly.
+	insinto "${ANDROID_SDK_DIR}/platforms"
+
+	# Rename directory to match correct version. Zipped directory has the
+	# wrong name.
+	# Also use numbers instead of letters to honor the convention used
+	# by Android Studio.
+	mv "${WORKDIR}/android-Q" "${WORKDIR}/android-27"
+
+	doins -r "android-27"
 }