Skip to content

Commit

Permalink
test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky committed Jul 11, 2022
1 parent fffaa5d commit 70cf070
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "me.lucky.duress"
minSdk 23
targetSdk 32
versionCode 7
versionName "1.0.6"
versionCode 8
versionName "1.0.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</service>

<receiver
android:name=".DeviceAdminReceiver"
android:name=".admin.DeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN"
android:exported="true">
<meta-data android:name="android.app.device_admin"
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/me/lucky/duress/AccessibilityService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.content.IntentFilter
import android.view.accessibility.AccessibilityEvent
import java.lang.ref.WeakReference

import me.lucky.duress.admin.DeviceAdminManager

class AccessibilityService : AccessibilityService() {
companion object {
private const val MIN_PASSWORD_LEN = 6
Expand Down Expand Up @@ -55,13 +57,11 @@ class AccessibilityService : AccessibilityService() {
KeyguardType.B.value -> checkKeyguardTypeB(event)
else -> return
}) return
if (prefs.mode == Mode.WIPE.value) {
wipeData()
return
when (prefs.mode) {
Mode.TEST.value -> sendNotification()
Mode.WIPE.value -> wipeData()
Mode.BROADCAST.value -> sendBroadcast()
}
val action = prefs.action
if (action.isEmpty()) return
sendBroadcast(action)
}

override fun onInterrupt() {}
Expand Down Expand Up @@ -102,7 +102,11 @@ class AccessibilityService : AccessibilityService() {
return true
}

private fun sendBroadcast(action: String) {
private fun sendNotification() = NotificationManager(this).send()

private fun sendBroadcast() {
val action = prefs.action
if (action.isEmpty()) return
sendBroadcast(Intent(action).apply {
val cls = prefs.receiver.split('/')
val packageName = cls.firstOrNull() ?: ""
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/me/lucky/duress/DeviceAdminReceiver.kt

This file was deleted.

27 changes: 15 additions & 12 deletions app/src/main/java/me/lucky/duress/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout

import me.lucky.duress.admin.DeviceAdminManager
import me.lucky.duress.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -56,6 +57,7 @@ class MainActivity : AppCompatActivity() {
prefsdb = Preferences(this, encrypted = false)
prefs.copyTo(prefsdb)
accessibilityManager = getSystemService(AccessibilityManager::class.java)
NotificationManager(this).createNotificationChannels()
}

private fun init2() {
Expand Down Expand Up @@ -90,19 +92,19 @@ class MainActivity : AppCompatActivity() {
this,
executor,
object : BiometricPrompt.AuthenticationCallback()
{
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
finishAndRemoveTask()
}
{
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
finishAndRemoveTask()
}

override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
init2()
setup()
if (prefs.isShowProminentDisclosure) showProminentDisclosure()
}
})
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
init2()
setup()
if (prefs.isShowProminentDisclosure) showProminentDisclosure()
}
})
try {
prompt.authenticate(BiometricPrompt.PromptInfo.Builder()
.setTitle(getString(R.string.authentication))
Expand Down Expand Up @@ -165,6 +167,7 @@ class MainActivity : AppCompatActivity() {
val v = when (prefs.mode) {
Mode.BROADCAST.value -> View.VISIBLE
Mode.WIPE.value -> View.GONE
Mode.TEST.value -> View.GONE
else -> View.GONE
}
binding.apply {
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/me/lucky/duress/NotificationManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.lucky.duress

import android.content.Context
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat

class NotificationManager(private val ctx: Context) {
companion object {
const val CHANNEL_DEFAULT_ID = "default"
private const val GROUP_KEY = "test"
private const val NOTIFICATION_ID = 1000
}

private val manager = NotificationManagerCompat.from(ctx)

fun createNotificationChannels() {
manager.createNotificationChannel(
NotificationChannelCompat.Builder(
CHANNEL_DEFAULT_ID,
NotificationManagerCompat.IMPORTANCE_LOW,
).setName(ctx.getString(R.string.notification_channel_default_name)).build())
}

fun send() {
manager.notify(
NOTIFICATION_ID,
NotificationCompat.Builder(ctx, CHANNEL_DEFAULT_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(ctx.getString(R.string.notification_title))
.setContentText(ctx.getString(android.R.string.ok))
.setPriority(NotificationCompat.PRIORITY_LOW)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setShowWhen(true)
.setAutoCancel(true)
.setGroup(GROUP_KEY)
.setGroupSummary(true)
.build(),
)
}
}
1 change: 1 addition & 0 deletions app/src/main/java/me/lucky/duress/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Preferences(ctx: Context, encrypted: Boolean = true) {
enum class Mode(val value: Int) {
BROADCAST(0),
WIPE(1),
TEST(2),
}

enum class KeyguardType(val value: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.lucky.duress
package me.lucky.duress.admin

import android.app.admin.DevicePolicyManager
import android.content.ComponentName
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.lucky.duress.admin

import android.app.admin.DeviceAdminReceiver

class DeviceAdminReceiver : DeviceAdminReceiver()
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
android:layout_height="wrap_content"
android:text="@string/tab_wipe" />

<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tab_test" />

</com.google.android.material.tabs.TabLayout>

<ScrollView
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
<string name="password_len_helper_text">Has to be at least your password length plus two.</string>
<string name="tab_broadcast">BROADCAST</string>
<string name="tab_wipe">WIPE</string>
<string name="tab_test">TEST</string>
<string name="keyguard_type">Keyguard:</string>
<string name="keyguard_type_a">A</string>
<string name="keyguard_type_b">B</string>
<string name="keyguard_type_description">Change only if the default value does not work.</string>
<string name="authentication">Authentication</string>
<string name="notification_channel_default_name">Default</string>
<string name="notification_title">Test</string>
</resources>
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test mode
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70cf070

Please sign in to comment.