Sync in KeychainIntentService on delete, import, save

This commit is contained in:
Dominik Schürmann 2014-08-20 23:55:01 +02:00
parent 642a63fab6
commit 6e3af6605a
2 changed files with 21 additions and 0 deletions

View File

@ -21,6 +21,8 @@ import android.accounts.Account;
import android.app.Service; import android.app.Service;
import android.content.AbstractThreadedSyncAdapter; import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient; import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SyncResult; import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
@ -29,9 +31,11 @@ import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.provider.ContactsContract;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.KeychainApplication; import org.sufficientlysecure.keychain.KeychainApplication;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ContactHelper; import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.helper.EmailKeyHelper; import org.sufficientlysecure.keychain.helper.EmailKeyHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -94,6 +98,15 @@ public class ContactSyncAdapterService extends Service {
} }
} }
public static void requestSync(Context context) {
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(
new Account(context.getString(R.string.app_name), Constants.PACKAGE_NAME),
ContactsContract.AUTHORITY,
extras);
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return new ContactSyncAdapter().getSyncAdapterBinder(); return new ContactSyncAdapter().getSyncAdapterBinder();

View File

@ -453,6 +453,9 @@ public class KeychainIntentService extends IntentService
setProgress(R.string.progress_done, 100, 100); setProgress(R.string.progress_done, 100, 100);
// make sure new data is synced into contacts
ContactSyncAdapterService.requestSync(this);
/* Output */ /* Output */
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
} catch (Exception e) { } catch (Exception e) {
@ -501,6 +504,8 @@ public class KeychainIntentService extends IntentService
if (result.mSecret > 0) { if (result.mSecret > 0) {
providerHelper.consolidateDatabaseStep1(this); providerHelper.consolidateDatabaseStep1(this);
} }
// make sure new data is synced into contacts
ContactSyncAdapterService.requestSync(this);
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
} catch (Exception e) { } catch (Exception e) {
@ -708,6 +713,9 @@ public class KeychainIntentService extends IntentService
} }
if (success) { if (success) {
// make sure new data is synced into contacts
ContactSyncAdapterService.requestSync(this);
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY);
} }