Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cacheDir for setting TMPDIR env to solve android 12 issue #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android/cpp-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ struct QuickSQLiteBridge : jni::JavaClass<QuickSQLiteBridge> {
static void installNativeJsi(
jni::alias_ref<jni::JObject> thiz, jlong jsiRuntimePtr,
jni::alias_ref<react::CallInvokerHolder::javaobject> jsCallInvokerHolder,
jni::alias_ref<jni::JString> docPath) {
jni::alias_ref<jni::JString> docPath,
jni::alias_ref<jni::JString> cachePath) {
auto jsiRuntime = reinterpret_cast<jsi::Runtime *>(jsiRuntimePtr);
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
std::string docPathString = docPath->toStdString();
std::string cachePathString = cachePath->toStdString();

osp::install(*jsiRuntime, jsCallInvoker, docPathString.c_str());
osp::install(*jsiRuntime, jsCallInvoker, docPathString.c_str(), cachePathString.c_str());
}

static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;

public class QuickSQLiteBridge {
private native void installNativeJsi(long jsContextNativePointer, CallInvokerHolderImpl jsCallInvokerHolder, String docPath);
private native void installNativeJsi(long jsContextNativePointer, CallInvokerHolderImpl jsCallInvokerHolder, String docPath, String cachePath);
private native void clearStateNativeJsi();
public static final QuickSQLiteBridge instance = new QuickSQLiteBridge();

public void install(ReactContext context) {
long jsContextPointer = context.getJavaScriptContextHolder().get();
CallInvokerHolderImpl jsCallInvokerHolder = (CallInvokerHolderImpl)context.getCatalystInstance().getJSCallInvokerHolder();
final String path = context.getFilesDir().getAbsolutePath();
final String cachePath = context.getCacheDir().getAbsolutePath();

installNativeJsi(
jsContextPointer,
jsCallInvokerHolder,
path
path,
cachePath
);
}

Expand Down
6 changes: 5 additions & 1 deletion cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include "macros.h"
#include <iostream>
#include <stdlib.h>

using namespace std;
using namespace facebook;
Expand All @@ -21,8 +22,11 @@ void clearState() {
sqliteCloseAll();
}

void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker, const char *docPath)
void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker, const char *docPath, const char *cachePath)
{
// android 12 fix
setenv("TMPDIR", cachePath, 1);

docPathStr = std::string(docPath);
auto pool = std::make_shared<ThreadPool>();
invoker = jsCallInvoker;
Expand Down
2 changes: 1 addition & 1 deletion cpp/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace facebook;

namespace osp {
void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker, const char *docPath);
void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker, const char *docPath, const char *cachePath);
void clearState();
}

3 changes: 2 additions & 1 deletion ios/QuickSQLite.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ @implementation QuickSQLite
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
documentPath = [paths objectAtIndex:0];
}
NSString *cachePath = NSTemporaryDirectory();

osp::install(runtime, callInvoker, [documentPath UTF8String]);
osp::install(runtime, callInvoker, [documentPath UTF8String], [cachePath UTF8String]);
return @true;
}

Expand Down