Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 557e69f1 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Sync manager optimization

* allow cancellation of synchronization within appropriate time
* sync error notification: use loader, show all accounts, show whether JB Workaround is installed, reorder
parent a68717de
Loading
Loading
Loading
Loading
+34 −38
Original line number Diff line number Diff line
@@ -62,47 +62,10 @@ public class HttpClient extends OkHttpClient {
    protected String username, password;


    public HttpClient() {
        super();
        context = null;
        initialize();
    }

    public HttpClient(Context context, String username, String password, boolean preemptive) {
    protected HttpClient(Context context) {
        super();
        this.context = context;

        initialize();

        // authentication
        this.username = username;
        this.password = password;
        if (preemptive)
            networkInterceptors().add(new PreemptiveAuthenticationInterceptor(username, password));
        else
            setAuthenticator(new BasicDigestAuthenticator(null, username, password));
    }

    /**
     * Creates a new HttpClient (based on another one) which can be used to download external resources:
     * 1. it does not use preemptive authentication
     * 2. it only authenticates against a given host
     * @param client  user name and password from this client will be used
     * @param host    authentication will be restricted to this host
     */
    public HttpClient(HttpClient client, String host) {
        super();
        context = client.context;

        initialize();

        username = client.username;
        password = client.password;
        setAuthenticator(new BasicDigestAuthenticator(host, username, password));
    }


    protected void initialize() {
        if (context != null) {
            // use MemorizingTrustManager to manage self-signed certificates
            MemorizingTrustManager mtm = new MemorizingTrustManager(context);
@@ -131,6 +94,39 @@ public class HttpClient extends OkHttpClient {
            enableLogs();
    }

    public HttpClient(Context context, String username, String password, boolean preemptive) {
        this(context);

        // authentication
        this.username = username;
        this.password = password;
        if (preemptive)
            networkInterceptors().add(new PreemptiveAuthenticationInterceptor(username, password));
        else
            setAuthenticator(new BasicDigestAuthenticator(null, username, password));
    }

    /**
     * Creates a new HttpClient (based on another one) which can be used to download external resources:
     * 1. it does not use preemptive authentication
     * 2. it only authenticates against a given host
     * @param client  user name and password from this client will be used
     * @param host    authentication will be restricted to this host
     */
    public HttpClient(HttpClient client, String host) {
        this(client.context);

        username = client.username;
        password = client.password;
        setAuthenticator(new BasicDigestAuthenticator(host, username, password));
    }

    // for testing (mock server doesn't need auth)
    protected HttpClient() {
        this(null, null, null, false);
    }


    protected void enableLogs() {
        interceptors().add(loggingInterceptor);
    }
+4 −2
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@ public class CalendarSyncManager extends SyncManager {
    protected static final int MAX_MULTIGET = 20;


    public CalendarSyncManager(Context context, Account account, Bundle extras, SyncResult result, LocalCalendar calendar) {
        super(Constants.NOTIFICATION_CALENDAR_SYNC, context, account, extras, result);
    public CalendarSyncManager(Context context, Account account, Bundle extras, String authority, SyncResult result, LocalCalendar calendar) {
        super(Constants.NOTIFICATION_CALENDAR_SYNC, context, account, extras, authority, result);
        localCollection = calendar;
    }

@@ -130,6 +130,8 @@ public class CalendarSyncManager extends SyncManager {

        // download new/updated iCalendars from server
        for (DavResource[] bunch : ArrayUtils.partition(toDownload.toArray(new DavResource[toDownload.size()]), MAX_MULTIGET)) {
            if (Thread.interrupted())
                return;
            Constants.log.info("Downloading " + StringUtils.join(bunch, ", "));

            if (bunch.length == 1) {
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class CalendarsSyncAdapterService extends Service {
            try {
                for (LocalCalendar calendar : (LocalCalendar[])LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, CalendarContract.Calendars.SYNC_EVENTS + "!=0", null)) {
                    Constants.log.info("Synchronizing calendar #"  + calendar.getId() + ", URL: " + calendar.getName());
                    CalendarSyncManager syncManager = new CalendarSyncManager(getContext(), account, extras, syncResult, calendar);
                    CalendarSyncManager syncManager = new CalendarSyncManager(getContext(), account, extras, authority, syncResult, calendar);
                    syncManager.performSync();
                }
            } catch (CalendarStorageException e) {
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class ContactsSyncAdapterService extends Service {
        public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
            Constants.log.info("Starting address book sync (" + authority + ")");

            ContactsSyncManager syncManager = new ContactsSyncManager(getContext(), account, extras, provider, syncResult);
            ContactsSyncManager syncManager = new ContactsSyncManager(getContext(), account, extras, authority, provider, syncResult);
            syncManager.performSync();

            Constants.log.info("Address book sync complete");
+5 −2
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ public class ContactsSyncManager extends SyncManager {
    protected boolean hasVCard4;


    public ContactsSyncManager(Context context, Account account, Bundle extras, ContentProviderClient provider, SyncResult result) {
        super(Constants.NOTIFICATION_CONTACTS_SYNC, context, account, extras, result);
    public ContactsSyncManager(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult result) {
        super(Constants.NOTIFICATION_CONTACTS_SYNC, context, account, extras, authority, result);
        this.provider = provider;
    }

@@ -140,6 +140,9 @@ public class ContactsSyncManager extends SyncManager {

        // download new/updated VCards from server
        for (DavResource[] bunch : ArrayUtils.partition(toDownload.toArray(new DavResource[toDownload.size()]), MAX_MULTIGET)) {
            if (Thread.interrupted())
                return;

            Constants.log.info("Downloading " + StringUtils.join(bunch, ", "));

            if (bunch.length == 1) {
Loading