mirror of https://github.com/x13a/Wasted.git
ref
This commit is contained in:
parent
2ab1dce3f2
commit
22fedc85eb
|
@ -64,7 +64,7 @@ open class MainActivity : AppCompatActivity() {
|
||||||
wipeESIM.isChecked = prefs.isWipeESIM
|
wipeESIM.isChecked = prefs.isWipeESIM
|
||||||
wipeESIM.isEnabled = wipeData.isChecked
|
wipeESIM.isEnabled = wipeData.isChecked
|
||||||
maxFailedPasswordAttempts.value = prefs.maxFailedPasswordAttempts.toFloat()
|
maxFailedPasswordAttempts.value = prefs.maxFailedPasswordAttempts.toFloat()
|
||||||
wipeOnInactiveSwitch.isChecked = prefs.isWipeOnInactive
|
wipeOnInactivitySwitch.isChecked = prefs.isWipeOnInactivity
|
||||||
toggle.isChecked = prefs.isServiceEnabled
|
toggle.isChecked = prefs.isServiceEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,17 +91,17 @@ open class MainActivity : AppCompatActivity() {
|
||||||
maxFailedPasswordAttempts.addOnChangeListener { _, value, _ ->
|
maxFailedPasswordAttempts.addOnChangeListener { _, value, _ ->
|
||||||
prefs.maxFailedPasswordAttempts = value.toInt()
|
prefs.maxFailedPasswordAttempts = value.toInt()
|
||||||
}
|
}
|
||||||
wipeOnInactiveSwitch.setOnCheckedChangeListener { _, isChecked ->
|
wipeOnInactivitySwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (!setWipeOnInactiveComponentsState(prefs.isServiceEnabled && isChecked)) {
|
if (!setWipeOnInactivityComponentsState(prefs.isServiceEnabled && isChecked)) {
|
||||||
wipeOnInactiveSwitch.isChecked = false
|
wipeOnInactivitySwitch.isChecked = false
|
||||||
showWipeJobServiceStartFailedPopup()
|
showWipeJobServiceStartFailedPopup()
|
||||||
return@setOnCheckedChangeListener
|
return@setOnCheckedChangeListener
|
||||||
}
|
}
|
||||||
prefs.isWipeOnInactive = isChecked
|
prefs.isWipeOnInactivity = isChecked
|
||||||
|
|
||||||
}
|
}
|
||||||
wipeOnInactiveSwitch.setOnLongClickListener {
|
wipeOnInactivitySwitch.setOnLongClickListener {
|
||||||
showWipeOnInactiveSettings()
|
showWipeOnInactivitySettings()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
toggle.setOnCheckedChangeListener { _, isChecked ->
|
toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
@ -113,19 +113,19 @@ open class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showWipeOnInactiveSettings() {
|
private fun showWipeOnInactivitySettings() {
|
||||||
val items = arrayOf("1", "2", "3", "5", "7", "10", "15", "30")
|
val items = arrayOf("1", "2", "3", "5", "7", "10", "15", "30")
|
||||||
var days = prefs.wipeOnInactiveDays
|
var days = prefs.wipeOnInactivityDays
|
||||||
var checked = items.indexOf(days.toString())
|
var checked = items.indexOf(days.toString())
|
||||||
if (checked == -1) checked = items
|
if (checked == -1) checked = items
|
||||||
.indexOf(Preferences.DEFAULT_WIPE_ON_INACTIVE_DAYS.toString())
|
.indexOf(Preferences.DEFAULT_WIPE_ON_INACTIVITY_DAYS.toString())
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setTitle(R.string.wipe_on_inactive_days)
|
.setTitle(R.string.wipe_on_inactivity_days)
|
||||||
.setSingleChoiceItems(items, checked) { _, which ->
|
.setSingleChoiceItems(items, checked) { _, which ->
|
||||||
days = items[which].toInt()
|
days = items[which].toInt()
|
||||||
}
|
}
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
prefs.wipeOnInactiveDays = days
|
prefs.wipeOnInactivityDays = days
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ open class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setOn() {
|
private fun setOn() {
|
||||||
if (!setWipeOnInactiveComponentsState(prefs.isWipeOnInactive)) {
|
if (!setWipeOnInactivityComponentsState(prefs.isWipeOnInactivity)) {
|
||||||
binding.toggle.isChecked = false
|
binding.toggle.isChecked = false
|
||||||
showWipeJobServiceStartFailedPopup()
|
showWipeJobServiceStartFailedPopup()
|
||||||
return
|
return
|
||||||
|
@ -158,7 +158,7 @@ open class MainActivity : AppCompatActivity() {
|
||||||
private fun setOff() {
|
private fun setOff() {
|
||||||
prefs.isServiceEnabled = false
|
prefs.isServiceEnabled = false
|
||||||
setCodeReceiverState(false)
|
setCodeReceiverState(false)
|
||||||
setWipeOnInactiveComponentsState(false)
|
setWipeOnInactivityComponentsState(false)
|
||||||
shortcut.remove()
|
shortcut.remove()
|
||||||
admin.remove()
|
admin.remove()
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ open class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setWipeOnInactiveComponentsState(value: Boolean): Boolean {
|
private fun setWipeOnInactivityComponentsState(value: Boolean): Boolean {
|
||||||
val result = job.setState(value)
|
val result = job.setState(value)
|
||||||
if (result) {
|
if (result) {
|
||||||
setUnlockServiceState(value)
|
setUnlockServiceState(value)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import androidx.security.crypto.MasterKeys
|
||||||
|
|
||||||
class Preferences(ctx: Context) {
|
class Preferences(ctx: Context) {
|
||||||
companion object {
|
companion object {
|
||||||
const val DEFAULT_WIPE_ON_INACTIVE_DAYS = 7
|
const val DEFAULT_WIPE_ON_INACTIVITY_DAYS = 7
|
||||||
|
|
||||||
private const val SERVICE_ENABLED = "service_enabled"
|
private const val SERVICE_ENABLED = "service_enabled"
|
||||||
private const val CODE = "code"
|
private const val CODE = "code"
|
||||||
|
@ -15,12 +15,14 @@ class Preferences(ctx: Context) {
|
||||||
private const val WIPE_DATA = "wipe_data"
|
private const val WIPE_DATA = "wipe_data"
|
||||||
private const val WIPE_ESIM = "wipe_esim"
|
private const val WIPE_ESIM = "wipe_esim"
|
||||||
private const val MAX_FAILED_PASSWORD_ATTEMPTS = "max_failed_password_attempts"
|
private const val MAX_FAILED_PASSWORD_ATTEMPTS = "max_failed_password_attempts"
|
||||||
private const val WIPE_ON_INACTIVE = "wipe_on_inactive"
|
private const val WIPE_ON_INACTIVITY = "wipe_on_inactivity"
|
||||||
private const val WIPE_ON_INACTIVE_DAYS = "wipe_on_inactive_days"
|
private const val WIPE_ON_INACTIVITY_DAYS = "wipe_on_inactivity_days"
|
||||||
|
|
||||||
private const val FILE_NAME = "sec_shared_prefs"
|
private const val FILE_NAME = "sec_shared_prefs"
|
||||||
// migration
|
// migration
|
||||||
private const val DO_WIPE = "do_wipe"
|
private const val DO_WIPE = "do_wipe"
|
||||||
|
private const val WIPE_ON_INACTIVE = "wipe_on_inactive"
|
||||||
|
private const val WIPE_ON_INACTIVE_DAYS = "wipe_on_inactive_days"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val mk = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
|
private val mk = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
|
||||||
|
@ -56,11 +58,17 @@ class Preferences(ctx: Context) {
|
||||||
get() = prefs.getInt(MAX_FAILED_PASSWORD_ATTEMPTS, 0)
|
get() = prefs.getInt(MAX_FAILED_PASSWORD_ATTEMPTS, 0)
|
||||||
set(value) = prefs.edit { putInt(MAX_FAILED_PASSWORD_ATTEMPTS, value) }
|
set(value) = prefs.edit { putInt(MAX_FAILED_PASSWORD_ATTEMPTS, value) }
|
||||||
|
|
||||||
var isWipeOnInactive: Boolean
|
var isWipeOnInactivity: Boolean
|
||||||
get() = prefs.getBoolean(WIPE_ON_INACTIVE, false)
|
get() = prefs.getBoolean(
|
||||||
set(value) = prefs.edit { putBoolean(WIPE_ON_INACTIVE, value) }
|
WIPE_ON_INACTIVITY,
|
||||||
|
prefs.getBoolean(WIPE_ON_INACTIVE, false),
|
||||||
|
)
|
||||||
|
set(value) = prefs.edit { putBoolean(WIPE_ON_INACTIVITY, value) }
|
||||||
|
|
||||||
var wipeOnInactiveDays: Int
|
var wipeOnInactivityDays: Int
|
||||||
get() = prefs.getInt(WIPE_ON_INACTIVE_DAYS, DEFAULT_WIPE_ON_INACTIVE_DAYS)
|
get() = prefs.getInt(
|
||||||
set(value) = prefs.edit { putInt(WIPE_ON_INACTIVE_DAYS, value) }
|
WIPE_ON_INACTIVITY_DAYS,
|
||||||
|
prefs.getInt(WIPE_ON_INACTIVE_DAYS, DEFAULT_WIPE_ON_INACTIVITY_DAYS),
|
||||||
|
)
|
||||||
|
set(value) = prefs.edit { putInt(WIPE_ON_INACTIVITY_DAYS, value) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class RestartReceiver : BroadcastReceiver() {
|
||||||
if (intent.action != Intent.ACTION_BOOT_COMPLETED &&
|
if (intent.action != Intent.ACTION_BOOT_COMPLETED &&
|
||||||
intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return
|
intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return
|
||||||
val prefs = Preferences(context)
|
val prefs = Preferences(context)
|
||||||
if (!prefs.isServiceEnabled || !prefs.isWipeOnInactive) return
|
if (!prefs.isServiceEnabled || !prefs.isWipeOnInactivity) return
|
||||||
ContextCompat.startForegroundService(context, Intent(context, UnlockService::class.java))
|
ContextCompat.startForegroundService(context, Intent(context, UnlockService::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WipeJobManager(private val ctx: Context) {
|
||||||
fun schedule(): Int {
|
fun schedule(): Int {
|
||||||
return jobScheduler.schedule(
|
return jobScheduler.schedule(
|
||||||
JobInfo.Builder(JOB_ID, ComponentName(ctx, WipeJobService::class.java))
|
JobInfo.Builder(JOB_ID, ComponentName(ctx, WipeJobService::class.java))
|
||||||
.setMinimumLatency(TimeUnit.DAYS.toMillis(prefs.wipeOnInactiveDays.toLong()))
|
.setMinimumLatency(TimeUnit.DAYS.toMillis(prefs.wipeOnInactivityDays.toLong()))
|
||||||
.setBackoffCriteria(0, JobInfo.BACKOFF_POLICY_LINEAR)
|
.setBackoffCriteria(0, JobInfo.BACKOFF_POLICY_LINEAR)
|
||||||
.setPersisted(true)
|
.setPersisted(true)
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -6,7 +6,7 @@ import android.app.job.JobService
|
||||||
class WipeJobService : JobService() {
|
class WipeJobService : JobService() {
|
||||||
override fun onStartJob(params: JobParameters?): Boolean {
|
override fun onStartJob(params: JobParameters?): Boolean {
|
||||||
val prefs = Preferences(this)
|
val prefs = Preferences(this)
|
||||||
if (!prefs.isServiceEnabled || !prefs.isWipeOnInactive) return false
|
if (!prefs.isServiceEnabled || !prefs.isWipeOnInactivity) return false
|
||||||
try {
|
try {
|
||||||
DeviceAdminManager(this).wipeData()
|
DeviceAdminManager(this).wipeData()
|
||||||
} catch (exc: SecurityException) {}
|
} catch (exc: SecurityException) {}
|
||||||
|
|
|
@ -98,17 +98,17 @@
|
||||||
android:layout_marginVertical="8dp" />
|
android:layout_marginVertical="8dp" />
|
||||||
|
|
||||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
android:id="@+id/wipeOnInactiveSwitch"
|
android:id="@+id/wipeOnInactivitySwitch"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:text="@string/wipe_on_inactive_switch" />
|
android:text="@string/wipe_on_inactivity_switch" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/description3"
|
android:id="@+id/description3"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/wipe_on_inactive_description" />
|
android:text="@string/wipe_on_inactivity_description" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
<string name="shortcut_label">Паниковать</string>
|
<string name="shortcut_label">Паниковать</string>
|
||||||
<string name="max_failed_password_attempts_description">Максимальное количество неудачных попыток ввода пароля.</string>
|
<string name="max_failed_password_attempts_description">Максимальное количество неудачных попыток ввода пароля.</string>
|
||||||
<string name="max_failed_password_attempts_content_description">Количество</string>
|
<string name="max_failed_password_attempts_content_description">Количество</string>
|
||||||
<string name="wipe_on_inactive_switch">Стереть при неактивности</string>
|
<string name="wipe_on_inactivity_switch">Стереть при неактивности</string>
|
||||||
<string name="wipe_on_inactive_description">Стереть данные когда устройство не разблокируется N дней.</string>
|
<string name="wipe_on_inactivity_description">Стереть данные когда устройство не разблокируется N дней.</string>
|
||||||
<string name="wipe_on_inactive_days">Дней</string>
|
<string name="wipe_on_inactivity_days">Дней</string>
|
||||||
<string name="notification_channel_default_name">Дефолт</string>
|
<string name="notification_channel_default_name">Дефолт</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="wipe_job_service_description">Стереть данные при условии</string>
|
<string name="wipe_job_service_description">Стереть данные при неактивности</string>
|
||||||
<string name="wipe_job_service_start_failed_popup">Не удалось запустить службу стирания данных</string>
|
<string name="wipe_job_service_start_failed_popup">Не удалось запустить службу стирания данных</string>
|
||||||
<string name="unlock_service_description">Получать события разблокировки</string>
|
<string name="unlock_service_description">Получать события разблокировки</string>
|
||||||
<string name="unlock_service_notification_title">Служба Разблокировки</string>
|
<string name="unlock_service_notification_title">Служба Разблокировки</string>
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
<string name="shortcut_label">Panic</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_description">Maximum number of failed password attempts.</string>
|
||||||
<string name="max_failed_password_attempts_content_description">Count</string>
|
<string name="max_failed_password_attempts_content_description">Count</string>
|
||||||
<string name="wipe_on_inactive_switch">Wipe on inactive</string>
|
<string name="wipe_on_inactivity_switch">Wipe on inactivity</string>
|
||||||
<string name="wipe_on_inactive_description">Wipe device when it was not unlocked for N days.</string>
|
<string name="wipe_on_inactivity_description">Wipe device when it was not unlocked for N days.</string>
|
||||||
<string name="wipe_on_inactive_days">Days</string>
|
<string name="wipe_on_inactivity_days">Days</string>
|
||||||
<string name="notification_channel_default_name">Default</string>
|
<string name="notification_channel_default_name">Default</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="wipe_job_service_description">Wipe device on condition</string>
|
<string name="wipe_job_service_description">Wipe device on inactivity</string>
|
||||||
<string name="wipe_job_service_start_failed_popup">Failed to start wipe service</string>
|
<string name="wipe_job_service_start_failed_popup">Failed to start wipe service</string>
|
||||||
<string name="unlock_service_description">Receive unlock events</string>
|
<string name="unlock_service_description">Receive unlock events</string>
|
||||||
<string name="unlock_service_notification_title">Unlock Service</string>
|
<string name="unlock_service_notification_title">Unlock Service</string>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
Loading…
Reference in New Issue