1
0
mirror of https://github.com/etesync/android synced 2025-07-05 14:22:37 +00:00
etesync-android/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java
Tom Hacohen 8b5f87c2d4 Adjust DAVdroid to use the EteSync protocol (mostly working)
This commit includes the major changes between DAVdroid and EteSync. It
adjusts the app to use the EteSync protocol and server. It includes some
ugliness still, and it's a squash of many ugly snapshot commits while
hacking on the initial DAVdroid code.

History should be "clean" from this point onwards.
2017-02-21 17:26:19 +00:00

112 lines
3.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright © 2013 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui.setup;
import android.content.Context;
import android.support.annotation.NonNull;
import java.io.Serializable;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import at.bitfire.davdroid.HttpClient;
import at.bitfire.davdroid.journalmanager.Exceptions;
import at.bitfire.davdroid.journalmanager.JournalAuthenticator;
import at.bitfire.davdroid.log.StringHandler;
import at.bitfire.davdroid.model.CollectionInfo;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
public class DavResourceFinder {
protected final Context context;
protected final LoginCredentials credentials;
protected final Logger log;
protected final StringHandler logBuffer = new StringHandler();
protected OkHttpClient httpClient;
public DavResourceFinder(@NonNull Context context, @NonNull LoginCredentials credentials) {
this.context = context;
this.credentials = credentials;
log = Logger.getLogger("davdroid.DavResourceFinder");
log.setLevel(Level.FINEST);
log.addHandler(logBuffer);
httpClient = HttpClient.create(context, log);
}
public Configuration findInitialConfiguration() {
boolean failed = false;
Configuration.ServiceInfo
cardDavConfig = findInitialConfiguration(CollectionInfo.Type.ADDRESS_BOOK),
calDavConfig = findInitialConfiguration(CollectionInfo.Type.CALENDAR);
JournalAuthenticator authenticator = new JournalAuthenticator(httpClient, HttpUrl.get(credentials.uri));
String authtoken = null;
try {
authtoken = authenticator.getAuthToken(credentials.userName, credentials.password);
} catch (Exceptions.HttpException e) {
log.warning(e.getMessage());
failed = true;
}
return new Configuration(
credentials.uri,
credentials.userName, authtoken,
cardDavConfig, calDavConfig,
logBuffer.toString(), failed
);
}
protected Configuration.ServiceInfo findInitialConfiguration(@NonNull CollectionInfo.Type service) {
// put discovered information here
final Configuration.ServiceInfo config = new Configuration.ServiceInfo();
log.info("Finding initial " + service.toString() + " service configuration");
return config;
}
// data classes
@RequiredArgsConstructor
@ToString(exclude="logs")
public static class Configuration implements Serializable {
// We have to use URI here because HttpUrl is not serializable!
@ToString
public static class ServiceInfo implements Serializable {
public final Map<String, CollectionInfo> collections = new HashMap<>();
}
public final URI url;
public final String userName, authtoken;
public String rawPassword;
public String password;
public final ServiceInfo cardDAV;
public final ServiceInfo calDAV;
public final String logs;
@Getter
private final boolean failed;
}
}