MCPcopy Create free account
hub / github.com/M66B/FairEmail / init

Method init

app/src/main/java/eu/faircode/email/DB.java:203–264  ·  view source on GitHub ↗
(@NonNull DatabaseConfiguration configuration)

Source from the content-addressed store, hash-verified

201 }
202
203 @Override
204 public void init(@NonNull DatabaseConfiguration configuration) {
205 File dbfile = configuration.context.getDatabasePath(DB_NAME);
206
207 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(configuration.context);
208 boolean sqlite_integrity_check = prefs.getBoolean("sqlite_integrity_check", false);
209
210 // https://www.sqlite.org/pragma.html#pragma_integrity_check
211 if (sqlite_integrity_check && dbfile.exists()) {
212 String check = (Helper.isRedmiNote() || Helper.isOnePlus() || Helper.isOppo() || BuildConfig.DEBUG
213 ? "integrity_check" : "quick_check");
214 try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) {
215 Log.i("PRAGMA " + check);
216 try (Cursor cursor = db.rawQuery("PRAGMA " + check + ";", null)) {
217 while (cursor.moveToNext()) {
218 String line = cursor.getString(0);
219 if ("ok".equals(line))
220 Log.i("PRAGMA " + check + "=" + line);
221 else
222 Log.e("PRAGMA " + check + "=" + line);
223 }
224 }
225 } catch (SQLiteDatabaseCorruptException ex) {
226 Log.e(ex);
227 Helper.secureDelete(dbfile);
228 } catch (Throwable ex) {
229 Log.e(ex);
230 /*
231 java.lang.String, java.lang.String, android.os.Bundle)' on a null object reference
232 at android.provider.Settings$NameValueCache.getStringForUser(Settings.java:3002)
233 at android.provider.Settings$Global.getStringForUser(Settings.java:16253)
234 at android.provider.Settings$Global.getString(Settings.java:16241)
235 at android.database.sqlite.SQLiteCompatibilityWalFlags.initIfNeeded(SQLiteCompatibilityWalFlags.java:105)
236 at android.database.sqlite.SQLiteCompatibilityWalFlags.isLegacyCompatibilityWalEnabled(SQLiteCompatibilityWalFlags.java:57)
237 at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:321)
238 at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:788)
239 at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:737)
240 at eu.faircode.email.DB.init(SourceFile:61)
241 at androidx.room.RoomDatabase$Builder.build(SourceFile:274)
242 at eu.faircode.email.DB.getInstance(SourceFile:106)
243 at eu.faircode.email.DB.setupViewInvalidation(SourceFile:1)
244 at eu.faircode.email.ApplicationEx.onCreate(SourceFile:140)
245 at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1229)
246 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6719)
247 */
248 }
249 }
250
251 // https://www.sqlite.org/pragma.html#pragma_wal_autocheckpoint
252 if (BuildConfig.DEBUG && dbfile.exists()) {
253 try (SQLiteDatabase db = SQLiteDatabase.openDatabase(dbfile.getPath(), null, SQLiteDatabase.OPEN_READWRITE)) {
254 Log.i("Set PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT);
255 try (Cursor cursor = db.rawQuery("PRAGMA wal_autocheckpoint=" + DB_CHECKPOINT + ";", null)) {
256 cursor.moveToNext(); // required
257 }
258 } catch (Throwable ex) {
259 Log.e(ex);
260 }

Callers 14

uploadMethod · 0.45
getMetadataMethod · 0.45
verifiedConnectMethod · 0.45
getDefaultMethod · 0.45
transformMethod · 0.45
toUriMethod · 0.45
fromUriMethod · 0.45
onExecuteMethod · 0.45
onCreateDialogMethod · 0.45
getTrustManagersMethod · 0.45
getCiphersMethod · 0.45

Calls 12

isRedmiNoteMethod · 0.95
isOnePlusMethod · 0.95
isOppoMethod · 0.95
iMethod · 0.95
eMethod · 0.95
secureDeleteMethod · 0.95
getBooleanMethod · 0.80
moveToNextMethod · 0.80
existsMethod · 0.45
getPathMethod · 0.45
getStringMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected