Skip to content

Commit

Permalink
[RFR-769] Migrate to DataStore (#70)
Browse files Browse the repository at this point in the history
* Upgrade robolectric to 4.10.2

* Upgrade kotlin to 1.8.22

* [RFR-780] Migrate energy-settings to DataStore

* [RFR-782] Support energy_settings and SDK DataStore

* [RFR-781] Migrate UI to DataStore

* [RFR-789] Set default values in migration code

* Rename classes

* [RFR-790] Fix SettingsFragment UI bugs

* Upgrade dependencies

* Cleanup

* Upgrade camera-service to 4.3.1

* Cleanup

* Update version numbers
  • Loading branch information
hb0 authored Sep 18, 2023
1 parent ccf3233 commit a6e0d46
Show file tree
Hide file tree
Showing 87 changed files with 2,330 additions and 1,667 deletions.
2 changes: 1 addition & 1 deletion backend
Submodule backend updated 114 files
29 changes: 16 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
*
* @author Armin Schnabel
* @author Klemens Muthmann
* @version 2.4.0
* @version 2.5.0
* @since 1.0.0
*/

buildscript {
ext.gradle_version = '7.4.2' // Major release available but breaks publish [RFR-412]
ext.kotlin_version = "1.8.0"
ext.kotlin_version = "1.8.22" // Build fails when upgrading to 1.9.0/10
ext.matcher_version = "1.2.4"

repositories {
Expand All @@ -43,6 +43,11 @@ buildscript {
}
}

plugins {
// To generate Proto DataStores for settings in ui/digural and utils/
id 'com.google.protobuf' version '0.8.19' apply false // Maybe keep in sync with other usages
}

ext {
// This app's version
versionName = "0.0.0" // Automatically overwritten by CI. Version shown to the user
Expand All @@ -55,18 +60,18 @@ ext {
*/

// Cyface dependencies
cyfaceAndroidBackendVersion = "7.8.2" // Also update submodule commit ref
cyfaceUtilsVersion = "3.5.1"
cyfaceEnergySettingsVersion = "3.3.5" // Also update submodule commit ref
cyfaceCameraServiceVersion = "4.2.2" // Also update submodule commit ref
cyfaceAndroidBackendVersion = "7.9.0" // Also update submodule commit ref
cyfaceUtilsVersion = "4.0.2"
cyfaceEnergySettingsVersion = "4.0.1" // Also update submodule commit ref
cyfaceCameraServiceVersion = "4.3.1" // Also update submodule commit ref
// Maybe keep this in sync with the serialization library version used in `uploader` lib
cyfaceSerializationVersion = "3.0.0" // Keep im sync with version in submodule `backend`
cyfaceUploaderVersion = "1.0.0"

// Android SDK versions
minSdkVersion = 21 // device support
targetSdkVersion = 33 // behavioral changes, follow migration guide & test the app against this
compileSdkVersion = 33 // allows newest APIs to be used and to see deprecations, use latest
compileSdkVersion = 34 // allows newest APIs to be used and to see deprecations, use latest
buildToolsVersion = '34.0.0' // optional, if defined, use latest (SDK Manager > SDK Tools)

// Android dependencies
Expand All @@ -79,6 +84,8 @@ ext {
lifecycleVersion = "2.6.1"
navigationVersion = "2.5.3"
okHttpVersion = "4.11.0"
// 1.1.0-alpha05: ':persistence:mergeExtDexDebugAndroidTest' fails (transitive dependency)
datastoreVersion = "1.1.0-alpha04" // only 1.1.0 supports multi-process datastore

// Kotlin components
coroutinesVersion = "1.6.4"
Expand All @@ -89,6 +96,7 @@ ext {
// Can't be a SDK dependency as `appAuthRedirectScheme` needs to be defined at build-time
appAuthVersion = "0.11.1" // Can't move to uploader lib because of dependency issues
retrofitVersion = "2.9.0" // Used by digural UI
protobufVersion = '3.22.2' // For Proto Datastore. Maybe keep in sync with other versions.


// Testing
Expand All @@ -97,7 +105,7 @@ ext {
mockitoKotlinVersion = '4.1.0'
hamcrestVersion = "1.3"
rulesVersion = "1.5.0"
robolectricVersion = "4.8.2"
robolectricVersion = "4.10.2"
androidxTestCoreVersion = '1.4.0'
runnerVersion = "1.5.2"
uiAutomatorVersion = "2.2.0"
Expand Down Expand Up @@ -149,8 +157,3 @@ allprojects {
// Generate a single reporting for all sub-modules (test results, lint, coverage, etc.)
// TODO does not work currently. ui is unable to find dependencies with this applied.
//apply plugin: 'android-reporting'

// Auto-generated by Android Studio
task clean(type: Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion camera_service
3 changes: 2 additions & 1 deletion ui/cyface/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
*
* @author Armin Schnabel
* @author Klemens Muthmann
* @version 1.11.0
* @version 1.11.1
* @since 1.0.0
*/

apply plugin: 'com.android.application'
apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'
apply plugin: 'io.sentry.android.gradle' // Exception tracking when using proguard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@
import de.cyface.app.R;
import de.cyface.app.button.AbstractButton;
import de.cyface.app.button.ButtonListener;
import de.cyface.app.notification.CameraEventHandler;
import de.cyface.app.utils.CalibrationDialogListener;
import de.cyface.app.utils.Map;
import de.cyface.camera_service.background.camera.CameraListener;
import de.cyface.camera_service.CameraPreferences;
import de.cyface.camera_service.foreground.CameraService;
import de.cyface.camera_service.Constants;
import de.cyface.camera_service.UIListener;
import de.cyface.camera_service.background.camera.CameraListener;
import de.cyface.camera_service.foreground.CameraService;
import de.cyface.camera_service.settings.CameraSettings;
import de.cyface.datacapturing.CyfaceDataCapturingService;
import de.cyface.datacapturing.DataCapturingListener;
import de.cyface.datacapturing.DataCapturingService;
Expand All @@ -89,9 +88,9 @@
import de.cyface.persistence.model.ParcelableGeoLocation;
import de.cyface.persistence.model.Track;
import de.cyface.persistence.strategy.DefaultLocationCleaning;
import de.cyface.utils.AppPreferences;
import de.cyface.utils.DiskConsumption;
import de.cyface.utils.Validate;
import de.cyface.utils.settings.AppSettings;
import io.sentry.Sentry;

// TODO: This class has overstretched its intended scope by several orders of magnitude by now.
Expand All @@ -103,7 +102,7 @@
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 3.8.3
* @version 4.0.0
* @since 1.0.0
*/
public class DataCapturingButton
Expand All @@ -126,13 +125,13 @@ public class DataCapturingButton
*/
private CameraService cameraService = null;
/**
* The `SharedPreferences` used to store the app preferences.
* The settings used by both, UIs and libraries.
*/
private AppPreferences preferences;
private final AppSettings appSettings;
/**
* The `SharedPreferences` used to store the camera preferences.
* The settings used by the camera service.
*/
private CameraPreferences cameraPreferences;
private final CameraSettings cameraSettings;
private final static long CALIBRATION_DIALOG_TIMEOUT = 1500L;
private Collection<CalibrationDialogListener> calibrationDialogListener;
/**
Expand Down Expand Up @@ -173,9 +172,12 @@ public class DataCapturingButton
private boolean isReportingEnabled;
private ProgressDialog calibrationProgressDialog;

public DataCapturingButton(@NonNull final CapturingFragment capturingFragment) {
public DataCapturingButton(@NonNull final CapturingFragment capturingFragment,
@NonNull final AppSettings appSettings, @NonNull final CameraSettings cameraSettings) {
this.listener = new HashSet<>();
this.capturingFragment = capturingFragment;
this.appSettings = appSettings;
this.cameraSettings = cameraSettings;
}

@Override
Expand All @@ -191,9 +193,7 @@ public void onCreateView(final ImageButton button, final DonutProgress ISNULL) {
this.cameraInfoTextView = button.getRootView().findViewById(R.id.camera_capturing_info);

// To get the vehicle
preferences = new AppPreferences(context);
cameraPreferences = new CameraPreferences(context);
isReportingEnabled = preferences.getReportingAccepted();
isReportingEnabled = appSettings.getReportErrorsBlocking();

// To load the measurement distance
this.persistenceLayer = new DefaultPersistenceLayer<>(context, new DefaultPersistenceBehaviour());
Expand Down Expand Up @@ -565,7 +565,7 @@ private void startCapturing() {

// TODO [CY-3855]: we have to provide a listener for the button (<- ???)
try {
final var modality = Modality.valueOf(preferences.getModality());
final var modality = Modality.valueOf(appSettings.getModalityBlocking());
Validate.notNull(modality);

currentMeasurementsTracks = new ArrayList<>();
Expand Down Expand Up @@ -594,12 +594,11 @@ public void startUpFinished(final long measurementIdentifier) {
});
} catch (final DataCapturingException e) {
throw new IllegalStateException(e);
} catch (final MissingPermissionException e) {
} catch (final MissingPermissionException e) {
Toast.makeText(
context,
context.getString(de.cyface.app.utils.R.string.missing_location_permissions_toast),
Toast.LENGTH_LONG
).show();
Toast.LENGTH_LONG).show();
throw new IllegalStateException(e);
}
}
Expand Down Expand Up @@ -699,17 +698,17 @@ private void showToastOnMainThread(final String toastMessage, final boolean long
private void startCameraService(final long measurementId)
throws DataCapturingException, MissingPermissionException {

final var rawModeSelected = cameraPreferences.getRawMode();
final var videoModeSelected = cameraPreferences.getVideoMode();
final var rawModeSelected = cameraSettings.getRawModeBlocking();
final var videoModeSelected = cameraSettings.getVideoModeBlocking();
// We need to load and pass the preferences for the camera focus here as the preferences
// do not work reliably on multi-process access. https://stackoverflow.com/a/27987956/5815054
final var staticFocusSelected = cameraPreferences.getStaticFocus();
final var staticFocusDistance = cameraPreferences.getStaticFocusDistance();
final var distanceBasedTriggeringSelected = cameraPreferences.getDistanceBasedTriggering();
final var triggeringDistance = cameraPreferences.getTriggeringDistance();
final var staticExposureTimeSelected = cameraPreferences.getStaticExposure();
final var staticExposureTime = cameraPreferences.getStaticExposureTime();
final var exposureValueIso100 = cameraPreferences.getStaticExposureValue();
final var staticFocusSelected = cameraSettings.getStaticFocusBlocking();
final var staticFocusDistance = cameraSettings.getStaticFocusDistanceBlocking();
final var distanceBasedTriggeringSelected = cameraSettings.getDistanceBasedTriggeringBlocking();
final var triggeringDistance = cameraSettings.getTriggeringDistanceBlocking();
final var staticExposureTimeSelected = cameraSettings.getStaticExposureBlocking();
final var staticExposureTime = cameraSettings.getStaticExposureTimeBlocking();
final var exposureValueIso100 = cameraSettings.getStaticExposureValueBlocking();

cameraService.start(
measurementId,
Expand All @@ -727,8 +726,7 @@ private void startCameraService(final long measurementId)
public void startUpFinished(final long measurementIdentifier) {
Log.v(Constants.TAG, "startCameraService: CameraService startUpFinished");
}
}
);
});
}

/**
Expand Down Expand Up @@ -877,7 +875,7 @@ public void addButtonListener(final ButtonListener buttonListener) {
}

private boolean isCameraServiceRequested() {
return cameraPreferences.getCameraEnabled();
return cameraSettings.getCameraEnabledBlocking();
}

@Override
Expand Down Expand Up @@ -956,7 +954,7 @@ public void onNewSensorDataAcquired(CapturedData capturedData) {
@Override
public void onNewPictureAcquired(final int picturesCaptured) {
Log.d(Constants.TAG, "onNewPictureAcquired");
final String text = context.getString(R.string.camera_images) + " " + picturesCaptured;
final var text = context.getString(de.cyface.camera_service.R.string.camera_images) + " " + picturesCaptured;
cameraInfoTextView.setText(text);
Log.d(TAG, "cameraInfoTextView: " + cameraInfoTextView.getText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
*/
package de.cyface.app

import de.cyface.camera_service.settings.CameraSettings
import de.cyface.camera_service.foreground.CameraService

/**
* Interface which defines the dependencies implemented by the `MainActivity` to be accessible from
* the `Fragments`.
*
* @author Armin Schnabel
* @version 1.0.0
* @version 1.1.0
* @since 7.5.0
*/
interface CameraServiceProvider {
val cameraService: CameraService
val cameraSettings: CameraSettings
}
Loading

0 comments on commit a6e0d46

Please sign in to comment.