Skip to content

Commit 2632466

Browse files
committed
Fixed handling of SQLiteFullException
* Also lowered locally stored notifications from 28 days to 7 days.
1 parent f967d55 commit 2632466

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotification.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,13 @@ private static void createSummaryIdDatabaseEntry(OneSignalDbHelper dbHelper, Str
623623
} catch (Throwable t) {
624624
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error adding summary notification record! ", t);
625625
} finally {
626-
if (writableDb != null)
627-
writableDb.endTransaction();
626+
if (writableDb != null) {
627+
try {
628+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
629+
} catch (Throwable t) {
630+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
631+
}
632+
}
628633
}
629634
}
630635

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,23 @@ static void saveNotification(NotificationGenerationJob notifiJob, boolean opened
173173
} catch (Exception e) {
174174
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error saving notification record! ", e);
175175
} finally {
176-
if (writableDb != null)
177-
writableDb.endTransaction();
176+
if (writableDb != null) {
177+
try {
178+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
179+
} catch (Throwable t) {
180+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
181+
}
182+
}
178183
}
179184
} catch (JSONException e) {
180185
e.printStackTrace();
181186
}
182187
}
183188

184-
// Clean up old records after 4 weeks.
189+
// Clean up old records after 1 week.
185190
static void deleteOldNotifications(SQLiteDatabase writableDb) {
186191
writableDb.delete(NotificationTable.TABLE_NAME,
187-
NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1000L) - 2419200L),
192+
NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1000L) - 604800L),
188193
null);
189194
}
190195

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ static void processIntent(Context context, Intent intent) {
103103
} catch (Exception e) {
104104
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error processing notification open or dismiss record! ", e);
105105
} finally {
106-
if (writableDb != null)
107-
writableDb.endTransaction();
106+
if (writableDb != null) {
107+
try {
108+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
109+
} catch (Throwable t) {
110+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
111+
}
112+
}
108113
}
109114

110115
if (!dismissed)

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationRestorer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ public static void restore(Context context) {
7272
} catch (Throwable t) {
7373
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error deleting old notification records! ", t);
7474
} finally {
75-
if (writableDb != null)
76-
writableDb.endTransaction();
75+
if (writableDb != null) {
76+
try {
77+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
78+
} catch (Throwable t) {
79+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
80+
}
81+
}
7782
}
7883

7984
Cursor cursor = null;

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,13 @@ public static void clearOneSignalNotifications() {
14481448
} catch (Throwable t) {
14491449
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error marking all notifications as dismissed! ", t);
14501450
} finally {
1451-
if (writableDb != null)
1452-
writableDb.endTransaction();
1451+
if (writableDb != null) {
1452+
try {
1453+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
1454+
} catch (Throwable t) {
1455+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
1456+
}
1457+
}
14531458
}
14541459

14551460
BadgeCountUpdater.updateCount(0, appContext);
@@ -1490,8 +1495,13 @@ public static void cancelNotification(int id) {
14901495
} catch (Throwable t) {
14911496
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error marking a notification id " + id + " as dismissed! ", t);
14921497
} finally {
1493-
if (writableDb != null)
1494-
writableDb.endTransaction();
1498+
if (writableDb != null) {
1499+
try {
1500+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
1501+
} catch (Throwable t) {
1502+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
1503+
}
1504+
}
14951505
}
14961506

14971507
NotificationManager notificationManager = (NotificationManager)appContext.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -1561,8 +1571,13 @@ public static void cancelGroupedNotifications(String group) {
15611571
} catch (Throwable t) {
15621572
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error marking a notifications with group " + group + " as dismissed! ", t);
15631573
} finally {
1564-
if (writableDb != null)
1565-
writableDb.endTransaction();
1574+
if (writableDb != null) {
1575+
try {
1576+
writableDb.endTransaction(); // May throw if transaction was never opened or DB is full.
1577+
} catch (Throwable t) {
1578+
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Error closing transaction! ", t);
1579+
}
1580+
}
15661581
}
15671582
}
15681583

0 commit comments

Comments
 (0)