This commit is contained in:
lucky 2022-01-22 18:01:51 +03:00
parent 05863593e9
commit f61578d853
6 changed files with 19 additions and 19 deletions

View File

@ -107,9 +107,9 @@
</service>
<service
android:name=".UnlockService"
android:name=".ForegroundService"
android:exported="false"
android:description="@string/unlock_service_description">
android:description="@string/foreground_service_description">
</service>
<receiver

View File

@ -11,7 +11,7 @@ import android.os.IBinder
import android.os.SystemClock
import androidx.core.app.NotificationCompat
class UnlockService : Service() {
class ForegroundService : Service() {
companion object {
private const val NOTIFICATION_ID = 1000
}
@ -42,7 +42,7 @@ class UnlockService : Service() {
startForeground(
NOTIFICATION_ID,
NotificationCompat.Builder(this, AppNotificationManager.CHANNEL_DEFAULT_ID)
.setContentTitle(getString(R.string.unlock_service_notification_title))
.setContentTitle(getString(R.string.foreground_service_notification_title))
.setSmallIcon(android.R.drawable.ic_delete)
.setPriority(NotificationCompat.PRIORITY_LOW)
.build()

View File

@ -213,16 +213,16 @@ open class MainActivity : AppCompatActivity() {
if (value) {
val launchers = prefs.launchers
setPanicKitState(launchers.and(Launcher.PANIC_KIT.flag) != 0)
setTileState(launchers.and(Launcher.TILE.flag) != 0)
setQSTileState(launchers.and(Launcher.TILE.flag) != 0)
shortcut.setState(launchers.and(Launcher.SHORTCUT.flag) != 0)
setCodeReceiverState(launchers.and(Launcher.BROADCAST.flag) != 0)
setNotificationState(launchers.and(Launcher.NOTIFICATION.flag) != 0)
setNotificationListenerState(launchers.and(Launcher.NOTIFICATION.flag) != 0)
} else {
setPanicKitState(false)
setTileState(false)
setQSTileState(false)
shortcut.setState(false)
setCodeReceiverState(false)
setNotificationState(false)
setNotificationListenerState(false)
}
updateCodeColorState()
}
@ -248,9 +248,9 @@ open class MainActivity : AppCompatActivity() {
setComponentState(CodeReceiver::class.java, value)
private fun setRestartReceiverState(value: Boolean) =
setComponentState(RestartReceiver::class.java, value)
private fun setTileState(value: Boolean) =
private fun setQSTileState(value: Boolean) =
setComponentState(QSTileService::class.java, value)
private fun setNotificationState(value: Boolean) =
private fun setNotificationListenerState(value: Boolean) =
setComponentState(NotificationListenerService::class.java, value)
private fun setPanicKitState(value: Boolean) {
@ -267,8 +267,8 @@ open class MainActivity : AppCompatActivity() {
)
}
private fun setUnlockServiceState(value: Boolean) {
Intent(this, UnlockService::class.java).also {
private fun setForegroundServiceState(value: Boolean) {
Intent(this, ForegroundService::class.java).also {
if (value) ContextCompat.startForegroundService(this, it) else stopService(it)
}
}
@ -276,7 +276,7 @@ open class MainActivity : AppCompatActivity() {
private fun setWipeOnInactivityComponentsState(value: Boolean): Boolean {
val result = job.setState(value)
if (result) {
setUnlockServiceState(value)
setForegroundServiceState(value)
setRestartReceiverState(value)
}
return result

View File

@ -12,6 +12,6 @@ class RestartReceiver : BroadcastReceiver() {
intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return
val prefs = Preferences(context)
if (!prefs.isServiceEnabled || !prefs.isWipeOnInactivity) return
ContextCompat.startForegroundService(context, Intent(context, UnlockService::class.java))
ContextCompat.startForegroundService(context, Intent(context, ForegroundService::class.java))
}
}

View File

@ -23,8 +23,8 @@
<string name="ok">OK</string>
<string name="wipe_job_description">Стереть данные при неактивности</string>
<string name="wipe_job_schedule_failed_popup">Не удалось запланировать сервис стирания данных</string>
<string name="unlock_service_description">Получать события разблокировки</string>
<string name="unlock_service_notification_title">Служба Разблокировки</string>
<string name="foreground_service_description">Получать события разблокировки</string>
<string name="foreground_service_notification_title">Служба Разблокировки</string>
<string name="dialog_confirm_panic_title">Активировать тревогу\?</string>
<string name="dialog_confirm_panic_message">Это заблокирует устройство и опционально сотрёт его данные.</string>
<string name="yes">Да</string>

View File

@ -12,7 +12,7 @@
<string name="panic_app_unknown_app">an unknown app</string>
<string name="allow">Allow</string>
<string name="cancel">Cancel</string>
<string name="tile_label">Unlock a device</string>
<string name="tile_label">Unlock device</string>
<string name="shortcut_label">Panic</string>
<string name="max_failed_password_attempts_description">Maximum number of failed password attempts.</string>
<string name="max_failed_password_attempts_content_description">Count</string>
@ -23,8 +23,8 @@
<string name="ok">OK</string>
<string name="wipe_job_description">Wipe a device on inactivity</string>
<string name="wipe_job_schedule_failed_popup">Failed to schedule a wipe job</string>
<string name="unlock_service_description">Receive unlock events</string>
<string name="unlock_service_notification_title">Unlock Service</string>
<string name="foreground_service_description">Receive unlock events</string>
<string name="foreground_service_notification_title">Unlock Service</string>
<string name="dialog_confirm_panic_title">Activate panic\?</string>
<string name="dialog_confirm_panic_message">This will lock a device and optionally wipe its data.</string>
<string name="yes">Yes</string>