From 059efd92f18337e3a5097a037ee109b87450246a Mon Sep 17 00:00:00 2001 From: CheK539 Date: Tue, 23 Jul 2024 22:23:24 +0500 Subject: [PATCH 1/6] Fix widget worker --- documentation/WIDGET.md | 11 +++++++++++ example/src/main/AndroidManifest.xml | 5 ----- widget/src/main/AndroidManifest.xml | 16 ++++++++-------- .../android/widget/worker/FileUploadWorker.kt | 11 ++++++++++- ...ializer.kt => UploadcareWidgetInitializer.kt} | 11 +---------- 5 files changed, 30 insertions(+), 24 deletions(-) rename widget/src/main/java/com/uploadcare/android/widget/worker/{UploadcareWorkManagerInitializer.kt => UploadcareWidgetInitializer.kt} (82%) diff --git a/documentation/WIDGET.md b/documentation/WIDGET.md index ed5ab74e..606253e0 100644 --- a/documentation/WIDGET.md +++ b/documentation/WIDGET.md @@ -12,6 +12,17 @@ ``` +#### If your app targets Android 14 (API level 34) or higher you must specify a foreground service type for all long-running workers. + +Declare your worker's foreground service type with `dataSync` foreground service type in your app's manifest to support our worker: + +```xml + +``` + ##### Select and upload file to Uploadcare from any available social network/camera/local file from Activity/Fragment. Kotlin diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 982f8206..c727bb62 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -22,11 +22,6 @@ - - diff --git a/widget/src/main/AndroidManifest.xml b/widget/src/main/AndroidManifest.xml index 96142e84..509e4416 100644 --- a/widget/src/main/AndroidManifest.xml +++ b/widget/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ + - - + + diff --git a/widget/src/main/java/com/uploadcare/android/widget/worker/FileUploadWorker.kt b/widget/src/main/java/com/uploadcare/android/widget/worker/FileUploadWorker.kt index f9a7f5bc..903780de 100644 --- a/widget/src/main/java/com/uploadcare/android/widget/worker/FileUploadWorker.kt +++ b/widget/src/main/java/com/uploadcare/android/widget/worker/FileUploadWorker.kt @@ -3,6 +3,7 @@ package com.uploadcare.android.widget.worker import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC import android.os.Build import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat @@ -99,7 +100,15 @@ class FileUploadWorker(appContext: Context, private fun createForegroundInfo(notificationBuilder: NotificationCompat.Builder) : ForegroundInfo { //Notification ID - return ForegroundInfo(NOTIFICATION_ID, notificationBuilder.build()) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + ForegroundInfo( + NOTIFICATION_ID, + notificationBuilder.build(), + FOREGROUND_SERVICE_TYPE_DATA_SYNC + ) + } else { + ForegroundInfo(NOTIFICATION_ID, notificationBuilder.build()) + } } private fun updateNotificationProgress(content: String, progress: Int) { diff --git a/widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWorkManagerInitializer.kt b/widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWidgetInitializer.kt similarity index 82% rename from widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWorkManagerInitializer.kt rename to widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWidgetInitializer.kt index b651cf71..11b7a27d 100644 --- a/widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWorkManagerInitializer.kt +++ b/widget/src/main/java/com/uploadcare/android/widget/worker/UploadcareWidgetInitializer.kt @@ -7,8 +7,6 @@ import android.content.pm.ProviderInfo import android.database.Cursor import android.net.Uri import androidx.annotation.RestrictTo -import androidx.work.Configuration -import androidx.work.WorkManager import com.uploadcare.android.widget.controller.UploadcareWidget /** @@ -18,18 +16,11 @@ import com.uploadcare.android.widget.controller.UploadcareWidget * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -class UploadcareWorkManagerInitializer : ContentProvider() { +class UploadcareWidgetInitializer : ContentProvider() { override fun onCreate(): Boolean { //Initialize UploadcareWidget. UploadcareWidget.init(context!!) - // provide custom configuration - val workManagerConfig = Configuration.Builder() - .setMinimumLoggingLevel(android.util.Log.INFO) - .build() - - // initialize WorkManager - WorkManager.initialize(context!!, workManagerConfig) return true } From e5674c85370d612649728e04d6e6527dc77d0eb5 Mon Sep 17 00:00:00 2001 From: Dmitry Voronov Date: Fri, 26 Jul 2024 10:19:24 +0100 Subject: [PATCH 2/6] Updates Pre-requisites section of the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ceb694b2..af826ffc 100644 --- a/README.md +++ b/README.md @@ -50,5 +50,5 @@ Supported features: * Gradle 7.6 * JDK 11 -* Android SDK 34 +* Android SDK 22 From 3999e3f6530b99cb8cb5fb345b3f4ffcc20402d4 Mon Sep 17 00:00:00 2001 From: Dmitry Voronov Date: Fri, 26 Jul 2024 10:31:50 +0100 Subject: [PATCH 3/6] Bump version --- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- library/README.md | 2 +- widget/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1ae07acb..41e9de1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project-wide Gradle settings. -version=4.3.1 +version=4.3.2 # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 45e0f75a..8eea6c7a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -appVersion = "4.3.1" +appVersion = "4.3.2" kotlinVersion = "1.9.23" kotlinCoroutines = "1.8.0" minSdk = "22" diff --git a/library/README.md b/library/README.md index 1ff3e6c4..7129907f 100644 --- a/library/README.md +++ b/library/README.md @@ -25,5 +25,5 @@ The latest stable version is available at Maven Central. To include it in your Android project, add this line to the 'gradle.build' file: ``` -implementation 'com.uploadcare.android.library:uploadcare-android:4.3.1' +implementation 'com.uploadcare.android.library:uploadcare-android:4.3.2' ``` diff --git a/widget/README.md b/widget/README.md index 9d34668b..b459eebc 100644 --- a/widget/README.md +++ b/widget/README.md @@ -20,5 +20,5 @@ The latest stable version is available at Maven Central. To include it in your Android project, add this line to the 'gradle.build' file: ``` -implementation 'com.uploadcare.android.widget:uploadcare-android-widget:4.3.1' +implementation 'com.uploadcare.android.widget:uploadcare-android-widget:4.3.2' ``` From a52cccacbb2491e32bbaec593d90881cbc38eed9 Mon Sep 17 00:00:00 2001 From: Dmitry Voronov Date: Mon, 12 Aug 2024 15:49:02 +0100 Subject: [PATCH 4/6] Add 4.3.2 version changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 320a0a34..5d75c303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.3.2 +**Widget changes:** +- Remove custom worker initializer to not to force apps to remove the default one in manifest, or to avoid crashes when the app has its own custom initializer +- Add foregroundServiceType to support Android 14 and newer + ## 4.3.1 **Changes:** * bugfix: UploadcareClient class visibility From c8492dd669ffba82c33863532e218ee602340ec6 Mon Sep 17 00:00:00 2001 From: Roman Sedykh Date: Mon, 12 Aug 2024 16:59:48 +0200 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d75c303..c0f9bd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 4.3.2 **Widget changes:** -- Remove custom worker initializer to not to force apps to remove the default one in manifest, or to avoid crashes when the app has its own custom initializer +Remove custom worker initializer to avoid forcing apps to remove the default one in the manifest or to avoid crashes when the app has its own custom initializer - Add foregroundServiceType to support Android 14 and newer ## 4.3.1 From 970c8e151d5bb021531864a909791d2f8ae1156c Mon Sep 17 00:00:00 2001 From: Roman Sedykh Date: Mon, 12 Aug 2024 17:00:35 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f9bd42..3ec67710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 4.3.2 **Widget changes:** -Remove custom worker initializer to avoid forcing apps to remove the default one in the manifest or to avoid crashes when the app has its own custom initializer +- Remove custom worker initializer to avoid forcing apps to remove the default one in the manifest or to avoid crashes when the app has its own custom initializer - Add foregroundServiceType to support Android 14 and newer ## 4.3.1