Synchronization works, at least basically

This commit is contained in:
Christian Basler 2015-10-25 11:29:46 +01:00
parent 7fe7ee42fc
commit 2a17bbe34b
5 changed files with 13 additions and 6 deletions

View File

@ -13,7 +13,7 @@ import android.os.Bundle;
*/
public class Authenticator extends AbstractAccountAuthenticator {
public static final String ACCOUNT_NAME = "Bitmessage";
public static final String ACCOUNT_TYPE = "bitmessage.dissem.ch";
public static final String ACCOUNT_TYPE = "ch.dissem.bitmessage";
// Simple constructor
public Authenticator(Context context) {

View File

@ -37,9 +37,12 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
LOG.info("Synchronizing Bitmessage");
// If the Bitmessage context acts as a full node, synchronization isn't necessary
if (bmc.isRunning()) return;
if (bmc.isRunning()) {
LOG.info("Synchronization skipped, Abit is acting as a full node");
return;
}
LOG.info("Synchronizing Bitmessage");
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
@ -63,7 +66,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
} else {
port = 8444;
}
long timeoutInSeconds = preferences.getInt("sync_timeout", 120);
long timeoutInSeconds = Long.parseLong(preferences.getString("sync_timeout", "120"));
try {
LOG.info("Synchronization started");
bmc.synchronize(InetAddress.getByName(trustedNode), port, timeoutInSeconds, true);

View File

@ -4,6 +4,9 @@ import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.dissem.apps.abit.listener.MessageListener;
import ch.dissem.apps.abit.notification.NetworkNotification;
import ch.dissem.apps.abit.repository.AndroidInventory;
@ -22,6 +25,7 @@ import static ch.dissem.apps.abit.notification.NetworkNotification.ONGOING_NOTIF
* onPerformSync().
*/
public class SyncService extends Service {
private static final Logger LOG = LoggerFactory.getLogger(SyncService.class);
// Storage for an instance of the sync adapter
private static SyncAdapter syncAdapter = null;
// Object to use as a thread-safe lock

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="bitmessage.dissem.ch"
android:accountType="ch.dissem.bitmessage"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:smallIcon="@mipmap/ic_launcher" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="ch.dissem.bitmessage.provider"
android:contentAuthority="ch.dissem.apps.abit.provider"
android:accountType="ch.dissem.bitmessage"
android:userVisible="true"
android:supportsUploading="true"