From 16b79689c6bd8ab609952a57d94a8ec310961364 Mon Sep 17 00:00:00 2001 From: lucky Date: Tue, 28 Jun 2022 12:32:14 +0300 Subject: [PATCH] update wipe on inactivity scheduler --- app/build.gradle | 4 +-- app/src/main/AndroidManifest.xml | 8 +---- .../me/lucky/wasted/DeviceAdminManager.kt | 4 --- .../java/me/lucky/wasted/ForegroundService.kt | 31 ++++++++++++----- .../main/java/me/lucky/wasted/MainActivity.kt | 32 ++++++++---------- .../java/me/lucky/wasted/WipeJobManager.kt | 7 +--- .../res/drawable/ic_baseline_settings_24.xml | 5 +++ app/src/main/res/layout/activity_main.xml | 19 +++-------- app/src/main/res/menu/main.xml | 11 ++++++ app/src/main/res/values-de/strings.xml | 10 +----- app/src/main/res/values-es-rES/strings.xml | 10 +----- app/src/main/res/values-it/strings.xml | 10 +----- app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values-ru/strings.xml | 10 +----- app/src/main/res/values-tr/strings.xml | 10 +----- app/src/main/res/values-uk/strings.xml | 10 +----- app/src/main/res/values-zh-rCN/strings.xml | 10 +----- app/src/main/res/values/strings.xml | 10 +----- app/src/main/res/values/themes.xml | 2 +- .../metadata/android/en-US/changelogs/27.txt | 1 + .../en-US/images/phoneScreenshots/1.png | Bin 112802 -> 94252 bytes .../en-US/images/phoneScreenshots/2.png | Bin 106843 -> 88529 bytes 22 files changed, 72 insertions(+), 134 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_settings_24.xml create mode 100644 app/src/main/res/menu/main.xml create mode 100644 fastlane/metadata/android/en-US/changelogs/27.txt diff --git a/app/build.gradle b/app/build.gradle index fa940c7..2587e69 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "me.lucky.wasted" minSdk 23 targetSdk 32 - versionCode 26 - versionName "1.4.1" + versionCode 27 + versionName "1.4.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c170a2..b354046 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,8 +30,6 @@ + android:exported="false"> diff --git a/app/src/main/java/me/lucky/wasted/DeviceAdminManager.kt b/app/src/main/java/me/lucky/wasted/DeviceAdminManager.kt index 9c485a2..44a7b68 100644 --- a/app/src/main/java/me/lucky/wasted/DeviceAdminManager.kt +++ b/app/src/main/java/me/lucky/wasted/DeviceAdminManager.kt @@ -42,8 +42,4 @@ class DeviceAdminManager(private val ctx: Context) { fun makeRequestIntent() = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN) .putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin) - .putExtra( - DevicePolicyManager.EXTRA_ADD_EXPLANATION, - ctx.getString(R.string.device_admin_description), - ) } diff --git a/app/src/main/java/me/lucky/wasted/ForegroundService.kt b/app/src/main/java/me/lucky/wasted/ForegroundService.kt index 7c8202c..ca8976b 100644 --- a/app/src/main/java/me/lucky/wasted/ForegroundService.kt +++ b/app/src/main/java/me/lucky/wasted/ForegroundService.kt @@ -15,7 +15,7 @@ class ForegroundService : Service() { private const val NOTIFICATION_ID = 1000 } - private val unlockReceiver = UnlockReceiver() + private val lockReceiver = LockReceiver() override fun onCreate() { super.onCreate() @@ -28,11 +28,14 @@ class ForegroundService : Service() { } private fun init() { - registerReceiver(unlockReceiver, IntentFilter(Intent.ACTION_USER_PRESENT)) + registerReceiver(lockReceiver, IntentFilter().apply { + addAction(Intent.ACTION_USER_PRESENT) + addAction(Intent.ACTION_SCREEN_OFF) + }) } private fun deinit() { - unregisterReceiver(unlockReceiver) + unregisterReceiver(lockReceiver) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -52,12 +55,24 @@ class ForegroundService : Service() { return null } - private class UnlockReceiver : BroadcastReceiver() { + private class LockReceiver : BroadcastReceiver() { + private var unlocked = false + override fun onReceive(context: Context?, intent: Intent?) { - if (intent?.action != Intent.ACTION_USER_PRESENT || - context?.getSystemService(KeyguardManager::class.java)?.isDeviceSecure != true || - !Preferences(context).isWipeOnInactivity) return - Thread(Runner(context, goAsync())).start() + if (!Preferences(context ?: return).isWipeOnInactivity) return + when (intent?.action) { + Intent.ACTION_USER_PRESENT -> { + if (context.getSystemService(KeyguardManager::class.java) + ?.isDeviceSecure != true) return + unlocked = true + WipeJobManager(context).cancel() + } + Intent.ACTION_SCREEN_OFF -> { + if (!unlocked) return + unlocked = false + Thread(Runner(context, goAsync())).start() + } + } } private class Runner( diff --git a/app/src/main/java/me/lucky/wasted/MainActivity.kt b/app/src/main/java/me/lucky/wasted/MainActivity.kt index 499b829..df8425a 100644 --- a/app/src/main/java/me/lucky/wasted/MainActivity.kt +++ b/app/src/main/java/me/lucky/wasted/MainActivity.kt @@ -1,6 +1,5 @@ package me.lucky.wasted -import android.app.job.JobScheduler import android.content.ClipData import android.content.ClipboardManager import android.content.ComponentName @@ -8,6 +7,8 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Build import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import android.view.View import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity @@ -55,6 +56,16 @@ open class MainActivity : AppCompatActivity() { setup() } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.main, menu) + return super.onCreateOptionsMenu(menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.triggers) showTriggers() + return super.onOptionsItemSelected(item) + } + override fun onStart() { super.onStart() update() @@ -116,9 +127,6 @@ open class MainActivity : AppCompatActivity() { private fun setup() { binding.apply { - authenticationCode.setOnClickListener { - showTriggersSettings() - } authenticationCode.setOnLongClickListener { copyAuthenticationCode() true @@ -156,10 +164,6 @@ open class MainActivity : AppCompatActivity() { MODIFIER_MINUTES -> i else -> return@setEndIconOnClickListener } - if (prefs.isEnabled && prefs.isWipeOnInactivity) { - if (job.schedule() == JobScheduler.RESULT_FAILURE) - showWipeJobScheduleFailedPopup() - } } toggle.setOnCheckedChangeListener { _, isChecked -> if (isChecked) requestAdmin() else setOff() @@ -191,7 +195,7 @@ open class MainActivity : AppCompatActivity() { }, CLIPBOARD_CLEAR_DELAY) } - private fun showTriggersSettings() { + private fun showTriggers() { var triggers = prefs.triggers val values = Trigger.values().toMutableList() val strings = resources.getStringArray(R.array.triggers).toMutableList() @@ -248,14 +252,6 @@ open class MainActivity : AppCompatActivity() { updateCodeColorState() } - private fun showWipeJobScheduleFailedPopup() { - Snackbar.make( - binding.toggle, - R.string.wipe_job_schedule_failed_popup, - Snackbar.LENGTH_LONG, - ).show() - } - private fun setOff() { prefs.isEnabled = false setWipeOnInactivityState(false) @@ -284,7 +280,7 @@ open class MainActivity : AppCompatActivity() { } private fun setWipeOnInactivityState(value: Boolean) { - job.setState(value) + if (!value) job.cancel() setForegroundState(value) } diff --git a/app/src/main/java/me/lucky/wasted/WipeJobManager.kt b/app/src/main/java/me/lucky/wasted/WipeJobManager.kt index 836301a..daa08a9 100644 --- a/app/src/main/java/me/lucky/wasted/WipeJobManager.kt +++ b/app/src/main/java/me/lucky/wasted/WipeJobManager.kt @@ -23,10 +23,5 @@ class WipeJobManager(private val ctx: Context) { ) ?: JobScheduler.RESULT_FAILURE } - fun setState(value: Boolean): Boolean { - if (value) { - if (schedule() == JobScheduler.RESULT_FAILURE) return false - } else { scheduler?.cancel(JOB_ID) } - return true - } + fun cancel() = scheduler?.cancel(JOB_ID) } diff --git a/app/src/main/res/drawable/ic_baseline_settings_24.xml b/app/src/main/res/drawable/ic_baseline_settings_24.xml new file mode 100644 index 0000000..298a5a1 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_settings_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8f5d226..6101854 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,25 +7,14 @@ android:padding="32dp" tools:context=".MainActivity"> - - + app:layout_constraintTop_toTopOf="parent"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 073aefd..f07546b 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1,12 +1,9 @@ Wasted - Aktiviere Wasted, um dein Gerät im Notfall zu sperren. Du kannst hierfür PanicKit, Tile und Shortcut verwenden, oder eine Nachricht mit diesem Authentifizierungscode auf dein Gerät senden. - Wasted - Wasted erlauben das Gerät zu sperren und optional die Daten in einem Notfall zu löschen Geräteadministrator nicht verfügbar Daten löschen - eSim löschen + eSim löschen Bestätige Panik App Bist du sicher, dass du %1$s erlauben willst, destruktive Aktionen auslösen zu lassen\? eine unbekannte App @@ -16,17 +13,12 @@ Bei Inaktivität löschen Den Speicher des Geräts löschen, wenn es für N Tage nicht entsperrt wurde. Standard - Den Speicher bei Inaktivität löschen - Fehler bei der Durchführung des Wipes - Receive events which require foreground service Guard PanicKit Tile Shortcut Broadcast Benachrichtigung - Viper - Benachrichtigungen nach dem Authentifizierungscode absuchen Auslöser Kopiert diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index d0a949d..d7daf4d 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1,12 +1,9 @@ Wasted - Active Wasted para bloquear un dispositivo en caso de emergencia. Puede usar PanicKit, title, acceso directo o enviar un mensaje con este código de autenticación. - Wasted - Permita que Wasted bloquee un dispositivo y, opcionalmente, borre sus datos en caso de emergencia Administrador de dispositivos no disponible Borrar datos - Borrar eSIM + Borrar eSIM Confirmar aplicación de pánico ¿Está seguro de que desea permitir que %1$s active acciones de pánico destructivas\? una aplicación desconocida @@ -16,17 +13,12 @@ Borrar por inactividad Limpia un dispositivo cuando no fue desbloqueado por N días. Predeterminado - Borrar un dispositivo por inactividad - Error al programar un trabajo de borrado - Recibir eventos que requieren servicio de primer plano Guardia PanicKit Título Acceso directo Transmisión Notificación - Viper - Escanear notificaciones para el código de autenticación Activadores Copiado diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e0bd6f7..be0e2a7 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1,12 +1,9 @@ Wasted - Attiva Wasted per bloccare un dispositivo in caso di pericolo. Puoi usare PanicKit, un toggle, una scorciatoia o inviare un messaggio con questo codice di autenticazione. - Wasted - Consenti a Wasted di bloccare un dispositivo e, facoltativamente, cancellare i suoi dati in caso di pericolo Amministrazione dispositivo non disponibile Cancella i dati - Cancella eSIM + Cancella eSIM Conferma app di panico Sei sicuro di voler consentire a %1$s di attivare azioni di panico distruttive\? un\'app sconosciuta @@ -16,17 +13,12 @@ Cancella in caso di inattività Cancella i dati quando il dispositivo non viene sbloccato per N giorni. Predefinito - Cancella i dati in caso di inattività - Impossibile pianificare un processo di cancellazione - Ricevi eventi che richiedono il servizio in primo piano Guardia PanicKit Toggle Scorciatoia Broadcast Notifica - Viper - Scansiona le notifiche per il codice di autenticazione Attivatori Copiato diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 960ab3c..bef17fd 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,6 +1,6 @@ -