mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-07 16:06:18 +00:00
Add some useful logging to permit better troubleshoot, and various fixes
* Properly close cursors for database * Implement filtering for sender number size * Remove systemd strings for chinese translation
This commit is contained in:
parent
0e71ca5fa1
commit
00000e84c6
@ -38,6 +38,7 @@ import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.widget.Toast;
|
||||
@ -126,6 +127,7 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
public void syncAllMessages () {
|
||||
Log.v(MainActivity.TAG, "Launch syncAllMessages()");
|
||||
if (!PermissionChecker.checkPermission(this, Manifest.permission.READ_SMS,
|
||||
REQUEST_SMS)) {
|
||||
return;
|
||||
@ -147,6 +149,7 @@ public class MainActivity extends AppCompatActivity
|
||||
else {
|
||||
Toast.makeText(ctx, ctx.getString(R.string.err_sync_no_connection_available), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
Log.v(MainActivity.TAG, "Finish syncAllMessages()");
|
||||
}
|
||||
|
||||
private boolean openMyAccounts () {
|
||||
@ -202,4 +205,6 @@ public class MainActivity extends AppCompatActivity
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public interface ASyncSMSSync {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Log.d(ASyncSMSSync.TAG, "Starting background sync");
|
||||
// Get ownCloud SMS account list
|
||||
AccountManager _accountMgr = AccountManager.get(_context);
|
||||
Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type));
|
||||
@ -62,6 +63,7 @@ public interface ASyncSMSSync {
|
||||
}
|
||||
}
|
||||
OCSMSNotificationUI.cancel(_context);
|
||||
Log.d(ASyncSMSSync.TAG, "Stopping background sync");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -104,15 +104,16 @@ public class SmsFetcher {
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
while (c.moveToNext());
|
||||
|
||||
Log.d(SmsFetcher.TAG, c.getCount() + " messages read from " + mbURI);
|
||||
|
||||
c.close();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Used by Content Observer
|
||||
@ -235,15 +236,16 @@ public class SmsFetcher {
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
while (c.moveToNext());
|
||||
|
||||
Log.d(SmsFetcher.TAG, c.getCount() + " messages read from " + mbURI);
|
||||
|
||||
c.close();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
private String mapMailboxIDToURI(MailboxID mbID) {
|
||||
|
@ -23,6 +23,7 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||
|
||||
@ -36,7 +37,7 @@ public class SmsDataProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Cursor query(String mailBox) {
|
||||
@ -46,7 +47,9 @@ public class SmsDataProvider extends ContentProvider {
|
||||
);
|
||||
}
|
||||
|
||||
// NOTE: in APIv2 this call should be modified to use date instead of _id which is likely unique
|
||||
public Cursor queryNonExistingMessages(String mailBox, String existingIds) {
|
||||
Log.d(SmsDataProvider.TAG, "queryNonExistingMessages !");
|
||||
if (!existingIds.isEmpty()) {
|
||||
return query(Uri.parse(mailBox),
|
||||
new String[] { "read", "date", "address", "seen", "body", "_id", "type", },
|
||||
@ -58,6 +61,7 @@ public class SmsDataProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
public Cursor queryMessagesSinceDate(String mailBox, Long sinceDate) {
|
||||
Log.d(SmsDataProvider.TAG, "queryMessagesSinceDate !");
|
||||
return query(Uri.parse(mailBox),
|
||||
new String[] { "read", "date", "address", "seen", "body", "_id", "type", },
|
||||
"date > ?", new String[] { sinceDate.toString() }, null
|
||||
@ -67,20 +71,51 @@ public class SmsDataProvider extends ContentProvider {
|
||||
@Override
|
||||
public Cursor query(@NonNull Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder) {
|
||||
if ((_context == null) || (_context.getContentResolver() == null)) {
|
||||
Log.e(SmsDataProvider.TAG, "query: context is null or content resolver is null, abort.");
|
||||
return null;
|
||||
}
|
||||
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
|
||||
Integer bulkLimit = prefs.getSyncBulkLimit();
|
||||
//Integer senderMinSize = prefs.getMinPhoneNumberCharsToSync();
|
||||
Integer senderMinSize = prefs.getMinPhoneNumberCharsToSync();
|
||||
if (senderMinSize < 0) {
|
||||
senderMinSize = 0;
|
||||
}
|
||||
|
||||
// If minSize > 0 we should filter
|
||||
if (senderMinSize > 0) {
|
||||
if ((selection == null) || (selection.isEmpty())) {
|
||||
selection = "length(address) > ?";
|
||||
selectionArgs = new String[] { senderMinSize.toString() };
|
||||
}
|
||||
else {
|
||||
selection = "length(address) > ? AND " + selection;
|
||||
int nSelectionArgLength = 1;
|
||||
if (selectionArgs != null) {
|
||||
nSelectionArgLength += selectionArgs.length;
|
||||
}
|
||||
String[] nSelectionArgs = new String[nSelectionArgLength];
|
||||
nSelectionArgs[0] = senderMinSize.toString();
|
||||
if (selectionArgs != null) {
|
||||
System.arraycopy(selectionArgs, 0, nSelectionArgs, 1, selectionArgs.length);
|
||||
}
|
||||
selectionArgs = nSelectionArgs;
|
||||
}
|
||||
|
||||
Log.d(SmsDataProvider.TAG, "query: Minimum message length set to " + selectionArgs[0]);
|
||||
}
|
||||
|
||||
if (bulkLimit > 0) {
|
||||
if (sortOrder == null)
|
||||
sortOrder = "_id ";
|
||||
sortOrder += " LIMIT " + bulkLimit.toString();
|
||||
|
||||
Log.d(SmsDataProvider.TAG, "query: Bulk limit set to " + bulkLimit.toString());
|
||||
}
|
||||
|
||||
if ((_context != null) && (_context.getContentResolver() != null)) {
|
||||
return _context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
|
||||
}
|
||||
Log.d(SmsDataProvider.TAG, "query: selection set to " + selection);
|
||||
|
||||
return null;
|
||||
return _context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,18 +32,6 @@
|
||||
<!-- Translation version, reference for translators -->
|
||||
<string name="translation_version">7</string>
|
||||
|
||||
<!-- System strings, do not translate -->
|
||||
<string name="app_name">ownCloud-SMS</string>
|
||||
<string name="account_type">fr.unix_experience.owncloud_sms</string>
|
||||
<string name="account_authority">fr.unix_experience.owncloud_sms.datasync.provider</string>
|
||||
<string name="slowsync_account_authority">fr.unix_experience.owncloud_sms.datasync.slowsync_provider</string>
|
||||
<string name="target_package">fr.unix_experience.owncloud_sms</string>
|
||||
<string name="login_logo">Login logo</string>
|
||||
|
||||
<!-- System strings: preferences -->
|
||||
<string name="shared_preference_file">ownCloudSMSPrefs</string>
|
||||
<string name="pref_lastmsgdate">last_message_date</string>
|
||||
|
||||
<!-- Translations must begin there -->
|
||||
<!-- Preferences -->
|
||||
<string name="pref_title_sync">短信 - 快速模式</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user