Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable screen recording #1047

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ class TariSettingsSharedRepository @Inject constructor(sharedPrefs: SharedPrefer
const val isRestoredWallet = "tari_is_restored_wallet"
const val hasVerifiedSeedWords = "tari_has_verified_seed_words"
const val backgroundServiceTurnedOnKey = "tari_background_service_turned_on"
const val screenRecordingTurnedOnKey = "tari_screen_recording_turned_on"
const val isOneSidePaymentEnabledKey = "is_one_side_payment_enabled"
const val themeKey = "tari_theme_key"
}

var isRestoredWallet: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.isRestoredWallet))
var isRestoredWallet: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.isRestoredWallet))

var hasVerifiedSeedWords: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.hasVerifiedSeedWords))
var hasVerifiedSeedWords: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.hasVerifiedSeedWords))

var backgroundServiceTurnedOn: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.backgroundServiceTurnedOnKey), true)
var backgroundServiceTurnedOn: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.backgroundServiceTurnedOnKey), true)

var isOneSidePaymentEnabled: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.isOneSidePaymentEnabledKey), false)
var screenRecordingTurnedOn: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.screenRecordingTurnedOnKey), false)

var currentTheme: TariTheme? by SharedPrefGsonDelegate(sharedPrefs, this, Key.themeKey, TariTheme::class.java, TariTheme.AppBased)
var isOneSidePaymentEnabled: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.isOneSidePaymentEnabledKey), false)

var currentTheme: TariTheme? by SharedPrefGsonDelegate(sharedPrefs, this, Key.themeKey, TariTheme::class.java, TariTheme.AppBased)

