increase cursor window size on Android P when restoring messages

This commit is contained in:
Daniel Gultsch 2019-12-02 13:20:53 +01:00
parent 10c5d151d3
commit a99d7a7400
3 changed files with 26 additions and 5 deletions

View file

@ -90,7 +90,7 @@ public final class Config {
public static final int REFRESH_UI_INTERVAL = 500; public static final int REFRESH_UI_INTERVAL = 500;
public static final int MAX_DISPLAY_MESSAGE_CHARS = 4096; public static final int MAX_DISPLAY_MESSAGE_CHARS = 4096;
public static final int MAX_STORAGE_MESSAGE_CHARS = 1024 * 1024; //1MB public static final int MAX_STORAGE_MESSAGE_CHARS = 2 * 1024 * 1024; //2MB
public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000; public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;

View file

@ -52,6 +52,7 @@ import eu.siacs.conversations.entities.ServiceDiscoveryResult;
import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.services.ShortcutService; import eu.siacs.conversations.services.ShortcutService;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.CursorUtils;
import eu.siacs.conversations.utils.FtsUtils; import eu.siacs.conversations.utils.FtsUtils;
import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.Resolver; import eu.siacs.conversations.utils.Resolver;
@ -754,12 +755,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
null, null, Message.TIME_SENT + " DESC", null, null, Message.TIME_SENT + " DESC",
String.valueOf(limit)); String.valueOf(limit));
} }
CursorUtils.upgradeCursorWindowSize(cursor);
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
try { try {
final Message message = Message.fromCursor(cursor, conversation); list.add(0, Message.fromCursor(cursor, conversation));
if (message != null) {
list.add(0, message);
}
} catch (Exception e) { } catch (Exception e) {
Log.e(Config.LOGTAG,"unable to restore message"); Log.e(Config.LOGTAG,"unable to restore message");
} }

View file

@ -0,0 +1,22 @@
package eu.siacs.conversations.utils;
import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.database.CursorWindow;
import android.database.sqlite.SQLiteCursor;
public class CursorUtils {
public static void upgradeCursorWindowSize(final Cursor cursor) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
if (cursor instanceof AbstractWindowedCursor) {
final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor;
windowedCursor.setWindow(new CursorWindow("8k", 8 * 1024 * 1024));
}
if (cursor instanceof SQLiteCursor) {
((SQLiteCursor) cursor).setFillWindowForwardOnly(true);
}
}
}
}