diff --git a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt
index f46ed4775f..0ebd9ca2c6 100644
--- a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt
+++ b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt
@@ -332,6 +332,8 @@ class SimplexApp: Application(), LifecycleEventObserver {
NetworkObserver.shared.restartNetworkObserver()
}
+ override fun androidIsXiaomiDevice(): Boolean = setOf("xiaomi", "redmi", "poco").contains(Build.BRAND.lowercase())
+
@SuppressLint("SourceLockedOrientationActivity")
@Composable
override fun androidLockPortraitOrientation() {
diff --git a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt
index ce3f0825b8..33799087a7 100644
--- a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt
+++ b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexService.kt
@@ -497,6 +497,12 @@ class SimplexService: Service() {
Modifier.padding(bottom = 8.dp)
)
Text(annotatedStringResource(MR.strings.turn_off_battery_optimization))
+
+ if (platform.androidIsXiaomiDevice() && (mode == NotificationsMode.PERIODIC || mode == NotificationsMode.SERVICE)) {
+ Text(annotatedStringResource(MR.strings.xiaomi_ignore_battery_optimization),
+ Modifier.padding(top = 8.dp)
+ )
+ }
}
},
dismissButton = {
@@ -623,7 +629,7 @@ class SimplexService: Service() {
fun isBackgroundAllowed(): Boolean = isIgnoringBatteryOptimizations() && !isBackgroundRestricted()
- fun isIgnoringBatteryOptimizations(): Boolean {
+ private fun isIgnoringBatteryOptimizations(): Boolean {
val powerManager = androidAppContext.getSystemService(Application.POWER_SERVICE) as PowerManager
return powerManager.isIgnoringBatteryOptimizations(androidAppContext.packageName)
}
diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt
index 23ab450cb6..e0a9e22f71 100644
--- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt
+++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt
@@ -26,6 +26,7 @@ interface PlatformInterface {
fun androidPictureInPictureAllowed(): Boolean = true
fun androidCallEnded() {}
fun androidRestartNetworkObserver() {}
+ fun androidIsXiaomiDevice(): Boolean = false
val androidApiLevel: Int? get() = null
@Composable fun androidLockPortraitOrientation() {}
suspend fun androidAskToAllowBackgroundCalls(): Boolean = true
diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NotificationsSettingsView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NotificationsSettingsView.kt
index 60bde83c17..66b518e9aa 100644
--- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NotificationsSettingsView.kt
+++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NotificationsSettingsView.kt
@@ -1,11 +1,10 @@
package chat.simplex.common.views.usersettings
import SectionBottomSpacer
+import SectionTextFooter
import SectionView
import SectionViewSelectable
import androidx.compose.foundation.layout.*
-import androidx.compose.foundation.rememberScrollState
-import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
@@ -16,6 +15,7 @@ import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.style.TextOverflow
import chat.simplex.common.model.*
import chat.simplex.common.platform.*
+import chat.simplex.common.ui.theme.DEFAULT_PADDING_HALF
import chat.simplex.common.views.helpers.*
import chat.simplex.res.MR
import kotlin.collections.ArrayList
@@ -77,6 +77,9 @@ fun NotificationsSettingsLayout(
color = MaterialTheme.colors.secondary
)
}
+ if (platform.androidIsXiaomiDevice() && (notificationsMode.value == NotificationsMode.PERIODIC || notificationsMode.value == NotificationsMode.SERVICE)) {
+ SectionTextFooter(stringResource(MR.strings.xiaomi_ignore_battery_optimization))
+ }
}
SectionBottomSpacer()
}
@@ -91,6 +94,9 @@ fun NotificationsModeView(
ColumnWithScrollBar {
AppBarTitle(stringResource(MR.strings.settings_notifications_mode_title).lowercase().capitalize(Locale.current))
SectionViewSelectable(null, notificationsMode, modes, onNotificationsModeSelected)
+ if (platform.androidIsXiaomiDevice() && (notificationsMode.value == NotificationsMode.PERIODIC || notificationsMode.value == NotificationsMode.SERVICE)) {
+ SectionTextFooter(stringResource(MR.strings.xiaomi_ignore_battery_optimization))
+ }
}
}
diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
index 1c036d76b2..c390096ee2 100644
--- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
+++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
@@ -191,9 +191,9 @@
Instant notifications
Instant notifications!
Instant notifications are disabled!
- SimpleX background service – it uses a few percent of the battery per day.]]>
+ SimpleX runs in background instead of using push notifications.]]>
It can be disabled via settings – notifications will still be shown while the app is running.]]>
- allow SimpleX to run in background in the next dialog. Otherwise, the notifications will be disabled.]]>
+ Allow it in the next dialog to receive notifications instantly.]]>
Battery optimization is active, turning off background service and periodic requests for new messages. You can re-enable them via settings.
Periodic notifications
Periodic notifications are disabled!
@@ -210,6 +210,7 @@
To receive notifications, please, enter the database passphrase
Can\'t initialize the database
The database is not working correctly. Tap to learn more
+ Xiaomi devices: please enable Autostart in the system settings for notifications to work.]]>
SimpleX Chat service