Skip the checksum if we have precompiled code on the /system/ partition.

Bug: 20894664

The system partition is read-only, and can/should be compiled correctly
during the offline creation of the system image. Since we cannot replace
these precompiled blobs (short of app update/OTA), there is no reason or
correct way to validate/replace the checksum.

Change-Id: Ia66bfdbe178bf215e146c3699f5bc7804222e978
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 8c6e584..b95d8f7 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -46,12 +46,6 @@
 #include <iostream>
 #include <sstream>
 
-#ifdef __LP64__
-#define SYSLIBPATH "/system/lib64"
-#else
-#define SYSLIBPATH "/system/lib"
-#endif
-
 namespace {
 
 static const bool kDebugGlobalVariables = false;
@@ -153,7 +147,20 @@
                    compileArguments.size()-1, compileArguments.data());
 }
 
-bool isChecksumNeeded() {
+// The checksum is unnecessary under a few conditions, since the primary
+// use-case for it is debugging. If we are loading something from the
+// system partition (read-only), we know that it was precompiled as part of
+// application ahead of time (and thus the checksum is completely
+// unnecessary). The checksum is also unnecessary on release (non-debug)
+// builds, as the only way to get a shared object is to have compiled the
+// script once already. On a release build, there is no way to adjust the
+// other libraries/dependencies, and so the only reason to recompile would
+// be for a source APK change or an OTA. In either case, the APK would be
+// reinstalled, which would already clear the code_cache/ directory.
+bool isChecksumNeeded(const char *cacheDir) {
+    if ((::strcmp(SYSLIBPATH, cacheDir) == 0) ||
+        (::strcmp(SYSLIBPATH_VENDOR, cacheDir) == 0))
+        return false;
     char buf[PROPERTY_VALUE_MAX];
     property_get("ro.debuggable", buf, "");
     return (buf[0] == '1');
@@ -322,7 +329,7 @@
                         useRSDebugContext, bccPluginName, emitGlobalInfo,
                         emitGlobalInfoSkipConstant);
 
-    mChecksumNeeded = isChecksumNeeded();
+    mChecksumNeeded = isChecksumNeeded(cacheDir);
     if (mChecksumNeeded) {
         std::vector<const char *> bccFiles = { BCC_EXE_PATH,
                                                core_lib,
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index 2f1991f..6059825 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef RSD_BCC_H
-#define RSD_BCC_H
+#ifndef RSD_CPU_SCRIPT_H
+#define RSD_CPU_SCRIPT_H
 
 #include <rs_hal.h>
 #include <rsRuntime.h>
@@ -161,4 +161,4 @@
 
 }
 
-#endif
+#endif  // RSD_CPU_SCRIPT_H