|
|
@ -25,11 +25,12 @@ import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
|
|
|
@ -134,23 +135,6 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
super.init(configuration);
|
|
|
|
super.init(configuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected InvalidationTracker createInvalidationTracker() {
|
|
|
|
|
|
|
|
final HashMap<String, String> _shadowTablesMap = new HashMap<String, String>(0);
|
|
|
|
|
|
|
|
HashMap<String, Set<String>> _viewTables = new HashMap<String, Set<String>>(3);
|
|
|
|
|
|
|
|
HashSet<String> _tables = new HashSet<String>(1);
|
|
|
|
|
|
|
|
//_tables.add("account");
|
|
|
|
|
|
|
|
_viewTables.put("account_view", _tables);
|
|
|
|
|
|
|
|
HashSet<String> _tables_1 = new HashSet<String>(1);
|
|
|
|
|
|
|
|
//_tables_1.add("identity");
|
|
|
|
|
|
|
|
_viewTables.put("identity_view", _tables_1);
|
|
|
|
|
|
|
|
HashSet<String> _tables_2 = new HashSet<String>(1);
|
|
|
|
|
|
|
|
//_tables_2.add("folder");
|
|
|
|
|
|
|
|
_viewTables.put("folder_view", _tables_2);
|
|
|
|
|
|
|
|
return new InvalidationTracker(this, _shadowTablesMap, _viewTables, DB_TABLES);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void setupViewInvalidation(Context context) {
|
|
|
|
static void setupViewInvalidation(Context context) {
|
|
|
|
// This needs to be done on a foreground thread
|
|
|
|
// This needs to be done on a foreground thread
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
@ -176,7 +160,7 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
if (changed) {
|
|
|
|
if (changed) {
|
|
|
|
Log.i("Invalidating account view");
|
|
|
|
Log.i("Invalidating account view");
|
|
|
|
last = accounts;
|
|
|
|
last = accounts;
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("account_view");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -202,7 +186,7 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
if (changed) {
|
|
|
|
if (changed) {
|
|
|
|
Log.i("Invalidating identity view");
|
|
|
|
Log.i("Invalidating identity view");
|
|
|
|
last = identities;
|
|
|
|
last = identities;
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("identity_view");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -228,7 +212,7 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
if (changed) {
|
|
|
|
if (changed) {
|
|
|
|
Log.i("Invalidating folder view");
|
|
|
|
Log.i("Invalidating folder view");
|
|
|
|
last = folders;
|
|
|
|
last = folders;
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("message");
|
|
|
|
db.getInvalidationTracker().notifyObserversByTableNames("folder_view");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -240,6 +224,29 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
|
|
|
|
|
|
|
|
sInstance = migrate(acontext, getBuilder(acontext)).build();
|
|
|
|
sInstance = migrate(acontext, getBuilder(acontext)).build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Log.i("Disabling view invalidation");
|
|
|
|
|
|
|
|
Field fmTableNames = InvalidationTracker.class.getDeclaredField("mTableNames");
|
|
|
|
|
|
|
|
Field fmViewTables = InvalidationTracker.class.getDeclaredField("mViewTables");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmTableNames.setAccessible(true);
|
|
|
|
|
|
|
|
fmViewTables.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Set<String>> mViewTables = (Map) fmViewTables.get(sInstance.getInvalidationTracker());
|
|
|
|
|
|
|
|
mViewTables.get("account_view").clear();
|
|
|
|
|
|
|
|
mViewTables.get("identity_view").clear();
|
|
|
|
|
|
|
|
mViewTables.get("folder_view").clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> tableNames = new ArrayList<>(Arrays.asList(DB_TABLES));
|
|
|
|
|
|
|
|
tableNames.addAll(mViewTables.keySet());
|
|
|
|
|
|
|
|
Log.i("Observing invalidation tables=" + TextUtils.join(",", tableNames));
|
|
|
|
|
|
|
|
fmTableNames.set(sInstance.getInvalidationTracker(), tableNames.toArray(new String[0]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Disabled view invalidation");
|
|
|
|
|
|
|
|
} catch (ReflectiveOperationException ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sInstance.getInvalidationTracker().addObserver(new InvalidationTracker.Observer(DB.DB_TABLES) {
|
|
|
|
sInstance.getInvalidationTracker().addObserver(new InvalidationTracker.Observer(DB.DB_TABLES) {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onInvalidated(@NonNull Set<String> tables) {
|
|
|
|
public void onInvalidated(@NonNull Set<String> tables) {
|
|
|
|