1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-08 16:36:10 +00:00

SmsFetcher: improve robustness of the synchronization

This commit is contained in:
Loic Blot 2016-11-02 08:03:51 +01:00
parent e8ce83a232
commit 8212ef63aa

View File

@ -59,9 +59,21 @@ public class SmsFetcher {
String existingIDs = buildExistingMessagesString(mbID);
Cursor c = new SmsDataProvider(_context).queryNonExistingMessages(mbID.getURI(), existingIDs);
if (c == null) {
return;
}
if (c.getCount() == 0) {
c.close();
return;
}
if (!c.moveToFirst()) {
c.close();
return;
}
// Reading mailbox
if ((c != null) && (c.getCount() > 0)) {
c.moveToFirst();
do {
JSONObject entry = new JSONObject();
@ -81,12 +93,8 @@ public class SmsFetcher {
while (c.moveToNext());
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
}
if (c != null) {
c.close();
}
}
// Used by Content Observer
public JSONArray getLastMessage(MailboxID mbID) {
@ -100,7 +108,17 @@ public class SmsFetcher {
return null;
}
c.moveToNext();
// or for a reason count returns zero value
if (c.getCount() == 0) {
c.close();
return null;
}
// If no first message into cursor
if (!c.moveToFirst()) {
c.close();
return null;
}
// We create a list of strings to store results
JSONArray results = new JSONArray();
@ -153,9 +171,21 @@ public class SmsFetcher {
Log.i(SmsFetcher.TAG, "No message retrieved.");
}
if (c == null) {
return;
}
if (c.getCount() == 0) {
c.close();
return;
}
// Reading mailbox
if ((c != null) && (c.getCount() > 0)) {
c.moveToFirst();
if (!c.moveToFirst()) {
c.close();
return;
}
do {
JSONObject entry = new JSONObject();
@ -174,12 +204,8 @@ public class SmsFetcher {
while (c.moveToNext());
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
}
if (c != null) {
c.close();
}
}
private Integer handleProviderColumn(Cursor c, int idx, JSONObject entry) throws JSONException {
String colName = c.getColumnName(idx);