Use libnativewindow for Android builds

To avoid references to libEGL.so do not link with libandroid,
use libnativewindow instead. libnativewindow is available in
android-26 and newer.
The appropriate library will be selected based on the ndk level
configured. If ndk revision is 26 or higher, we'll link to
libnativewindow otherwise use libandroid.
The ANGLE apk needs to use 26 or higher.

Bug: angleproject:2418
Change-Id: I96509e5d645d132a34734558cd0566f1812b615b
Reviewed-on: https://chromium-review.googlesource.com/1066821
Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9aeb5ec..bbfbfda 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -8,7 +8,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     package="com.google.android.angle">
-    <uses-sdk android:minSdkVersion="24"
+    <uses-sdk android:minSdkVersion="26"
               android:targetSdkVersion="28">
     </uses-sdk>
 
diff --git a/BUILD.gn b/BUILD.gn
index 84172aa..37158d7 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -78,11 +78,10 @@
     "EGL_EGLEXT_PROTOTYPES",
   ]
 
-  if (current_cpu == "x86" || current_cpu == "arm") {
-    defines += [ "ANGLE_IS_32_BIT_CPU" ]
-  }
-  if (current_cpu == "x64" || current_cpu == "arm64") {
+  if (angle_64bit_current_cpu) {
     defines += [ "ANGLE_IS_64_BIT_CPU" ]
+  } else {
+    defines += [ "ANGLE_IS_32_BIT_CPU" ]
   }
 }
 
@@ -531,10 +530,12 @@
       sources += rebase_path(gles_gypi.libangle_gl_egl_dl_sources, ".", "src")
       sources +=
           rebase_path(gles_gypi.libangle_gl_egl_android_sources, ".", "src")
-      libs += [
-        "android",
-        "log",
-      ]
+      if (ndk_supports_nativewindow) {
+        libs += [ "nativewindow" ]
+      } else {
+        libs += [ "android" ]
+      }
+      libs += [ "log" ]
     }
     if (ozone_platform_gbm) {
       configs += [ ":libdrm" ]
@@ -840,9 +841,10 @@
       sources += rebase_path(util_gypi.util_win32_sources, ".", "util")
     }
 
+    libs = []
     if (is_linux) {
       sources += rebase_path(util_gypi.util_linux_sources, ".", "util")
-      libs = [
+      libs += [
         "rt",
         "dl",
       ]
@@ -850,7 +852,7 @@
 
     if (is_mac) {
       sources += rebase_path(util_gypi.util_osx_sources, ".", "util")
-      libs = [
+      libs += [
         "AppKit.framework",
         "QuartzCore.framework",
       ]
@@ -869,10 +871,12 @@
       set_sources_assignment_filter([])
       sources += rebase_path(util_gypi.util_linux_sources, ".", "util")
       sources += rebase_path(util_gypi.util_android_sources, ".", "util")
-      libs = [
-        "android",
-        "log",
-      ]
+      if (ndk_supports_nativewindow) {
+        libs += [ "nativewindow" ]
+      } else {
+        libs += [ "android" ]
+      }
+      libs += [ "log" ]
     }
 
     if (use_ozone) {
@@ -932,9 +936,9 @@
   android_apk("angle_apk") {
     if (build_apk_secondary_abi && android_64bit_target_cpu) {
       secondary_abi_shared_libraries = [
-        "//third_party/angle:libGLESv2${angle_libs_suffix}($android_secondary_abi_toolchain)",
         "//third_party/angle:libEGL${angle_libs_suffix}($android_secondary_abi_toolchain)",
         "//third_party/angle:libGLESv1_CM${angle_libs_suffix}($android_secondary_abi_toolchain)",
+        "//third_party/angle:libGLESv2${angle_libs_suffix}($android_secondary_abi_toolchain)",
       ]
     }
 
@@ -947,9 +951,9 @@
     apk_name = "AngleLibraries"
     uncompress_shared_libraries = true
     shared_libraries = [
-      "//third_party/angle:libGLESv2${angle_libs_suffix}",
       "//third_party/angle:libEGL${angle_libs_suffix}",
       "//third_party/angle:libGLESv1_CM${angle_libs_suffix}",
+      "//third_party/angle:libGLESv2${angle_libs_suffix}",
     ]
   }
 }
diff --git a/gni/angle.gni b/gni/angle.gni
index 4653d51..95e55b2 100644
--- a/gni/angle.gni
+++ b/gni/angle.gni
@@ -25,12 +25,28 @@
 data_dir = "angledata"
 
 declare_args() {
+  if (current_cpu == "arm64" || current_cpu == "x64" ||
+      current_cpu == "mips64el") {
+    angle_64bit_current_cpu = true
+  } else if (current_cpu == "arm" || current_cpu == "x86" ||
+             current_cpu == "mipsel") {
+    angle_64bit_current_cpu = false
+  } else {
+    assert(false, "Unknown current CPU: $current_cpu")
+  }
+}
+
+declare_args() {
   if (!is_android) {
     ndk_supports_vulkan = false
+    ndk_supports_nativewindow = false
   } else {
     ndk_supports_vulkan =
-        (current_cpu == "arm" && android32_ndk_api_level >= 24) ||
-        (current_cpu == "arm64" && android64_ndk_api_level >= 24)
+        (!angle_64bit_current_cpu && android32_ndk_api_level >= 24) ||
+        (angle_64bit_current_cpu && android64_ndk_api_level >= 24)
+    ndk_supports_nativewindow =
+        (!angle_64bit_current_cpu && android32_ndk_api_level >= 26) ||
+        (angle_64bit_current_cpu && android64_ndk_api_level >= 26)
   }
   angle_shared_libvulkan = false
   angle_libs_suffix = ""