Skip to content

Commit

Permalink
Store lock file in persistent directory.
Browse files Browse the repository at this point in the history
Reviewed By: tadeuzagallo

Differential Revision: D3190827

fb-gh-sync-id: 42dd65bccd7c248989475f68c81061079e3601a4
fbshipit-source-id: 42dd65bccd7c248989475f68c81061079e3601a4
  • Loading branch information
Micha? Gregorczyk authored and samerce committed Aug 23, 2016
1 parent 950412e commit 5c4070b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions ReactAndroid/src/main/jni/react/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -864,23 +864,32 @@ std::string getDeviceCacheDir() {
auto application = getApplicationMethod(getApplicationClass);

// Get getCacheDir() from the context
auto getCacheDirMethod = findClassLocal("android/app/Application")
->getMethod<jobject()>("getCacheDir",
"()Ljava/io/File;"
auto getDirMethod = findClassLocal("android/app/Application")
->getMethod<jobject()>(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<jstring()>("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<JSExecutor> createJSExecutor(Bridge *bridge) override {
return JSCExecutorFactory(getDeviceCacheDir(), m_jscConfig).createJSExecutor(bridge);
m_jscConfig["PersistentDirectory"] = getApplicationPersistentDir();
return JSCExecutorFactory(getApplicationCacheDir(), m_jscConfig).createJSExecutor(bridge);
}

private:
Expand Down

0 comments on commit 5c4070b

Please sign in to comment.