Skip to content

Commit

Permalink
[LEIP-206] Add draft for webdav upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Mar 21, 2024
1 parent 6e38158 commit 207c964
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ext {
// When `android-app` is checkout out, `rootProject.uploaderVersion` in the submodules will point
// to `android-app/build.gradle` instead of `submodule/build.gradle`.
cyfaceSerializationVersion = "3.2.0"
cyfaceUploaderVersion = "1.2.0"
cyfaceUploaderVersion = "1.2.1-alpha1" // FIXME

// Android SDK versions
minSdkVersion = 21 // device support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package de.cyface.datacapturing;

import static de.cyface.datacapturing.Constants.TAG;
import static de.cyface.synchronization.CyfaceAuthenticator.LOGIN_ACTIVITY;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,8 +29,6 @@

import androidx.annotation.NonNull;

import org.json.JSONObject;

import de.cyface.datacapturing.backend.DataCapturingBackgroundService;
import de.cyface.datacapturing.exception.CorruptedMeasurementException;
import de.cyface.datacapturing.exception.DataCapturingException;
Expand All @@ -49,6 +46,7 @@
import de.cyface.persistence.strategy.DefaultLocationCleaning;
import de.cyface.persistence.strategy.DistanceCalculationStrategy;
import de.cyface.persistence.strategy.LocationCleaningStrategy;
import de.cyface.synchronization.LoginActivityProvider;
import de.cyface.synchronization.WiFiSurveyor;
import de.cyface.uploader.exception.SynchronisationException;
import de.cyface.utils.Validate;
Expand Down Expand Up @@ -85,15 +83,16 @@ public final class CyfaceDataCapturingService extends DataCapturingService {
* usually uses a frequency sightly higher than this value, e.g.: 101-103/s for 100 Hz.
*/
private CyfaceDataCapturingService(@NonNull final Context context,
@NonNull final String authority, @NonNull final String accountType,
@NonNull final EventHandlingStrategy eventHandlingStrategy,
@NonNull final DistanceCalculationStrategy distanceCalculationStrategy,
@NonNull final LocationCleaningStrategy locationCleaningStrategy,
@NonNull final DataCapturingListener capturingListener, final int sensorFrequency) {
@NonNull final String authority, @NonNull final String accountType,
@NonNull final EventHandlingStrategy eventHandlingStrategy,
@NonNull final DistanceCalculationStrategy distanceCalculationStrategy,
@NonNull final LocationCleaningStrategy locationCleaningStrategy,
@NonNull final DataCapturingListener capturingListener, final int sensorFrequency,
@NonNull final LoginActivityProvider loginActivityProvider) {
super(context, authority, accountType, eventHandlingStrategy,
new DefaultPersistenceLayer<>(context, new CapturingPersistenceBehaviour()),
distanceCalculationStrategy, locationCleaningStrategy, capturingListener, sensorFrequency);
if (LOGIN_ACTIVITY == null) {
if (loginActivityProvider.getLoginActivity() == null) {
throw new IllegalStateException("No LOGIN_ACTIVITY was set from the SDK using app.");
}
}
Expand All @@ -119,11 +118,12 @@ private CyfaceDataCapturingService(@NonNull final Context context,
public CyfaceDataCapturingService(@NonNull final Context context,
@NonNull final String authority, @NonNull final String accountType,
@NonNull final EventHandlingStrategy eventHandlingStrategy,
@NonNull final DataCapturingListener capturingListener, final int sensorFrequency)
@NonNull final DataCapturingListener capturingListener, final int sensorFrequency,
@NonNull final LoginActivityProvider loginActivityProvider)
throws SetupException {
this(context, authority, accountType, eventHandlingStrategy,
new DefaultDistanceCalculation(), new DefaultLocationCleaning(), capturingListener,
sensorFrequency);
sensorFrequency, loginActivityProvider);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package de.cyface.synchronization

interface Auth {

/**
* Makes sure that a valid access token is available before executing the provided action.
*
* @param action The method which will be executed.
*/
fun performActionWithFreshTokens(
action: (
accessToken: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ import kotlinx.coroutines.runBlocking
* against the Cyface server.
*
* **ATTENTION:** The [.getAuthToken] method is only
* called by the system if no token is cached. As our logic to invalidate token currently is in this method, we call it
* directly where we need a fresh token.
* called by the system if no token is cached. As our logic to invalidate tokens is in this method,
* we call it directly where we need a fresh token.
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 5.1.1
* @since 2.0.0
*/
class CyfaceAuthenticator(private val context: Context) :
AbstractAccountAuthenticator(context) {
AbstractAccountAuthenticator(context), LoginActivityProvider {

private var auth: OAuth2 = OAuth2(context, settings)

Expand Down Expand Up @@ -171,4 +171,8 @@ class CyfaceAuthenticator(private val context: Context) :
*/
lateinit var settings: SynchronizationSettings
}

override fun getLoginActivity(): Class<out Activity?>? {
return LOGIN_ACTIVITY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,10 @@ class CyfaceAuthenticatorService : Service() {
private var authenticator: CyfaceAuthenticator? = null

override fun onCreate() {
Log.d(TAG, "authenticator service on create!")

authenticator = CyfaceAuthenticator(this)
}

override fun onBind(intent: Intent): IBinder? {
Log.d(TAG, "authenticator service on bind")
return authenticator!!.iBinder
}

companion object {
/**
* Logging TAG to identify logs associated with the [WiFiSurveyor].
*/
@Suppress("unused") // we add and move logs often, so keep it

val TAG = Constants.TAG + ".authSvc"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.cyface.synchronization

import android.app.Activity

interface LoginActivityProvider {
fun getLoginActivity(): Class<out Activity?>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ internal class SyncPerformer(private val context: Context, private val fromBackg
metaData,
measurementId,
file,
fileName,
progressListener
)

Expand Down

0 comments on commit 207c964

Please sign in to comment.