srctree

Robin Linden parent 61136594 304287bf
Add support for blocking screenshots inside the app

inlinesplit
atox/src/main/kotlin/MainActivity.kt added: 71, removed: 6, total 65
@@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.bundleOf
@@ -33,6 +34,12 @@ class MainActivity : AppCompatActivity() {
 
super.onCreate(savedInstanceState)
 
if (settings.disableScreenshots) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
 
AppCompatDelegate.setDefaultNightMode(settings.theme)
 
// The view inset/padding adjustments only run for Lollipop and newer.
 
atox/src/main/kotlin/settings/Settings.kt added: 71, removed: 6, total 65
@@ -80,4 +80,8 @@ class Settings @Inject constructor(private val ctx: Context) {
var bootstrapNodeSource: BootstrapNodeSource
get() = BootstrapNodeSource.values()[preferences.getInt("bootstrap_node_source", 0)]
set(source) = preferences.edit { putInt("bootstrap_node_source", source.ordinal) }
 
var disableScreenshots: Boolean
get() = preferences.getBoolean("disable_screenshots", false)
set(disable) = preferences.edit { putBoolean("disable_screenshots", disable) }
}
 
atox/src/main/kotlin/ui/settings/SettingsFragment.kt added: 71, removed: 6, total 65
@@ -3,6 +3,7 @@ package ltd.evilcorp.atox.ui.settings
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
@@ -260,6 +261,19 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
}
}
 
settingDisableScreenshots.isChecked = vm.getDisableScreenshots()
settingDisableScreenshots.setOnClickListener {
vm.setDisableScreenshots(settingDisableScreenshots.isChecked)
if (settingDisableScreenshots.isChecked) {
requireActivity().window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
} else {
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
 
version.text = getString(R.string.version_display, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
}
}
 
atox/src/main/kotlin/ui/settings/SettingsViewModel.kt added: 71, removed: 6, total 65
@@ -203,4 +203,9 @@ class SettingsViewModel @Inject constructor(
out.outputStream().use { it.write(bytes) }
return@withContext true
}
 
fun getDisableScreenshots(): Boolean = settings.disableScreenshots
fun setDisableScreenshots(disable: Boolean) {
settings.disableScreenshots = disable
}
}
 
atox/src/main/res/layout/fragment_settings.xml added: 71, removed: 6, total 65
@@ -512,6 +512,39 @@
android:layout_marginStart="16dp"
android:autoLink="web"
android:text="@string/pref_bootstrap_nodes_description"/>
 
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor"/>
<androidx.constraintlayout.widget.ConstraintLayout
style="@style/OptionRow"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/OptionItemText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/pref_block_screenshots"
app:layout_constraintEnd_toStartOf="@id/setting_disable_screenshots"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/setting_disable_screenshots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
style="@style/OptionItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/pref_block_screenshots_description"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
 
 
atox/src/main/res/values/strings.xml added: 71, removed: 6, total 65
@@ -173,4 +173,6 @@
<string name="pref_confirm_password">Confirm new password</string>
<string name="password_updated">Password updated</string>
<string name="passwords_must_match">The passwords must match</string>
<string name="pref_block_screenshots">Block screenshots</string>
<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>
</resources>
No newline at end of file