π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Update BG Sync notification
Prateek Sunal591f143e9bcf
diff --git a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/EnteApplication.kt b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/EnteApplication.ktindex c7942885a6..a7d1ee2627 100644--- a/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/EnteApplication.kt+++ b/mobile/apps/photos/android/app/src/main/kotlin/io/ente/photos/EnteApplication.kt@@ -1,14 +1,17 @@package io.ente.photosimport android.app.Application+import android.app.NotificationChannel+import android.app.NotificationManagerimport android.content.Contextimport android.util.Log-import dev.fluttercommunity.workmanager.NotificationDebugHandler+import androidx.core.app.NotificationCompatimport dev.fluttercommunity.workmanager.TaskDebugInfoimport dev.fluttercommunity.workmanager.TaskResultimport dev.fluttercommunity.workmanager.WorkmanagerDebugimport dev.fluttercommunity.workmanager.pigeon.TaskStatusimport org.json.JSONObject+import kotlin.random.Randomclass EnteApplication : Application() {override fun onCreate() {@@ -20,13 +23,13 @@ class EnteApplication : Application() {const val FLUTTER_SHARED_PREFERENCES = "FlutterSharedPreferences"const val REMOTE_FLAGS_KEY = "flutter.remote_flags"const val INTERNAL_USER_DISABLED_KEY = "flutter.ls.internal_user_disabled"+ const val BG_DEBUG_NOTIFICATIONS_ENABLED_KEY =+ "flutter.ls.bg_debug_notifications_enabled"const val TAG = "EnteApplication"}}private class InternalUserWorkmanagerDebugHandler : WorkmanagerDebug() {- private val delegate = NotificationDebugHandler()-override fun onTaskStatusUpdate(context: Context,taskInfo: TaskDebugInfo,@@ -36,7 +39,9 @@ private class InternalUserWorkmanagerDebugHandler : WorkmanagerDebug() {if (!shouldEnableWorkmanagerDebugNotifications(context)) {return}- delegate.onTaskStatusUpdate(context, taskInfo, status, result)++ val notification = formatNotification(taskInfo, status, result) ?: return+ postNotification(context, notification.first, notification.second)}override fun onExceptionEncountered(@@ -47,7 +52,12 @@ private class InternalUserWorkmanagerDebugHandler : WorkmanagerDebug() {if (!shouldEnableWorkmanagerDebugNotifications(context)) {return}- delegate.onExceptionEncountered(context, taskInfo, exception)+ val taskName = taskInfo?.taskName ?: "unknown"+ postNotification(+ context,+ "Failed",+ "$taskName\n${exception.message ?: "Unknown exception"}",+ )}private fun shouldEnableWorkmanagerDebugNotifications(context: Context): Boolean {@@ -59,8 +69,11 @@ private class InternalUserWorkmanagerDebugHandler : WorkmanagerDebug() {if (prefs.getBoolean(EnteApplication.INTERNAL_USER_DISABLED_KEY, false)) {return false}+ if (!prefs.getBoolean(EnteApplication.BG_DEBUG_NOTIFICATIONS_ENABLED_KEY, true)) {+ return false+ }- return BuildConfig.DEBUG || isInternalUser(prefs.getString(EnteApplication.REMOTE_FLAGS_KEY, null))+ return isInternalUser(prefs.getString(EnteApplication.REMOTE_FLAGS_KEY, null))}private fun isInternalUser(remoteFlags: String?): Boolean {@@ -79,4 +92,88 @@ private class InternalUserWorkmanagerDebugHandler : WorkmanagerDebug() {false}}++ private fun formatNotification(+ taskInfo: TaskDebugInfo,+ status: TaskStatus,+ result: TaskResult?,+ ): Pair<String, String>? {+ return when (status) {+ TaskStatus.SCHEDULED -> "Scheduled" to taskInfo.taskName+ TaskStatus.STARTED -> "Started" to taskInfo.taskName+ TaskStatus.RETRYING -> "Retrying" to taskInfo.taskName+ TaskStatus.RESCHEDULED -> "Rescheduled" to taskInfo.taskName+ TaskStatus.COMPLETED -> {+ val duration = (result?.duration ?: 0) / 1000+ "Success ${duration}s" to taskInfo.taskName+ }+ TaskStatus.FAILED -> {+ val duration = (result?.duration ?: 0) / 1000+ val error = result?.error ?: "Unknown"+ "Failed ${duration}s" to "${taskInfo.taskName}\n$error"+ }+ TaskStatus.CANCELLED -> "Cancelled" to taskInfo.taskName+ }+ }++ private fun postNotification(+ context: Context,+ title: String,+ content: String,+ ) {+ val notificationManager =+ context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager+ ensureNotificationChannel(notificationManager)++ val notification =+ NotificationCompat.Builder(context, CHANNEL_ID)+ .setContentTitle(title)+ .setContentText(content)+ .setStyle(NotificationCompat.BigTextStyle().bigText(content))+ .setSmallIcon(android.R.drawable.stat_notify_sync)+ .setPriority(NotificationCompat.PRIORITY_MIN)+ .setGroup(GROUP_KEY)+ .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)+ .setSilent(true)+ .setOnlyAlertOnce(true)+ .build()++ notificationManager.notify(Random.nextInt(), notification)+ notificationManager.notify(SUMMARY_NOTIFICATION_ID, buildSummaryNotification(context))+ }++ private fun ensureNotificationChannel(notificationManager: NotificationManager) {+ val channel =+ NotificationChannel(+ CHANNEL_ID,+ CHANNEL_NAME,+ NotificationManager.IMPORTANCE_MIN,+ ).apply {+ setSound(null, null)+ enableVibration(false)+ vibrationPattern = longArrayOf(0L)+ setShowBadge(false)+ }+ notificationManager.createNotificationChannel(channel)+ }++ private fun buildSummaryNotification(context: Context) =+ NotificationCompat.Builder(context, CHANNEL_ID)+ .setContentTitle("Workmanager Debug")+ .setContentText("Background task updates")+ .setSmallIcon(android.R.drawable.stat_notify_sync)+ .setPriority(NotificationCompat.PRIORITY_MIN)+ .setGroup(GROUP_KEY)+ .setGroupSummary(true)+ .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)+ .setSilent(true)+ .setOnlyAlertOnce(true)+ .build()++ private companion object {+ const val CHANNEL_ID = "io.ente.photos.workmanager.debug"+ const val CHANNEL_NAME = "Workmanager Debug"+ const val GROUP_KEY = "io.ente.photos.workmanager.debug.group"+ const val SUMMARY_NOTIFICATION_ID = 424242+ }}diff --git a/mobile/apps/photos/ios/Podfile.lock b/mobile/apps/photos/ios/Podfile.lockindex 8896f1c714..34e498dde7 100644--- a/mobile/apps/photos/ios/Podfile.lock+++ b/mobile/apps/photos/ios/Podfile.lock@@ -18,6 +18,8 @@ PODS:- Flutter- ente_photos_rust (0.0.1):- Flutter+ - ente_qr (0.0.1):+ - Flutter- ente_rust (0.0.1):- Flutter- ffmpeg_kit_custom (6.0.3)@@ -271,6 +273,7 @@ DEPENDENCIES:- dart_ui_isolate (from `.symlinks/plugins/dart_ui_isolate/ios`)- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)- ente_photos_rust (from `.symlinks/plugins/ente_photos_rust/ios`)+ - ente_qr (from `.symlinks/plugins/ente_qr/ios`)- ente_rust (from `.symlinks/plugins/ente_rust/ios`)- ffmpeg_kit_flutter (from `.symlinks/plugins/ffmpeg_kit_flutter/ios`)- file_saver (from `.symlinks/plugins/file_saver/ios`)@@ -369,6 +372,8 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/device_info_plus/ios"ente_photos_rust::path: ".symlinks/plugins/ente_photos_rust/ios"+ ente_qr:+ :path: ".symlinks/plugins/ente_qr/ios"ente_rust::path: ".symlinks/plugins/ente_rust/ios"ffmpeg_kit_flutter:@@ -490,6 +495,7 @@ SPEC CHECKSUMS:dart_ui_isolate: 46f6714abe6891313267153ef6f9748d8ecfcab1device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbeente_photos_rust: 79732f3ba67df7b0fb22089627afb80d692c2b2d+ ente_qr: 2a30f91f9e938c229ebcbc98a6f8f018d1ac665dente_rust: 9c976e3d083f0ce90f31693deb99629b28d8fe4cffmpeg_kit_custom: 682b4f2f1ff1f8abae5a92f6c3540f2441d5be99ffmpeg_kit_flutter: 915b345acc97d4142e8a9a8549d177ff10f043f5diff --git a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxprojindex 9fbcd71200..ca3d7ec9bc 100644--- a/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj+++ b/mobile/apps/photos/ios/Runner.xcodeproj/project.pbxproj@@ -637,6 +637,7 @@"${BUILT_PRODUCTS_DIR}/dart_ui_isolate/dart_ui_isolate.framework","${BUILT_PRODUCTS_DIR}/device_info_plus/device_info_plus.framework","${BUILT_PRODUCTS_DIR}/ente_photos_rust/ente_photos_rust.framework",+ "${BUILT_PRODUCTS_DIR}/ente_qr/ente_qr.framework","${BUILT_PRODUCTS_DIR}/ente_rust/ente_rust.framework","${BUILT_PRODUCTS_DIR}/file_saver/file_saver.framework","${BUILT_PRODUCTS_DIR}/flutter_email_sender/flutter_email_sender.framework",@@ -739,6 +740,7 @@"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/dart_ui_isolate.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info_plus.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_photos_rust.framework",+ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_qr.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ente_rust.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/file_saver.framework","${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_email_sender.framework",diff --git a/mobile/apps/photos/ios/Runner/AppDelegate.swift b/mobile/apps/photos/ios/Runner/AppDelegate.swiftindex fa973e26fd..2d4b3d0988 100644--- a/mobile/apps/photos/ios/Runner/AppDelegate.swift+++ b/mobile/apps/photos/ios/Runner/AppDelegate.swift@@ -1,16 +1,20 @@import AVFoundationimport Flutterimport UIKit+import UserNotificationsimport app_linksimport workmanager_apple@main@objc class AppDelegate: FlutterAppDelegate {+ private static let workmanagerDebugThreadIdentifier =+ "io.ente.frame.workmanager.debug"+override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {- WorkmanagerDebug.setCurrent(InternalUserWorkmanagerDebugHandler())+ configureWorkmanagerDebugHandler()// Prevent interrupting background audio from other apps on launchdo {@@ -50,26 +54,14 @@ import workmanager_applereturn super.application(application, didFinishLaunchingWithOptions: launchOptions)}- override func applicationDidBecomeActive(_ application: UIApplication) {- signal(SIGPIPE, SIG_IGN)- }-- override func applicationWillEnterForeground(_ application: UIApplication) {- signal(SIGPIPE, SIG_IGN)- }-}--private final class InternalUserWorkmanagerDebugHandler: WorkmanagerDebug {- private let delegate = NotificationDebugHandler()-- override func onTaskStatusUpdate(taskInfo: TaskDebugInfo, status: TaskStatus, result: TaskResult?) {- guard shouldEnableWorkmanagerDebugNotifications() else { return }- delegate.onTaskStatusUpdate(taskInfo: taskInfo, status: status, result: result)- }+ private func configureWorkmanagerDebugHandler() {+ guard shouldEnableWorkmanagerDebugNotifications() else {+ return+ }- override func onExceptionEncountered(taskInfo: TaskDebugInfo?, exception: Error) {- guard shouldEnableWorkmanagerDebugNotifications() else { return }- delegate.onExceptionEncountered(taskInfo: taskInfo, exception: exception)+ WorkmanagerDebug.setCurrent(+ NotificationDebugHandler(threadIdentifier: Self.workmanagerDebugThreadIdentifier)+ )}private func shouldEnableWorkmanagerDebugNotifications() -> Bool {@@ -77,18 +69,44 @@ private final class InternalUserWorkmanagerDebugHandler: WorkmanagerDebug {if defaults.bool(forKey: "flutter.ls.internal_user_disabled") {return false}+ if !defaults.bool(forKey: "flutter.ls.bg_debug_notifications_enabled") &&+ defaults.object(forKey: "flutter.ls.bg_debug_notifications_enabled") != nil {+ return false+ }- #if DEBUG- return true- #else- guard let remoteFlags = defaults.string(forKey: "flutter.remote_flags"),- let data = remoteFlags.data(using: .utf8),- let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any]- else {- return false+ guard let remoteFlags = defaults.string(forKey: "flutter.remote_flags"),+ let data = remoteFlags.data(using: .utf8),+ let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any]+ else {+ return false+ }++ return json["internalUser"] as? Bool ?? false+ }++ override func applicationDidBecomeActive(_ application: UIApplication) {+ signal(SIGPIPE, SIG_IGN)+ }++ override func applicationWillEnterForeground(_ application: UIApplication) {+ signal(SIGPIPE, SIG_IGN)+ }++ override func userNotificationCenter(+ _ center: UNUserNotificationCenter,+ willPresent notification: UNNotification,+ withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void+ ) {+ let content = notification.request.content+ if content.threadIdentifier == Self.workmanagerDebugThreadIdentifier {+ if #available(iOS 14.0, *) {+ completionHandler([.list, .banner])+ } else {+ completionHandler([.alert])}+ return+ }- return json["internalUser"] as? Bool ?? false- #endif+ completionHandler([])}}diff --git a/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart b/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dartindex 1f0e273ff8..b67f0b022e 100644--- a/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/debug/debug_settings_page.dart@@ -108,6 +108,30 @@ class _DebugSettingsPageState extends State<DebugSettingsPage> {},),),+ MenuItemWidgetNew(+ title: "Background sync notification",+ leadingIconWidget: _buildIconWidget(+ context,+ HugeIcons.strokeRoundedNotification01,+ ),+ trailingWidget: ToggleSwitchWidget(+ value: () =>+ localSettings.isBGDebugNotificationsEnabled,+ onChanged: () async {+ final newValue =+ !localSettings.isBGDebugNotificationsEnabled;+ await localSettings+ .setBGDebugNotificationsEnabled(newValue);+ setState(() {});+ showShortToast(+ context,+ newValue+ ? "Background debug notifications enabled. Restart app."+ : "Background debug notifications disabled. Restart app.",+ );+ },+ ),+ ),MenuItemWidgetNew(title: "Enable database logging",leadingIconWidget: _buildIconWidget(diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dartindex 7cf7c67681..34bfd1cb3d 100644--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart@@ -87,7 +87,9 @@ class BgTaskUtils {frequency: Platform.isIOS? const Duration(minutes: 30): const Duration(minutes: 15),- initialDelay: kDebugMode ? Duration.zero : const Duration(minutes: 10),+ // TODO: Remove the forced zero delay once Workmanager debug notification testing is done.+ initialDelay:+ (kDebugMode || true) ? Duration.zero : const Duration(minutes: 10),constraints: workmanager.Constraints(networkType: workmanager.NetworkType.connected,requiresCharging: false,diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dartindex 6bdb9363e0..471b7e89e2 100644--- a/mobile/apps/photos/lib/utils/local_settings.dart+++ b/mobile/apps/photos/lib/utils/local_settings.dart@@ -71,6 +71,8 @@ class LocalSettings {static const kShowLocalIDOverThumbnails = "show_local_id_over_thumbnails";static const kEnableDatabaseLogging = "enable_db_logging";static const _kInternalUserDisabled = "ls.internal_user_disabled";+ static const _kBGDebugNotificationsEnabled =+ "ls.bg_debug_notifications_enabled";static const _kCFUploadProxyEnabled = "ls.cf_upload_proxy_enabled";static const _kSharedPhotoFeedCutoffTime = "ls.shared_photo_feed_cutoff_time";static const _kWrapped2025ResumeIndex = "ls.wrapped_2025_resume_index";@@ -416,6 +418,13 @@ class LocalSettings {await _prefs.setBool(_kInternalUserDisabled, value);}+ bool get isBGDebugNotificationsEnabled =>+ _prefs.getBool(_kBGDebugNotificationsEnabled) ?? true;++ Future<void> setBGDebugNotificationsEnabled(bool value) async {+ await _prefs.setBool(_kBGDebugNotificationsEnabled, value);+ }+bool get isCFUploadProxyEnabled =>_prefs.getBool(_kCFUploadProxyEnabled) ?? true;