Stop using the __ANDROID_API_x__ constants.

Historically we've made a few mistakes where they haven't matched the
right number. And most non-Googlers are much more familiar with the
numbers, so it seems to make sense to rely more on them. Especially in
header files, which we actually expect real people to have to read from
time to time.

Test: treehugger
Change-Id: I0d4a97454ee108de1d32f21df285315c5488d886
diff --git a/linker/linker.cpp b/linker/linker.cpp
index fb22a1d..54e0703 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -209,7 +209,7 @@
   };
 
   // If you're targeting N, you don't get the greylist.
-  if (g_greylist_disabled || get_application_target_sdk_version() >= __ANDROID_API_N__) {
+  if (g_greylist_disabled || get_application_target_sdk_version() >= 24) {
     return false;
   }
 
@@ -252,7 +252,7 @@
   // New mapping for new apex should be added below
 
   // Nothing to do if target sdk version is Q or above
-  if (get_application_target_sdk_version() >= __ANDROID_API_Q__) {
+  if (get_application_target_sdk_version() >= 29) {
     return false;
   }
 
@@ -943,8 +943,7 @@
     // Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
     // if the library is opened by application with target api level < M.
     // See http://b/21565766
-    if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 &&
-        si->get_target_sdk_version() >= __ANDROID_API_M__) {
+    if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 && si->get_target_sdk_version() >= 23) {
       continue;
     }
 
@@ -1232,10 +1231,10 @@
 #if !defined(__LP64__)
   // Work around incorrect DT_NEEDED entries for old apps: http://b/21364029
   int app_target_api_level = get_application_target_sdk_version();
-  if (app_target_api_level < __ANDROID_API_M__) {
+  if (app_target_api_level < 23) {
     const char* bname = basename(dt_needed);
     if (bname != dt_needed) {
-      DL_WARN_documented_change(__ANDROID_API_M__,
+      DL_WARN_documented_change(23,
                                 "invalid-dt_needed-entries-enforced-for-api-level-23",
                                 "library \"%s\" has invalid DT_NEEDED entry \"%s\"",
                                 sopath, dt_needed, app_target_api_level);
@@ -1384,7 +1383,7 @@
         const soinfo* needed_or_dlopened_by = task->get_needed_by();
         const char* sopath = needed_or_dlopened_by == nullptr ? "(unknown)" :
                                                       needed_or_dlopened_by->get_realpath();
-        DL_WARN_documented_change(__ANDROID_API_N__,
+        DL_WARN_documented_change(24,
                                   "private-api-enforced-for-api-level-24",
                                   "library \"%s\" (\"%s\") needed or dlopened by \"%s\" "
                                   "is not accessible by namespace \"%s\"",
@@ -3832,9 +3831,9 @@
   if (soname_ == nullptr &&
       this != solist_get_somain() &&
       (flags_ & FLAG_LINKER) == 0 &&
-      get_application_target_sdk_version() < __ANDROID_API_M__) {
+      get_application_target_sdk_version() < 23) {
     soname_ = basename(realpath_.c_str());
-    DL_WARN_documented_change(__ANDROID_API_M__,
+    DL_WARN_documented_change(23,
                               "missing-soname-enforced-for-api-level-23",
                               "\"%s\" has no DT_SONAME (will use %s instead)",
                               get_realpath(), soname_);
@@ -3875,7 +3874,7 @@
   if (has_text_relocations) {
     // Fail if app is targeting M or above.
     int app_target_api_level = get_application_target_sdk_version();
-    if (app_target_api_level >= __ANDROID_API_M__) {
+    if (app_target_api_level >= 23) {
       DL_ERR_AND_LOG("\"%s\" has text relocations (https://android.googlesource.com/platform/"
                      "bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-"
                      "Enforced-for-API-level-23)", get_realpath());
@@ -3883,7 +3882,7 @@
     }
     // Make segments writable to allow text relocations to work properly. We will later call
     // phdr_table_protect_segments() after all of them are applied.
-    DL_WARN_documented_change(__ANDROID_API_M__,
+    DL_WARN_documented_change(23,
                               "Text-Relocations-Enforced-for-API-level-23",
                               "\"%s\" has text relocations",
                               get_realpath());
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index 3534287..da2d03c 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -264,12 +264,12 @@
 
   if (header_.e_shentsize != sizeof(ElfW(Shdr))) {
     // Fail if app is targeting Android O or above
-    if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
+    if (get_application_target_sdk_version() >= 26) {
       DL_ERR_AND_LOG("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)",
                      name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
       return false;
     }
-    DL_WARN_documented_change(__ANDROID_API_O__,
+    DL_WARN_documented_change(26,
                               "invalid-elf-header_section-headers-enforced-for-api-level-26",
                               "\"%s\" has unsupported e_shentsize 0x%x (expected 0x%zx)",
                               name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
@@ -278,12 +278,12 @@
 
   if (header_.e_shstrndx == 0) {
     // Fail if app is targeting Android O or above
-    if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
+    if (get_application_target_sdk_version() >= 26) {
       DL_ERR_AND_LOG("\"%s\" has invalid e_shstrndx", name_.c_str());
       return false;
     }
 
-    DL_WARN_documented_change(__ANDROID_API_O__,
+    DL_WARN_documented_change(26,
                               "invalid-elf-header_section-headers-enforced-for-api-level-26",
                               "\"%s\" has invalid e_shstrndx", name_.c_str());
     add_dlwarning(name_.c_str(), "has invalid ELF header");
@@ -392,7 +392,7 @@
   }
 
   if (pt_dynamic_offset != dynamic_shdr->sh_offset) {
-    if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
+    if (get_application_target_sdk_version() >= 26) {
       DL_ERR_AND_LOG("\"%s\" .dynamic section has invalid offset: 0x%zx, "
                      "expected to match PT_DYNAMIC offset: 0x%zx",
                      name_.c_str(),
@@ -400,7 +400,7 @@
                      pt_dynamic_offset);
       return false;
     }
-    DL_WARN_documented_change(__ANDROID_API_O__,
+    DL_WARN_documented_change(26,
                               "invalid-elf-header_section-headers-enforced-for-api-level-26",
                               "\"%s\" .dynamic section has invalid offset: 0x%zx "
                               "(expected to match PT_DYNAMIC offset 0x%zx)",
@@ -411,7 +411,7 @@
   }
 
   if (pt_dynamic_filesz != dynamic_shdr->sh_size) {
-    if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
+    if (get_application_target_sdk_version() >= 26) {
       DL_ERR_AND_LOG("\"%s\" .dynamic section has invalid size: 0x%zx, "
                      "expected to match PT_DYNAMIC filesz: 0x%zx",
                      name_.c_str(),
@@ -419,7 +419,7 @@
                      pt_dynamic_filesz);
       return false;
     }
-    DL_WARN_documented_change(__ANDROID_API_O__,
+    DL_WARN_documented_change(26,
                               "invalid-elf-header_section-headers-enforced-for-api-level-26",
                               "\"%s\" .dynamic section has invalid size: 0x%zx "
                               "(expected to match PT_DYNAMIC filesz 0x%zx)",
@@ -635,11 +635,11 @@
       int prot = PFLAGS_TO_PROT(phdr->p_flags);
       if ((prot & (PROT_EXEC | PROT_WRITE)) == (PROT_EXEC | PROT_WRITE)) {
         // W + E PT_LOAD segments are not allowed in O.
-        if (get_application_target_sdk_version() >= __ANDROID_API_O__) {
+        if (get_application_target_sdk_version() >= 26) {
           DL_ERR_AND_LOG("\"%s\": W+E load segments are not allowed", name_.c_str());
           return false;
         }
-        DL_WARN_documented_change(__ANDROID_API_O__,
+        DL_WARN_documented_change(26,
                                   "writable-and-executable-segments-enforced-for-api-level-26",
                                   "\"%s\" has load segments that are both writable and executable",
                                   name_.c_str());
diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp
index c71945a..04aa27b 100644
--- a/linker/linker_soinfo.cpp
+++ b/linker/linker_soinfo.cpp
@@ -754,7 +754,7 @@
 }
 
 void* soinfo::to_handle() {
-  if (get_application_target_sdk_version() < __ANDROID_API_N__ || !has_min_version(3)) {
+  if (get_application_target_sdk_version() < 24 || !has_min_version(3)) {
     return this;
   }