fun clear() {
isRestoredWallet = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import com.tari.android.wallet.ui.fragment.settings.logs.LogFilesManager
import com.tari.android.wallet.ui.fragment.settings.logs.logFiles.LogFilesViewModel
import com.tari.android.wallet.ui.fragment.settings.logs.logs.LogsViewModel
import com.tari.android.wallet.ui.fragment.settings.networkSelection.NetworkSelectionViewModel
import com.tari.android.wallet.ui.fragment.settings.screenRecording.ScreenRecordingSettingsViewModel
import com.tari.android.wallet.ui.fragment.settings.themeSelector.ThemeSelectorViewModel
import com.tari.android.wallet.ui.fragment.settings.torBridges.TorBridgesSelectionViewModel
import com.tari.android.wallet.ui.fragment.settings.torBridges.customBridges.CustomTorBridgesViewModel
Expand Down Expand Up @@ -147,6 +148,7 @@ interface ApplicationComponent {
fun inject(viewModel: ThumbnailGIFsViewModel)
fun inject(viewModel: GIFViewModel)
fun inject(viewModel: BackgroundServiceSettingsViewModel)
fun inject(viewModel: ScreenRecordingSettingsViewModel)
fun inject(viewModel: ConnectionIndicatorViewModel)
fun inject(viewModel: ChooseRestoreOptionViewModel)
fun inject(viewModel: EnterRestorationPasswordViewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.tari.android.wallet.extension

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

inline fun LifecycleOwner.launchAndRepeatOnLifecycle(
state: Lifecycle.State,
crossinline block: suspend CoroutineScope.() -> Unit,
) = lifecycleScope.launch { repeatOnLifecycle(state) { block() } }
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.viewbinding.ViewBinding
import com.squareup.seismic.ShakeDetector
import com.tari.android.wallet.R
import com.tari.android.wallet.extension.observe
import com.tari.android.wallet.extension.safeCastTo
import com.tari.android.wallet.ui.component.networkStateIndicator.ConnectionIndicatorViewModel
import com.tari.android.wallet.ui.component.tari.toast.TariToast
import com.tari.android.wallet.ui.component.tari.toast.TariToastArgs
Expand All @@ -38,7 +39,7 @@ import com.tari.android.wallet.ui.fragment.settings.logs.activity.DebugNavigatio
import com.tari.android.wallet.ui.fragment.settings.themeSelector.TariTheme
import yat.android.lib.YatIntegration

abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : AppCompatActivity(), ShakeDetector.Listener {
abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : AppCompatActivity(), ShakeDetector.Listener, FragmentPoppedListener {

private val dialogManager = DialogManager()
private var containerId: Int? = null
Expand Down Expand Up @@ -161,7 +162,7 @@ abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : App
containerId = id
}

fun addFragment(fragment: Fragment, bundle: Bundle? = null, isRoot: Boolean = false, withAnimation: Boolean = true) {
fun addFragment(fragment: CommonFragment<*, *>, bundle: Bundle? = null, isRoot: Boolean = false, withAnimation: Boolean = true) {
bundle?.let { fragment.arguments = it }
if (supportFragmentManager.isDestroyed) return
val transaction = supportFragmentManager.beginTransaction()
Expand All @@ -172,6 +173,7 @@ abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : App
if (!isRoot) {
transaction.addToBackStack(null)
}
fragment.setFragmentPoppedListener(this)
transaction.commit()
}

Expand All @@ -185,6 +187,12 @@ abstract class CommonActivity<Binding : ViewBinding, VM : CommonViewModel> : App
}
}

override fun onFragmentPopped(fragmentClass: Class<out Fragment>) {
supportFragmentManager.fragments
.mapNotNull { it.safeCastTo<CommonFragment<*, *>>() }
.forEach { fragment -> fragment.onFragmentPopped(fragmentClass) }
}

override fun hearShake() = showDebugDialog()

fun showDebugDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
Expand All @@ -25,9 +26,9 @@ import com.tari.android.wallet.ui.dialog.modular.InputModularDialog
import com.tari.android.wallet.ui.dialog.modular.ModularDialog
import com.tari.android.wallet.ui.extension.string

abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fragment() {
abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fragment(), FragmentPoppedListener {

lateinit var clipboardManager: ClipboardManager
private lateinit var clipboardManager: ClipboardManager

private val dialogManager = DialogManager()

Expand All @@ -37,18 +38,27 @@ abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fra

lateinit var viewModel: VM

val launcher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
if (it.all { it.value }) {
//TODO make viewModel not lateinit. Sometimes it's not initialized in time and causes crashes, so we need to check if it's initialized
private val blockScreenRecording
get() = !BuildConfig.DEBUG &&
(screenRecordingAlwaysDisable() || !(this::viewModel.isInitialized) || !viewModel.tariSettingsSharedRepository.screenRecordingTurnedOn)

private var fragmentPoppedListener: FragmentPoppedListener? = null

private val launcher = registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { results ->
if (results.all { it.value }) {
viewModel.permissionManager.grantedAction()
} else {
viewModel.permissionManager.showPermissionRequiredDialog(it.filter { !it.value }.map { it.key })
viewModel.permissionManager.showPermissionRequiredDialog(results.filter { !it.value }.map { it.key })
}
}

protected open fun screenRecordingAlwaysDisable() = false

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

//to eliminate click throuhg fragments
//to eliminate click through fragments
view.isClickable = true
view.isFocusable = true

Expand All @@ -66,12 +76,37 @@ abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fra
return super.onCreateView(inflater, container, savedInstanceState)
}

override fun onResume() {
super.onResume()

if (blockScreenRecording) {
requireActivity().window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}

fun bindViewModel(viewModel: VM) = with(viewModel) {
[email protected] = this

subscribeVM(viewModel)
}

override fun onDetach() {
super.onDetach()

fragmentPoppedListener?.onFragmentPopped(javaClass)
}

override fun onFragmentPopped(fragmentClass: Class<out Fragment>) {
// implement in subclass
}

fun setFragmentPoppedListener(listener: FragmentPoppedListener) {
fragmentPoppedListener = listener
}


fun <VM : CommonViewModel> subscribeVM(viewModel: VM) = with(viewModel) {
observe(backPressed) { requireActivity().onBackPressed() }

Expand Down Expand Up @@ -147,3 +182,9 @@ abstract class CommonFragment<Binding : ViewBinding, VM : CommonViewModel> : Fra
}
}

/**
* Interface for listening to fragment pop events and performing actions once a fragment is popped.
*/
interface FragmentPoppedListener {
fun onFragmentPopped(fragmentClass: Class<out Fragment>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ open class CommonViewModel : ViewModel() {

fun runWithAuthorization(action: () -> Unit) {
authorizedAction = action
navigation.postValue(Navigation.FeatureAuth())
navigation.postValue(Navigation.FeatureAuth)
}

fun checkAuthorization() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package com.tari.android.wallet.ui.component.loadingSwitch

data class TariLoadingSwitchState(val isChecked: Boolean, val isLoading: Boolean)
data class TariLoadingSwitchState(
val isChecked: Boolean = false,
val isLoading: Boolean = false,
) {
fun startLoading() = this.copy(isLoading = true)
fun stopLoading() = this.copy(isLoading = false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class AddContactFragment : ContactSelectionFragment() {
val surname = split.getOrNull(0).orEmpty().trim()

viewModel.contactsRepository.updateContactInfo(user, firstName, surname, "")
viewModel.navigation.postValue(Navigation.ContactBookNavigation.BackToContactBook())
viewModel.navigation.postValue(Navigation.ContactBookNavigation.BackToContactBook)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ import com.tari.android.wallet.ui.fragment.contact_book.data.contacts.YatDto
import com.tari.android.wallet.ui.fragment.contact_book.details.adapter.contactType.ContactTypeViewHolderItem
import com.tari.android.wallet.ui.fragment.contact_book.details.adapter.profile.ContactProfileViewHolderItem
import com.tari.android.wallet.ui.fragment.home.navigation.Navigation
import com.tari.android.wallet.ui.fragment.settings.allSettings.button.ButtonStyle
import com.tari.android.wallet.ui.fragment.settings.allSettings.button.ButtonViewDto
import com.tari.android.wallet.ui.fragment.settings.allSettings.row.SettingsRowStyle
import com.tari.android.wallet.ui.fragment.settings.allSettings.row.SettingsRowViewDto
import com.tari.android.wallet.ui.fragment.settings.allSettings.title.SettingsTitleViewHolderItem
import com.tari.android.wallet.yat.YatAdapter
import kotlinx.coroutines.Deferred
Expand Down Expand Up @@ -101,7 +101,7 @@ class ContactDetailsViewModel : CommonViewModel() {

ContactAction.Send.let {
if (availableActions.contains(it)) {
newList += ButtonViewDto(resourceManager.getString(it.title)) {
newList += SettingsRowViewDto(resourceManager.getString(it.title)) {
navigation.postValue(Navigation.ContactBookNavigation.ToSendTari(contact))
}
newList += DividerViewHolderItem()
Expand All @@ -110,23 +110,23 @@ class ContactDetailsViewModel : CommonViewModel() {

ContactAction.Link.let {
if (availableActions.contains(it)) {
newList += (ButtonViewDto(resourceManager.getString(it.title)) {
newList += (SettingsRowViewDto(resourceManager.getString(it.title)) {
navigation.postValue(Navigation.ContactBookNavigation.ToLinkContact(contact))
})
newList += DividerViewHolderItem()
}
}

if (contact.getFFIDto() != null) {
newList += ButtonViewDto(resourceManager.getString(R.string.contact_details_transaction_history)) {
newList += SettingsRowViewDto(resourceManager.getString(R.string.contact_details_transaction_history)) {
navigation.postValue(Navigation.ContactBookNavigation.ToContactTransactionHistory(contact))
}
newList += DividerViewHolderItem()
}

ContactAction.ToFavorite.let {
if (availableActions.contains(it)) {
newList += ButtonViewDto(resourceManager.getString(it.title), iconId = R.drawable.tari_empty_drawable) {
newList += SettingsRowViewDto(resourceManager.getString(it.title), iconId = R.drawable.tari_empty_drawable) {
this.contact.value = contactsRepository.toggleFavorite(contact)
}
newList += DividerViewHolderItem()
Expand All @@ -135,7 +135,7 @@ class ContactDetailsViewModel : CommonViewModel() {

ContactAction.ToUnFavorite.let {
if (availableActions.contains(it)) {
newList += ButtonViewDto(resourceManager.getString(it.title), iconId = R.drawable.tari_empty_drawable) {
newList += SettingsRowViewDto(resourceManager.getString(it.title), iconId = R.drawable.tari_empty_drawable) {
this.contact.value = contactsRepository.toggleFavorite(contact)
}
newList += DividerViewHolderItem()
Expand All @@ -144,7 +144,7 @@ class ContactDetailsViewModel : CommonViewModel() {

ContactAction.Unlink.let {
if (availableActions.contains(it)) {
newList += ButtonViewDto(resourceManager.getString(it.title)) {
newList += SettingsRowViewDto(resourceManager.getString(it.title)) {
showUnlinkDialog()
}
newList += DividerViewHolderItem()
Expand All @@ -153,9 +153,9 @@ class ContactDetailsViewModel : CommonViewModel() {

ContactAction.Delete.let {
if (availableActions.contains(it)) {
newList += ButtonViewDto(
newList += SettingsRowViewDto(
resourceManager.getString(it.title),
style = ButtonStyle.Warning,
style = SettingsRowStyle.Warning,
iconId = R.drawable.tari_empty_drawable
) {
showDeleteContactDialog()
Expand All @@ -169,7 +169,7 @@ class ContactDetailsViewModel : CommonViewModel() {
if (connectedWallets.isNotEmpty()) {
newList.add(SettingsTitleViewHolderItem(resourceManager.getString(contact_book_details_connected_wallets)))
for (connectedWallet in connectedWallets) {
newList += (ButtonViewDto(resourceManager.getString(connectedWallet.name!!)) {
newList += (SettingsRowViewDto(resourceManager.getString(connectedWallet.name!!)) {
navigation.postValue(Navigation.ContactBookNavigation.ToExternalWallet(connectedWallet))
})
newList += DividerViewHolderItem()
Expand Down Expand Up @@ -296,7 +296,7 @@ class ContactDetailsViewModel : CommonViewModel() {
ButtonModule(resourceManager.getString(common_close), Close)
)
modularDialog.postValue(ModularDialogArgs(DialogArgs {
navigation.value = Navigation.ContactBookNavigation.BackToContactBook()
navigation.value = Navigation.ContactBookNavigation.BackToContactBook
}, modules))
}

Expand All @@ -307,7 +307,7 @@ class ContactDetailsViewModel : CommonViewModel() {
ButtonModule(resourceManager.getString(contact_book_details_delete_button_title), Warning) {
contactsRepository.deleteContact(contact.value!!)
dismissDialog.postValue(Unit)
navigation.value = Navigation.ContactBookNavigation.BackToContactBook()
navigation.value = Navigation.ContactBookNavigation.BackToContactBook
},
ButtonModule(resourceManager.getString(common_close), Close)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.tari.android.wallet.ui.common.recyclerView.viewHolders.SpaceVerticalV
import com.tari.android.wallet.ui.common.recyclerView.viewHolders.TitleViewHolder
import com.tari.android.wallet.ui.fragment.contact_book.details.adapter.contactType.ContactTypeViewHolder
import com.tari.android.wallet.ui.fragment.contact_book.details.adapter.profile.ContactProfileViewHolder
import com.tari.android.wallet.ui.fragment.settings.allSettings.button.ButtonViewHolder
import com.tari.android.wallet.ui.fragment.settings.allSettings.row.SettingsRowViewHolder
import com.tari.android.wallet.ui.fragment.settings.allSettings.divider.SettingsDividerViewHolder
import com.tari.android.wallet.ui.fragment.settings.allSettings.title.SettingsTitleViewHolder

Expand All @@ -16,7 +16,7 @@ class ContactDetailsAdapter : CommonAdapter<CommonViewHolderItem>() {
TitleViewHolder.getBuilder(),
ContactProfileViewHolder.getBuilder(),
SettingsDividerViewHolder.getBuilder(),
ButtonViewHolder.getBuilder(),
SettingsRowViewHolder.getBuilder(),
SettingsTitleViewHolder.getBuilder(),
SpaceVerticalViewHolder.getBuilder(),
ContactTypeViewHolder.getBuilder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ContactLinkViewModel : CommonViewModel() {
ButtonModule(resourceManager.getString(common_close), ButtonStyle.Close)
)
modularDialog.postValue(ModularDialogArgs(DialogArgs {
navigation.value = Navigation.ContactBookNavigation.BackToContactBook()
navigation.value = Navigation.ContactBookNavigation.BackToContactBook
}, modules))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ContactBookActionMenuViewModel : CommonViewModel() {
ButtonModule(resourceManager.getString(R.string.common_cancel), ButtonStyle.Close)
)
modularDialog.postValue(ModularDialogArgs(DialogArgs {
navigation.value = Navigation.ContactBookNavigation.BackToContactBook()
navigation.value = Navigation.ContactBookNavigation.BackToContactBook
}, modules))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class HomeActivity : CommonActivity<ActivityHomeBinding, HomeViewModel>() {
}

private fun setupUi() {
ui.sendTariButton.setOnClickListener { viewModel.navigation.postValue(Navigation.TxListNavigation.ToTransfer()) }
ui.sendTariButton.setOnClickListener { viewModel.navigation.postValue(Navigation.TxListNavigation.ToTransfer) }
setupBottomNavigation()
}

Expand Down
Loading
Loading