Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def useDedicatedExecutor = rootProject.hasProperty('AsyncStorage_dedicatedExecut
? rootProject.properties['AsyncStorage_dedicatedExecutor']
: false

def disableLocalizedCollators = rootProject.hasProperty('AsyncStorage_noLocalizedCollators')
? rootProject.properties['AsyncStorage_noLocalizedCollators']
: false
Comment thread
krizzu marked this conversation as resolved.
Outdated

apply plugin: 'com.android.library'

android {
Expand All @@ -43,6 +47,7 @@ android {
targetSdkVersion safeExtGet('targetSdkVersion', 28)
buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
buildConfigField("boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}")
buildConfigField("boolean", "AsyncStorage_noLocalizedCollators", "${disableLocalizedCollators}")
}
lintOptions {
abortOnError false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand All @@ -33,7 +34,7 @@

@ReactModule(name = AsyncStorageModule.NAME)
public final class AsyncStorageModule
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable {
extends ReactContextBaseJavaModule implements ModuleDataCleaner.Cleanable, LifecycleEventListener {

// changed name to not conflict with AsyncStorage from RN repo
public static final String NAME = "RNC_AsyncSQLiteDBStorage";
Expand Down Expand Up @@ -91,6 +92,7 @@ public AsyncStorageModule(ReactApplicationContext reactContext) {
AsyncStorageModule(ReactApplicationContext reactContext, Executor executor) {
super(reactContext);
this.executor = new SerialExecutor(executor);
reactContext.addLifecycleEventListener(this);
mReactDatabaseSupplier = ReactDatabaseSupplier.getInstance(reactContext);
}

Expand Down Expand Up @@ -118,6 +120,18 @@ public void clearSensitiveData() {
mReactDatabaseSupplier.clearAndCloseDatabase();
}

@Override
public void onHostResume() {}

@Override
public void onHostPause() {}

@Override
public void onHostDestroy() {
// ensure we close database when activity is destroyed
mReactDatabaseSupplier.closeDatabase();
}

/**
* Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
* (key, null) for the keys that haven't been found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ReactDatabaseSupplier extends SQLiteOpenHelper {
private Context mContext;
private @Nullable SQLiteDatabase mDb;
private long mMaximumDatabaseSize = BuildConfig.AsyncStorage_db_size * 1024L * 1024L;
private boolean disableLocalizedCollators = BuildConfig.AsyncStorage_noLocalizedCollators;

private ReactDatabaseSupplier(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand Down Expand Up @@ -85,7 +86,13 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (tries > 0) {
deleteDatabase();
}
mDb = getWritableDatabase();

if(disableLocalizedCollators) {
Comment thread
krizzu marked this conversation as resolved.
Outdated
String dbPath = mContext.getDatabasePath(DATABASE_NAME).getPath();
mDb = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE);
} else {
mDb = getWritableDatabase();
}
break;
} catch (SQLiteException e) {
lastSQLiteException = e;
Expand Down Expand Up @@ -151,7 +158,7 @@ private synchronized boolean deleteDatabase() {
return mContext.deleteDatabase(DATABASE_NAME);
}

private synchronized void closeDatabase() {
public synchronized void closeDatabase() {
if (mDb != null && mDb.isOpen()) {
mDb.close();
mDb = null;
Expand Down
1 change: 1 addition & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

# Enable dedicated thread pool executor
AsyncStorage_dedicatedExecutor=true
AsyncStorage_noLocalizedCollators=true

android.useAndroidX=true
android.enableJetifier=true