From fd35ddcc65faedfda8148538384393b60c3e349a Mon Sep 17 00:00:00 2001 From: Micha? Gregorczyk Date: Mon, 18 Apr 2016 11:44:51 -0700 Subject: [PATCH] Store lock file in persistent directory. Reviewed By: tadeuzagallo Differential Revision: D3190827 fb-gh-sync-id: 42dd65bccd7c248989475f68c81061079e3601a4 fbshipit-source-id: 42dd65bccd7c248989475f68c81061079e3601a4 --- .../src/main/jni/react/jni/OnLoad.cpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index b9c4240d3..478eda666 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -853,7 +853,7 @@ static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) { namespace executors { -std::string getDeviceCacheDir() { +static std::string getApplicationDir(const char* methodName) { // Get the Application Context object auto getApplicationClass = findClassLocal( "com/facebook/react/common/ApplicationHolder"); @@ -864,23 +864,32 @@ std::string getDeviceCacheDir() { auto application = getApplicationMethod(getApplicationClass); // Get getCacheDir() from the context - auto getCacheDirMethod = findClassLocal("android/app/Application") - ->getMethod("getCacheDir", - "()Ljava/io/File;" + auto getDirMethod = findClassLocal("android/app/Application") + ->getMethod(methodName, + "()Ljava/io/File;" ); - auto cacheDirObj = getCacheDirMethod(application); + auto dirObj = getDirMethod(application); // Call getAbsolutePath() on the returned File object auto getAbsolutePathMethod = findClassLocal("java/io/File") ->getMethod("getAbsolutePath"); - return getAbsolutePathMethod(cacheDirObj)->toStdString(); + return getAbsolutePathMethod(dirObj)->toStdString(); +} + +static std::string getApplicationCacheDir() { + return getApplicationDir("getCacheDir"); +} + +static std::string getApplicationPersistentDir() { + return getApplicationDir("getFilesDir"); } struct CountableJSCExecutorFactory : CountableJSExecutorFactory { public: CountableJSCExecutorFactory(folly::dynamic jscConfig) : m_jscConfig(jscConfig) {} virtual std::unique_ptr createJSExecutor(Bridge *bridge) override { - return JSCExecutorFactory(getDeviceCacheDir(), m_jscConfig).createJSExecutor(bridge); + m_jscConfig["PersistentDirectory"] = getApplicationPersistentDir(); + return JSCExecutorFactory(getApplicationCacheDir(), m_jscConfig).createJSExecutor(bridge); } private: