From c1d0a437f71b10d6d17c99d7fe1ea7573ddfc15a Mon Sep 17 00:00:00 2001 From: Mathis Dirksen-Thedens Date: Tue, 31 Oct 2023 18:49:20 +0100 Subject: [PATCH] update Gradle and dependencies; target API level 34 (Android 14) and make some adjustments for that --- app/build.gradle | 14 ++++++-------- app/src/main/AndroidManifest.xml | 1 + .../java/org/zephyrsoft/trackworktime/Basics.java | 6 +++++- .../location/LocationTrackerService.java | 6 +++++- .../trackworktime/location/WifiScanner.java | 7 ++++++- .../trackworktime/location/WifiTrackerService.java | 6 +++++- gradle.properties | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 12a47b76..04886c74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,11 +43,10 @@ android { testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' minSdkVersion 21 - targetSdkVersion 33 + targetSdkVersion 34 + compileSdk 34 } - compileSdkVersion 33 - buildTypes { release { postprocessing { @@ -59,8 +58,8 @@ android { } // rename final APK files - android.applicationVariants.all { variant -> - variant.outputs.all { + android.applicationVariants.configureEach { variant -> + variant.outputs.configureEach { outputFileName = "TrackWorkTime_${variant.versionName}_${buildTime()}_${variant.buildType.name}${variant.signingReady ? "" : "-unsigned"}.apk" } } @@ -75,12 +74,11 @@ dependencies { implementation 'androidx.asynclayoutinflater:asynclayoutinflater:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.preference:preference:1.2.1' - implementation 'androidx.recyclerview:recyclerview:1.3.1' + implementation 'androidx.recyclerview:recyclerview:1.3.2' implementation 'androidx.recyclerview:recyclerview-selection:1.1.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' - // material:1.10.0 forces API level 34 - implementation 'com.google.android.material:material:1.9.0' + implementation 'com.google.android.material:material:1.10.0' implementation "ch.acra:acra-http:$acraVersion" implementation "ch.acra:acra-dialog:$acraVersion" implementation 'org.apache.commons:commons-lang3:3.13.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 41506a53..f0730f16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + diff --git a/app/src/main/java/org/zephyrsoft/trackworktime/Basics.java b/app/src/main/java/org/zephyrsoft/trackworktime/Basics.java index 7905b20b..5b8d481d 100644 --- a/app/src/main/java/org/zephyrsoft/trackworktime/Basics.java +++ b/app/src/main/java/org/zephyrsoft/trackworktime/Basics.java @@ -178,7 +178,11 @@ private void registerThirdPartyReceiver() { intentFilter.addAction(Constants.CLOCK_IN_ACTION); intentFilter.addAction(Constants.CLOCK_OUT_ACTION); intentFilter.addAction(Constants.STATUS_REQUEST_ACTION); - context.registerReceiver(thirdPartyReceiver, intentFilter); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver(thirdPartyReceiver, intentFilter, Context.RECEIVER_EXPORTED); + } else { + context.registerReceiver(thirdPartyReceiver, intentFilter); + } Logger.debug("Registered {}", ThirdPartyReceiver.class.getSimpleName()); } diff --git a/app/src/main/java/org/zephyrsoft/trackworktime/location/LocationTrackerService.java b/app/src/main/java/org/zephyrsoft/trackworktime/location/LocationTrackerService.java index 2a0e4841..47cb364e 100644 --- a/app/src/main/java/org/zephyrsoft/trackworktime/location/LocationTrackerService.java +++ b/app/src/main/java/org/zephyrsoft/trackworktime/location/LocationTrackerService.java @@ -18,6 +18,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.location.LocationManager; import android.media.AudioManager; import android.os.Build; @@ -46,7 +47,10 @@ public class LocationTrackerService extends Service { public void onCreate() { Logger.info("creating LocationTrackerService"); basics = Basics.get(getApplicationContext()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(Constants.PERSISTENT_TRACKING_ID, basics.createNotificationTracking(), + ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startForeground(Constants.PERSISTENT_TRACKING_ID, basics.createNotificationTracking()); } locationTracker = new LocationTracker((LocationManager) getSystemService(Context.LOCATION_SERVICE), basics diff --git a/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiScanner.java b/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiScanner.java index 27953129..8eec8354 100644 --- a/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiScanner.java +++ b/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiScanner.java @@ -21,6 +21,7 @@ import android.content.IntentFilter; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; +import android.os.Build; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -130,7 +131,11 @@ public void register(@NonNull Context context) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); // Note: Android API only allows registering broadcast receivers to application context! - context.getApplicationContext().registerReceiver(this, intentFilter); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.getApplicationContext().registerReceiver(this, intentFilter, Context.RECEIVER_EXPORTED); + } else { + context.getApplicationContext().registerReceiver(this, intentFilter); + } this.context = context; setRegistered(true); } diff --git a/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiTrackerService.java b/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiTrackerService.java index c2f50637..a81cad0c 100644 --- a/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiTrackerService.java +++ b/app/src/main/java/org/zephyrsoft/trackworktime/location/WifiTrackerService.java @@ -18,6 +18,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.media.AudioManager; import android.net.wifi.WifiManager; import android.os.Build; @@ -49,7 +50,10 @@ public class WifiTrackerService extends Service { public void onCreate() { Logger.info("creating WifiTrackerService"); basics = Basics.get(getApplicationContext()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(Constants.PERSISTENT_TRACKING_ID, basics.createNotificationTracking(), + ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startForeground(Constants.PERSISTENT_TRACKING_ID, basics.createNotificationTracking()); } diff --git a/gradle.properties b/gradle.properties index 460a4a62..dd65b3d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,8 +5,8 @@ app_suffix= # use appropriate AndroidX library instead of a Support Library android.useAndroidX=true -# automatic migrating of third-party libraries to AndroidX -android.enableJetifier=true +# automatic migrating of third-party libraries to AndroidX not needed +android.enableJetifier=false # Github Actions don't reserve enough memory without this: org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m # generate the BuildConfig class diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bc0a985d..5be28f63 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists -distributionSha256Sum=38f66cd6eef217b4c35855bb11ea4e9fbc53594ccccb5fb82dfd317ef8c2c5a3 +distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae zipStoreBase=GRADLE_USER_HOME