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:
parent
e8ce83a232
commit
8212ef63aa
@ -59,9 +59,21 @@ public class SmsFetcher {
|
|||||||
String existingIDs = buildExistingMessagesString(mbID);
|
String existingIDs = buildExistingMessagesString(mbID);
|
||||||
Cursor c = new SmsDataProvider(_context).queryNonExistingMessages(mbID.getURI(), existingIDs);
|
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
|
// Reading mailbox
|
||||||
if ((c != null) && (c.getCount() > 0)) {
|
|
||||||
c.moveToFirst();
|
|
||||||
do {
|
do {
|
||||||
JSONObject entry = new JSONObject();
|
JSONObject entry = new JSONObject();
|
||||||
|
|
||||||
@ -81,12 +93,8 @@ public class SmsFetcher {
|
|||||||
while (c.moveToNext());
|
while (c.moveToNext());
|
||||||
|
|
||||||
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
|
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
|
||||||
}
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Used by Content Observer
|
// Used by Content Observer
|
||||||
public JSONArray getLastMessage(MailboxID mbID) {
|
public JSONArray getLastMessage(MailboxID mbID) {
|
||||||
@ -100,7 +108,17 @@ public class SmsFetcher {
|
|||||||
return null;
|
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
|
// We create a list of strings to store results
|
||||||
JSONArray results = new JSONArray();
|
JSONArray results = new JSONArray();
|
||||||
@ -153,9 +171,21 @@ public class SmsFetcher {
|
|||||||
Log.i(SmsFetcher.TAG, "No message retrieved.");
|
Log.i(SmsFetcher.TAG, "No message retrieved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getCount() == 0) {
|
||||||
|
c.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Reading mailbox
|
// Reading mailbox
|
||||||
if ((c != null) && (c.getCount() > 0)) {
|
if (!c.moveToFirst()) {
|
||||||
c.moveToFirst();
|
c.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
JSONObject entry = new JSONObject();
|
JSONObject entry = new JSONObject();
|
||||||
|
|
||||||
@ -174,12 +204,8 @@ public class SmsFetcher {
|
|||||||
while (c.moveToNext());
|
while (c.moveToNext());
|
||||||
|
|
||||||
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
|
Log.i(SmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI());
|
||||||
}
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Integer handleProviderColumn(Cursor c, int idx, JSONObject entry) throws JSONException {
|
private Integer handleProviderColumn(Cursor c, int idx, JSONObject entry) throws JSONException {
|
||||||
String colName = c.getColumnName(idx);
|
String colName = c.getColumnName(idx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user