From 91b77b6d6363abeeded8a3fc26560368870e6ec7 Mon Sep 17 00:00:00 2001
From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
Date: Wed, 14 Jun 2023 11:08:51 +0300
Subject: [PATCH] android: restart and shutdown the app with buttons (#2578)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
---
apps/android/app/build.gradle | 1 +
.../main/java/chat/simplex/app/SimplexApp.kt | 4 +++
.../java/chat/simplex/app/SimplexService.kt | 1 -
.../app/views/usersettings/SettingsView.kt | 30 ++++++++++++++++---
.../res/drawable/ic_power_settings_new.xml | 4 +++
.../src/main/res/drawable/ic_restart_alt.xml | 4 +++
.../app/src/main/res/values-cs/strings.xml | 1 -
.../app/src/main/res/values-de/strings.xml | 1 -
.../app/src/main/res/values-es/strings.xml | 1 -
.../app/src/main/res/values-fr/strings.xml | 1 -
.../app/src/main/res/values-hi/strings.xml | 1 -
.../app/src/main/res/values-it/strings.xml | 1 -
.../app/src/main/res/values-iw/strings.xml | 1 -
.../app/src/main/res/values-ja/strings.xml | 1 -
.../app/src/main/res/values-ko/strings.xml | 1 -
.../app/src/main/res/values-nl/strings.xml | 1 -
.../app/src/main/res/values-pl/strings.xml | 1 -
.../src/main/res/values-pt-rBR/strings.xml | 1 -
.../app/src/main/res/values-ru/strings.xml | 1 -
.../src/main/res/values-zh-rCN/strings.xml | 1 -
.../src/main/res/values-zh-rTW/strings.xml | 1 -
.../app/src/main/res/values/strings.xml | 6 +++-
22 files changed, 44 insertions(+), 21 deletions(-)
create mode 100644 apps/android/app/src/main/res/drawable/ic_power_settings_new.xml
create mode 100644 apps/android/app/src/main/res/drawable/ic_restart_alt.xml
diff --git a/apps/android/app/build.gradle b/apps/android/app/build.gradle
index c191e05097..4f8b6cbe30 100644
--- a/apps/android/app/build.gradle
+++ b/apps/android/app/build.gradle
@@ -170,6 +170,7 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
+ implementation "com.jakewharton:process-phoenix:2.1.2"
}
// Don't do anything if no compression is needed
diff --git a/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt b/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt
index 0e5af1b6be..7a2aecaae6 100644
--- a/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt
+++ b/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt
@@ -10,6 +10,7 @@ import chat.simplex.app.ui.theme.DefaultTheme
import chat.simplex.app.views.helpers.*
import chat.simplex.app.views.onboarding.OnboardingStage
import chat.simplex.app.views.usersettings.NotificationsMode
+import com.jakewharton.processphoenix.ProcessPhoenix
import kotlinx.coroutines.*
import kotlinx.serialization.decodeFromString
import java.io.*
@@ -101,6 +102,9 @@ class SimplexApp: Application(), LifecycleEventObserver {
override fun onCreate() {
super.onCreate()
+ if (ProcessPhoenix.isPhoenixProcess(this)) {
+ return;
+ }
context = this
context.getDir("temp", MODE_PRIVATE).deleteRecursively()
withBGApi {
diff --git a/apps/android/app/src/main/java/chat/simplex/app/SimplexService.kt b/apps/android/app/src/main/java/chat/simplex/app/SimplexService.kt
index 497dc2ac86..42bfbe7298 100644
--- a/apps/android/app/src/main/java/chat/simplex/app/SimplexService.kt
+++ b/apps/android/app/src/main/java/chat/simplex/app/SimplexService.kt
@@ -166,7 +166,6 @@ class SimplexService: Service() {
it.setPackage(packageName)
};
val restartServicePendingIntent: PendingIntent = PendingIntent.getService(this, 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE);
- applicationContext.getSystemService(Context.ALARM_SERVICE);
val alarmService: AlarmManager = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager;
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent);
}
diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt
index 1875dc9cac..2966a65709 100644
--- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt
+++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt
@@ -6,7 +6,7 @@ import SectionItemView
import SectionItemViewWithIcon
import SectionView
import TextIconSpaced
-import android.content.Context
+import android.content.*
import android.content.res.Configuration
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
@@ -25,16 +25,16 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.*
import androidx.fragment.app.FragmentActivity
+import androidx.work.WorkManager
import chat.simplex.app.*
import chat.simplex.app.R
import chat.simplex.app.model.*
import chat.simplex.app.ui.theme.*
import chat.simplex.app.views.database.DatabaseView
import chat.simplex.app.views.helpers.*
-import chat.simplex.app.views.newchat.CreateLinkTab
-import chat.simplex.app.views.newchat.CreateLinkView
import chat.simplex.app.views.onboarding.SimpleXInfo
import chat.simplex.app.views.onboarding.WhatsNewView
+import com.jakewharton.processphoenix.ProcessPhoenix
@Composable
fun SettingsView(chatModel: ChatModel, setPerformLA: (Boolean, FragmentActivity) -> Unit) {
@@ -181,7 +181,9 @@ fun SettingsLayout(
}
SectionDividerSpaced()
- SectionView(stringResource(R.string.settings_section_title_develop)) {
+ SectionView(stringResource(R.string.settings_section_title_app)) {
+ SettingsActionItem(painterResource(R.drawable.ic_restart_alt), stringResource(R.string.settings_restart_app), ::restartApp, extraPadding = true)
+ SettingsActionItem(painterResource(R.drawable.ic_power_settings_new), stringResource(R.string.settings_shutdown), { shutdownAppAlert(::shutdownApp) }, extraPadding = true)
SettingsActionItem(painterResource(R.drawable.ic_code), stringResource(R.string.settings_developer_tools), showSettingsModal { DeveloperView(it, showCustomModal, withAuth) }, extraPadding = true)
AppVersionItem(showVersion)
}
@@ -490,6 +492,26 @@ private fun runAuth(title: String, desc: String, context: Context, onFinish: (su
)
}
+private fun restartApp() {
+ ProcessPhoenix.triggerRebirth(SimplexApp.context)
+ shutdownApp()
+}
+
+private fun shutdownApp() {
+ WorkManager.getInstance(SimplexApp.context).cancelAllWork()
+ SimplexService.safeStopService(SimplexApp.context)
+ Runtime.getRuntime().exit(0)
+}
+
+private fun shutdownAppAlert(onConfirm: () -> Unit) {
+ AlertManager.shared.showAlertDialog(
+ title = generalGetString(R.string.shutdown_alert_question),
+ text = generalGetString(R.string.shutdown_alert_desc),
+ destructive = true,
+ onConfirm = onConfirm
+ )
+}
+
@Preview(showBackground = true)
@Preview(
uiMode = Configuration.UI_MODE_NIGHT_YES,
diff --git a/apps/android/app/src/main/res/drawable/ic_power_settings_new.xml b/apps/android/app/src/main/res/drawable/ic_power_settings_new.xml
new file mode 100644
index 0000000000..a73a866f2e
--- /dev/null
+++ b/apps/android/app/src/main/res/drawable/ic_power_settings_new.xml
@@ -0,0 +1,4 @@
+
+
+
diff --git a/apps/android/app/src/main/res/drawable/ic_restart_alt.xml b/apps/android/app/src/main/res/drawable/ic_restart_alt.xml
new file mode 100644
index 0000000000..92043a534d
--- /dev/null
+++ b/apps/android/app/src/main/res/drawable/ic_restart_alt.xml
@@ -0,0 +1,4 @@
+
+
+
diff --git a/apps/android/app/src/main/res/values-cs/strings.xml b/apps/android/app/src/main/res/values-cs/strings.xml
index dc17bd2d53..a8d430c6a1 100644
--- a/apps/android/app/src/main/res/values-cs/strings.xml
+++ b/apps/android/app/src/main/res/values-cs/strings.xml
@@ -723,7 +723,6 @@
\n3. Spojení je kompromitováno.
VY
PODPOŘIT SIMPLEX CHAT
- VÝVOJ
Nástroje pro vývojáře
inkognito mód
Chat databáze
diff --git a/apps/android/app/src/main/res/values-de/strings.xml b/apps/android/app/src/main/res/values-de/strings.xml
index bbbe6f3a7a..939bc087af 100644
--- a/apps/android/app/src/main/res/values-de/strings.xml
+++ b/apps/android/app/src/main/res/values-de/strings.xml
@@ -564,7 +564,6 @@
EINSTELLUNGEN
HILFE
UNTERSTÜTZUNG VON SIMPLEX CHAT
- ENTWICKLUNG
GERÄT
CHATS
Entwicklertools
diff --git a/apps/android/app/src/main/res/values-es/strings.xml b/apps/android/app/src/main/res/values-es/strings.xml
index 1a6f3d8818..862465fe98 100644
--- a/apps/android/app/src/main/res/values-es/strings.xml
+++ b/apps/android/app/src/main/res/values-es/strings.xml
@@ -114,7 +114,6 @@
Llamada con cifrado de extremo a extremo
cifrado de extremo a extremo
mensaje duplicado
- DESARROLLO
Herramientas desarrollo
Eliminar los archivos de todos los perfiles
Eliminar mensaje
diff --git a/apps/android/app/src/main/res/values-fr/strings.xml b/apps/android/app/src/main/res/values-fr/strings.xml
index 1f2bff2a09..c1a6268a8f 100644
--- a/apps/android/app/src/main/res/values-fr/strings.xml
+++ b/apps/android/app/src/main/res/values-fr/strings.xml
@@ -535,7 +535,6 @@
Appel déjà terminé !
Appels audio et vidéo
chiffré de bout en bout
- DEVELOPPER
Fonctionnalités expérimentales
SOCKS PROXY
THEMES
diff --git a/apps/android/app/src/main/res/values-hi/strings.xml b/apps/android/app/src/main/res/values-hi/strings.xml
index ac5cfc339d..8b619b3bfa 100644
--- a/apps/android/app/src/main/res/values-hi/strings.xml
+++ b/apps/android/app/src/main/res/values-hi/strings.xml
@@ -271,7 +271,6 @@
%s के लिए पता बदल रहा है…
दोबारा मत दिखाओ
आप और आपका संपर्क दोनों ध्वनि संदेश भेज सकते हैं।
- विकास करना
आवाज़ बंद करना
अपने संपर्कों को गायब होने वाले संदेश भेजने की अनुमति दें।
ऑडियो और वीडियो कॉल
diff --git a/apps/android/app/src/main/res/values-it/strings.xml b/apps/android/app/src/main/res/values-it/strings.xml
index 4b172ce681..3dd6c9d846 100644
--- a/apps/android/app/src/main/res/values-it/strings.xml
+++ b/apps/android/app/src/main/res/values-it/strings.xml
@@ -395,7 +395,6 @@
Password del database
Eliminare il profilo di chat\?
Elimina database
- SVILUPPA
Strumenti di sviluppo
DISPOSITIVO
Errore nell\'eliminazione del database della chat
diff --git a/apps/android/app/src/main/res/values-iw/strings.xml b/apps/android/app/src/main/res/values-iw/strings.xml
index 05b2f182d0..942687a1de 100644
--- a/apps/android/app/src/main/res/values-iw/strings.xml
+++ b/apps/android/app/src/main/res/values-iw/strings.xml
@@ -328,7 +328,6 @@
מחק קבוצה
למחוק קבוצה\?
💻 שולחן עבודה: סירקו את קוד ה־QR המוצג באפליקציה, באמצעות סריקת קוד QR.
- פיתוח
מכשיר
נעילת המכשיר מושבתת. מכבה נעילת SimpleX.
נעילת המכשיר אינה מופעלת. ניתן להפעיל את נעילת SimpleX, לאחר שתפעילו את נעילת המכשיר.
diff --git a/apps/android/app/src/main/res/values-ja/strings.xml b/apps/android/app/src/main/res/values-ja/strings.xml
index 04b86d8868..883cf2b99b 100644
--- a/apps/android/app/src/main/res/values-ja/strings.xml
+++ b/apps/android/app/src/main/res/values-ja/strings.xml
@@ -349,7 +349,6 @@
カメラ切り替え
不在着信
拒否した通話
- 開発
重複メッセージ
ヘルプ
アプリ画面を守る
diff --git a/apps/android/app/src/main/res/values-ko/strings.xml b/apps/android/app/src/main/res/values-ko/strings.xml
index ed05450d1e..544ea2a015 100644
--- a/apps/android/app/src/main/res/values-ko/strings.xml
+++ b/apps/android/app/src/main/res/values-ko/strings.xml
@@ -232,7 +232,6 @@
주소를 삭제할까요\?
이미지 삭제
탈중앙화
- 개발
개발자 도구
기기
데이터베이스 비밀번호
diff --git a/apps/android/app/src/main/res/values-nl/strings.xml b/apps/android/app/src/main/res/values-nl/strings.xml
index 9a420ec046..f40123fa0d 100644
--- a/apps/android/app/src/main/res/values-nl/strings.xml
+++ b/apps/android/app/src/main/res/values-nl/strings.xml
@@ -242,7 +242,6 @@
Verwijderen voor iedereen
Link verwijderen
direct
- ONTWIKKELEN
APPARAAT
Verwijder alle bestanden
Berichten verwijderen na
diff --git a/apps/android/app/src/main/res/values-pl/strings.xml b/apps/android/app/src/main/res/values-pl/strings.xml
index e3d4f5f894..794cc6f7d8 100644
--- a/apps/android/app/src/main/res/values-pl/strings.xml
+++ b/apps/android/app/src/main/res/values-pl/strings.xml
@@ -515,7 +515,6 @@
CZATY
Hasło do bazy danych
Usuń bazę danych
- DEWELOPERSKIE
Narzędzia deweloperskie
URZĄDZENIE
Błąd uruchamiania czatu
diff --git a/apps/android/app/src/main/res/values-pt-rBR/strings.xml b/apps/android/app/src/main/res/values-pt-rBR/strings.xml
index 8d3f536fe7..ba715afaaf 100644
--- a/apps/android/app/src/main/res/values-pt-rBR/strings.xml
+++ b/apps/android/app/src/main/res/values-pt-rBR/strings.xml
@@ -745,7 +745,6 @@
chamada perdida
Você pode usar markdown para formatar mensagens:
chamada rejeitada
- DESENVOLVER
saiu
Versão do banco de dados incompatível
Remover membro
diff --git a/apps/android/app/src/main/res/values-ru/strings.xml b/apps/android/app/src/main/res/values-ru/strings.xml
index dd17625aab..3cfb5ac057 100644
--- a/apps/android/app/src/main/res/values-ru/strings.xml
+++ b/apps/android/app/src/main/res/values-ru/strings.xml
@@ -568,7 +568,6 @@
НАСТРОЙКИ
ПОМОЩЬ
ПОДДЕРЖАТЬ SIMPLEX CHAT
- ДЛЯ РАЗРАБОТЧИКОВ
УСТРОЙСТВО
ЧАТЫ
Инструменты разработчика
diff --git a/apps/android/app/src/main/res/values-zh-rCN/strings.xml b/apps/android/app/src/main/res/values-zh-rCN/strings.xml
index 686f79d04d..f6e6ef2406 100644
--- a/apps/android/app/src/main/res/values-zh-rCN/strings.xml
+++ b/apps/android/app/src/main/res/values-zh-rCN/strings.xml
@@ -378,7 +378,6 @@
加密数据库?
数据库使用随机密码进行加密,您可以更改它。
打开聊天需要数据库密码。
- 开发
停止聊天错误
导入聊天数据库?
删除聊天数据库错误
diff --git a/apps/android/app/src/main/res/values-zh-rTW/strings.xml b/apps/android/app/src/main/res/values-zh-rTW/strings.xml
index 01e7c2067d..23414ebec2 100644
--- a/apps/android/app/src/main/res/values-zh-rTW/strings.xml
+++ b/apps/android/app/src/main/res/values-zh-rTW/strings.xml
@@ -681,7 +681,6 @@
重覆的訊息
保護應用程式螢幕
傳送可以預覽的連結
- 開發
裝置
幫助
設定
diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml
index 2017bae844..13108eb090 100644
--- a/apps/android/app/src/main/res/values/strings.xml
+++ b/apps/android/app/src/main/res/values/strings.xml
@@ -602,6 +602,8 @@
Hide:
Show developer options
Database IDs and Transport isolation option.
+ Shutdown?
+ Notifications will stop working until you re-launch the app
Create address
@@ -851,9 +853,11 @@
SETTINGS
HELP
SUPPORT SIMPLEX CHAT
- DEVELOP
+ APP
DEVICE
CHATS
+ Restart
+ Shutdown
Developer tools
Experimental features
SOCKS PROXY