Set the default cachedir during context create.
- Use JNI reflection to access RenderScriptCacheDir.mCacheDir, and set
it immediately after the context is created.
- Java or C++ APIs could still call ContextSetCacheDir to override it.
- The JNI query is guarded by std::unique_lock to make sure that the
current thread is the only one attached to JNI.
- This change ensures that vendors could always get a valid code cache
dir even with support lib path, as RenderScriptCacheDir.mCacheDir is
set by ActivityThread.java when launching the application, regardless
of using RenderScript or not.
Bug: 34396220
Test: mm, CTS tests pass, tested with RSTest_CompatLib to make sure that
support lib path is covered.
Change-Id: I542ed2fe03e34b72e85398271b748c0053a35ae3
diff --git a/rsContext.cpp b/rsContext.cpp
index fabfa6b..21e8408 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -469,14 +469,12 @@
}
void Context::setCacheDir(const char * cacheDir_arg, uint32_t length) {
- if (!hasSetCacheDir) {
- if (length <= PATH_MAX) {
- memcpy(mCacheDir, cacheDir_arg, length);
- mCacheDir[length] = 0;
- hasSetCacheDir = true;
- } else {
- setError(RS_ERROR_BAD_VALUE, "Invalid path");
- }
+ if (length <= PATH_MAX) {
+ memcpy(mCacheDir, cacheDir_arg, length);
+ mCacheDir[length] = 0;
+ hasSetCacheDir = true;
+ } else {
+ setError(RS_ERROR_BAD_VALUE, "Invalid path");
}
}