srctree

Robin Linden parent 1e0bef6a 9ae23612
Notify the user to unlock their profile at boot if needed

inlinesplit
atox/src/main/kotlin/BootReceiver.kt added: 36, removed: 3, total 33
@@ -7,8 +7,15 @@ package ltd.evilcorp.atox
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.navigation.NavDeepLinkBuilder
import javax.inject.Inject
import ltd.evilcorp.atox.tox.ToxStarter
import ltd.evilcorp.domain.tox.ToxSaveStatus
 
private const val ENCRYPTED = "aTox profile encrypted"
 
class BootReceiver : BroadcastReceiver() {
@Inject
@@ -17,7 +24,28 @@ class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
(context.applicationContext as App).component.inject(this)
toxStarter.tryLoadTox(null)
if (toxStarter.tryLoadTox(null) == ToxSaveStatus.Encrypted) {
val channel = NotificationChannelCompat.Builder(ENCRYPTED, NotificationManagerCompat.IMPORTANCE_HIGH)
.setName(context.getString(R.string.atox_profile_locked))
.setDescription(context.getString(R.string.channel_profile_locked_explanation))
.build()
val notification = NotificationCompat.Builder(context, ENCRYPTED)
.setContentTitle(context.getString(R.string.atox_profile_locked))
.setContentText(context.getString(R.string.tap_to_unlock_and_start_atox))
.setContentIntent(
NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.contactListFragment)
.createPendingIntent()
)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setSmallIcon(R.drawable.notification_icon)
.setAutoCancel(true)
.build()
val notifier = NotificationManagerCompat.from(context)
notifier.createNotificationChannel(channel)
notifier.notify(ENCRYPTED.hashCode(), notification)
}
}
}
}
 
atox/src/main/res/values/strings.xml added: 36, removed: 3, total 33
@@ -177,4 +177,9 @@
<string name="pref_block_screenshots_description">This **only** blocks screenshots on **your** device, and provides no protection against your contacts taking screenshots or otherwise saving your conversations</string>
<string name="return_to_chat">Return to chat</string>
<string name="speakerphone_toggle">Toggle speakerphone</string>
 
<!-- Run at boot w/ encrypted profile notification -->
<string name="channel_profile_locked_explanation">Sent when your profile needs to be unlocked for aTox to run</string>
<string name="atox_profile_locked">aTox profile locked</string>
<string name="tap_to_unlock_and_start_atox">Tap to unlock your profile and start aTox</string>
</resources>
No newline at end of file