Revert "Refine SHA-1 related stuffs."

This reverts commit 6378d8f50449d79b8937c238b968ceeb9dbd4ee1.

Conflicts:

	Android.mk

Change-Id: Ib8988583a0b916d21e9314e919269f02c4dd600e
diff --git a/lib/RenderScript/RSInfo.cpp b/lib/RenderScript/RSInfo.cpp
index f3010cf..536c83b 100644
--- a/lib/RenderScript/RSInfo.cpp
+++ b/lib/RenderScript/RSInfo.cpp
@@ -17,36 +17,35 @@
 //#define LOG_NDEBUG 0
 #include "bcc/RenderScript/RSInfo.h"
 
-#include <dlfcn.h>
-
 #include <cstring>
 #include <new>
 
 #include "bcc/Support/FileBase.h"
 #include "bcc/Support/Log.h"
+#include "bcc/Support/Sha1Helper.h"
 
 using namespace bcc;
 
 const char RSInfo::LibBCCPath[] = "/system/lib/libbcc.so";
 const char RSInfo::LibRSPath[] = "/system/lib/libRS.so";
-const uint8_t *RSInfo::LibBCCSHA1 = NULL;
-const uint8_t *RSInfo::LibRSSHA1 = NULL;
+uint8_t RSInfo::LibBCCSHA1[20];
+uint8_t RSInfo::LibRSSHA1[20];
 
 void RSInfo::LoadBuiltInSHA1Information() {
-  if (LibBCCSHA1 != NULL) {
-    // Loaded before.
+  static bool loaded = false;
+
+  if (loaded) {
     return;
   }
 
-  void *h = ::dlopen("/system/lib/libbcc.sha1.so", RTLD_LAZY | RTLD_NOW);
-  if (h == NULL) {
-    ALOGE("Failed to load SHA-1 information from shared library '"
-          "/system/lib/libbcc.sha1.so'! (%s)", ::dlerror());
-    return;
-  }
+  // Read SHA-1 checksum of libbcc from hard-coded patch
+  // /system/lib/libbcc.so.sha1.
+  readSHA1(LibBCCSHA1, 20, "/system/lib/libbcc.so.sha1");
 
-  LibBCCSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libbcc_so_SHA1"));
-  LibRSSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libRS_so_SHA1"));
+  // Calculate the SHA-1 checksum of libRS.so.
+  calcFileSHA1(LibRSSHA1, LibRSPath);
+
+  loaded = true;
 
   return;
 }
@@ -87,7 +86,7 @@
         pInfo.mDependencyTable[1];
 
     // Check libbcc.so.
-    if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, SHA1_DIGEST_LENGTH) != 0) {
+    if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, 20) != 0) {
         ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename,
               LibBCCPath);
         PRINT_DEPENDENCY("current - ", LibBCCPath, LibBCCSHA1);
@@ -97,7 +96,7 @@
     }
 
     // Check libRS.so.
-    if (::memcmp(cache_libRS_dep.second, LibRSSHA1, SHA1_DIGEST_LENGTH) != 0) {
+    if (::memcmp(cache_libRS_dep.second, LibRSSHA1, 20) != 0) {
         ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename,
               LibRSPath);
         PRINT_DEPENDENCY("current - ", LibRSPath, LibRSSHA1);
@@ -114,8 +113,7 @@
       if ((::strncmp(in_dep.getSourceName().c_str(),
                      cache_dep.first,
                      in_dep.getSourceName().length()) != 0) ||
-          (::memcmp(in_dep.getSHA1Checksum(), cache_dep.second,
-                    SHA1_DIGEST_LENGTH) != 0)) {
+          (::memcmp(in_dep.getSHA1Checksum(), cache_dep.second, 20) != 0)) {
         ALOGD("Cache %s is dirty due to the source it dependends on has been "
               "changed:", pInputFilename);
         PRINT_DEPENDENCY("given - ", in_dep.getSourceName().c_str(),
diff --git a/lib/RenderScript/RSInfoExtractor.cpp b/lib/RenderScript/RSInfoExtractor.cpp
index 2e58fb7..377ec3a 100644
--- a/lib/RenderScript/RSInfoExtractor.cpp
+++ b/lib/RenderScript/RSInfoExtractor.cpp
@@ -112,13 +112,12 @@
 
   uint8_t *sha1 = reinterpret_cast<uint8_t *>(pStringPool + *pWriteStart);
 
-  // SHA-1 is special. It's size of SHA1_DIGEST_LENGTH (=20) bytes long without
-  // null-terminator.
-  ::memcpy(sha1, pSHA1, SHA1_DIGEST_LENGTH);
+  // SHA-1 is special. It's 20-bytes long without null-terminator.
+  ::memcpy(sha1, pSHA1, 20);
   // Record in the result RSInfo object.
   pDepTable.push(std::make_pair(source_name, sha1));
   // Update the string pool pointer.
-  *pWriteStart += SHA1_DIGEST_LENGTH;
+  *pWriteStart += 20;
 
   return true;
 }
@@ -165,15 +164,15 @@
 
   // Don't forget to reserve the space for the dependency informationin string
   // pool.
-  string_pool_size += ::strlen(LibBCCPath) + 1 + SHA1_DIGEST_LENGTH;
-  string_pool_size += ::strlen(LibRSPath) + 1 + SHA1_DIGEST_LENGTH;
+  string_pool_size += ::strlen(LibBCCPath) + 1 + 20;
+  string_pool_size += ::strlen(LibRSPath) + 1 + 20;
   for (unsigned i = 0, e = pDeps.size(); i != e; i++) {
     const RSScript::SourceDependency *source_dep = pDeps[i];
     if (source_dep != NULL) {
       // +1 for null-terminator
       string_pool_size += source_dep->getSourceName().length() + 1;
-      // +SHA1_DIGEST_LENGTH for SHA-1 checksum
-      string_pool_size += SHA1_DIGEST_LENGTH;
+      // +20 for SHA-1 checksum
+      string_pool_size += 20;
     }
   }