Some sync adapter fixes and changes - still doesn't work

This commit is contained in:
2015-10-12 14:44:01 +02:00
parent 348fa8daed
commit 67c06b9884
10 changed files with 82 additions and 104 deletions

View File

@ -10,6 +10,8 @@ import android.net.Uri;
* all methods
*/
public class StubProvider extends ContentProvider {
public static final String AUTHORITY = "ch.dissem.apps.abit.provider";
/*
* Always return true, indicating that the
* provider loaded correctly.
@ -18,6 +20,7 @@ public class StubProvider extends ContentProvider {
public boolean onCreate() {
return true;
}
/*
* Return no type for MIME type
*/
@ -25,6 +28,7 @@ public class StubProvider extends ContentProvider {
public String getType(Uri uri) {
return null;
}
/*
* query() always returns no results
*
@ -38,6 +42,7 @@ public class StubProvider extends ContentProvider {
String sortOrder) {
return null;
}
/*
* insert() always returns null (no URI)
*/
@ -45,6 +50,7 @@ public class StubProvider extends ContentProvider {
public Uri insert(Uri uri, ContentValues values) {
return null;
}
/*
* delete() always returns "no rows affected" (0)
*/
@ -52,6 +58,7 @@ public class StubProvider extends ContentProvider {
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
/*
* update() always returns "no rows affected" (0)
*/

View File

@ -25,17 +25,32 @@ import ch.dissem.bitmessage.BitmessageContext;
public class SyncAdapter extends AbstractThreadedSyncAdapter {
private final static Logger LOG = LoggerFactory.getLogger(SyncAdapter.class);
public static final String AUTHORITY = "ch.dissem.bitmessage.provider";
private final BitmessageContext bmc;
public SyncAdapter(Context context) {
super(context, true, false);
/**
* Set up the sync adapter
*/
public SyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
bmc = Singleton.getBitmessageContext(context);
}
/**
* Set up the sync adapter. This form of the
* constructor maintains compatibility with Android 3.0
* and later platform versions
*/
public SyncAdapter(
Context context,
boolean autoInitialize,
boolean allowParallelSyncs) {
super(context, autoInitialize, allowParallelSyncs);
bmc = Singleton.getBitmessageContext(context);
}
@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;
@ -52,7 +67,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
String portString = trustedNode.substring(index + 1);
trustedNode = trustedNode.substring(0, index);
try {
port = Integer.parseInt(portString);// FIXME
port = Integer.parseInt(portString);
} catch (NumberFormatException e) {
LOG.error("Invalid port " + portString);
// TODO: show error as notification

View File

@ -27,7 +27,7 @@ public class SyncService extends Service {
*/
synchronized (syncAdapterLock) {
if (syncAdapter == null) {
syncAdapter = new SyncAdapter(getApplicationContext());
syncAdapter = new SyncAdapter(getApplicationContext(), true);
}
}
}