@@ -311,28 +311,32 @@ public void delete(@NonNull String table, @Nullable String whereClause, @Nullabl
311
311
312
312
@ Override
313
313
public void onCreate (SQLiteDatabase db ) {
314
- db .execSQL (SQL_CREATE_ENTRIES );
315
- db .execSQL (SQL_CREATE_OUTCOME_ENTRIES_V3 );
316
- db .execSQL (SQL_CREATE_UNIQUE_OUTCOME_ENTRIES_V2 );
317
- db .execSQL (SQL_CREATE_IN_APP_MESSAGE_ENTRIES );
318
- for (String ind : SQL_INDEX_ENTRIES ) {
319
- db .execSQL (ind );
314
+ synchronized (LOCK ) {
315
+ db .execSQL (SQL_CREATE_ENTRIES );
316
+ db .execSQL (SQL_CREATE_OUTCOME_ENTRIES_V3 );
317
+ db .execSQL (SQL_CREATE_UNIQUE_OUTCOME_ENTRIES_V2 );
318
+ db .execSQL (SQL_CREATE_IN_APP_MESSAGE_ENTRIES );
319
+ for (String ind : SQL_INDEX_ENTRIES ) {
320
+ db .execSQL (ind );
321
+ }
320
322
}
321
323
}
322
324
323
325
@ Override
324
326
public void onUpgrade (SQLiteDatabase db , int oldVersion , int newVersion ) {
325
327
OneSignal .Log (OneSignal .LOG_LEVEL .DEBUG , "OneSignal Database onUpgrade from: " + oldVersion + " to: " + newVersion );
326
- try {
327
- internalOnUpgrade (db , oldVersion );
328
- } catch (SQLiteException e ) {
329
- // This could throw if rolling back then forward again.
330
- // However this shouldn't happen as we clearing the database on onDowngrade
331
- OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "Error in upgrade, migration may have already run! Skipping!" , e );
328
+ synchronized (LOCK ) {
329
+ try {
330
+ internalOnUpgrade (db , oldVersion );
331
+ } catch (SQLiteException e ) {
332
+ // This could throw if rolling back then forward again.
333
+ // However this shouldn't happen as we clearing the database on onDowngrade
334
+ OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "Error in upgrade, migration may have already run! Skipping!" , e );
335
+ }
332
336
}
333
337
}
334
338
335
- private synchronized void internalOnUpgrade (SQLiteDatabase db , int oldVersion ) {
339
+ private void internalOnUpgrade (SQLiteDatabase db , int oldVersion ) {
336
340
if (oldVersion < 2 )
337
341
upgradeToV2 (db );
338
342
@@ -404,7 +408,7 @@ private static void upgradeToV7(SQLiteDatabase db) {
404
408
safeExecSQL (db , SQL_CREATE_IN_APP_MESSAGE_ENTRIES );
405
409
}
406
410
407
- private synchronized void upgradeToV8 (SQLiteDatabase db ) {
411
+ private void upgradeToV8 (SQLiteDatabase db ) {
408
412
outcomeTableProvider .upgradeOutcomeTableRevision2To3 (db );
409
413
outcomeTableProvider .upgradeCacheOutcomeTableRevision1To2 (db );
410
414
}
@@ -420,24 +424,25 @@ private static void safeExecSQL(SQLiteDatabase db, String sql) {
420
424
@ Override
421
425
public void onDowngrade (SQLiteDatabase db , int oldVersion , int newVersion ) {
422
426
OneSignal .Log (OneSignal .LOG_LEVEL .WARN , "SDK version rolled back! Clearing " + DATABASE_NAME + " as it could be in an unexpected state." );
427
+ synchronized (LOCK ) {
428
+ Cursor cursor = db .rawQuery ("SELECT name FROM sqlite_master WHERE type='table'" , null );
429
+ try {
430
+ List <String > tables = new ArrayList <>(cursor .getCount ());
423
431
424
- Cursor cursor = db .rawQuery ("SELECT name FROM sqlite_master WHERE type='table'" , null );
425
- try {
426
- List <String > tables = new ArrayList <>(cursor .getCount ());
427
-
428
- while (cursor .moveToNext ())
429
- tables .add (cursor .getString (0 ));
432
+ while (cursor .moveToNext ())
433
+ tables .add (cursor .getString (0 ));
430
434
431
- for (String table : tables ) {
432
- if (table .startsWith ("sqlite_" ))
433
- continue ;
434
- db .execSQL ("DROP TABLE IF EXISTS " + table );
435
+ for (String table : tables ) {
436
+ if (table .startsWith ("sqlite_" ))
437
+ continue ;
438
+ db .execSQL ("DROP TABLE IF EXISTS " + table );
439
+ }
440
+ } finally {
441
+ cursor .close ();
435
442
}
436
- } finally {
437
- cursor .close ();
438
- }
439
443
440
- onCreate (db );
444
+ onCreate (db );
445
+ }
441
446
}
442
447
443
448
static StringBuilder recentUninteractedWithNotificationsWhere () {
0 commit comments