Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #18507: Prevent screenshots on credit card screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed May 19, 2021
1 parent a5a50d6 commit d9e48fa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Expand Up @@ -302,9 +302,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
super.onResume()

// Even if screenshots are allowed, we hide private content in the recents screen in onPause
// so onResume we should go back to setting these flags with the user screenshot setting
// only when we are in private mode, so in onResume we should go back to setting these flags
// with the user screenshot setting only when we are in private mode.
// See https://github.com/mozilla-mobile/fenix/issues/11153
updateSecureWindowFlags(settings().lastKnownMode)
if (settings().lastKnownMode == BrowsingMode.Private) {
updateSecureWindowFlags(settings().lastKnownMode)
}

// Diagnostic breadcrumb for "Display already aquired" crash:
// https://github.com/mozilla-mobile/android-components/issues/7960
Expand Down Expand Up @@ -372,6 +375,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
components.core.store.state.getNormalOrPrivateTabs(private = false).isNotEmpty()

// Even if screenshots are allowed, we want to hide private content in the recents screen
// only when we are in private mode
// See https://github.com/mozilla-mobile/fenix/issues/11153
if (settings().lastKnownMode.isPrivate) {
window.addFlags(FLAG_SECURE)
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/org/mozilla/fenix/SecureFragment.kt
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix

import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
import org.mozilla.fenix.ext.removeSecure
import org.mozilla.fenix.ext.secure

open class SecureFragment() : Fragment() {

constructor(@LayoutRes contentLayoutId: Int) : this() {
Fragment(contentLayoutId)
}

override fun onCreate(savedInstanceState: Bundle?) {
this.secure()
super.onCreate(savedInstanceState)
}

override fun onDestroy() {
this.removeSecure()
super.onDestroy()
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/org/mozilla/fenix/ext/Fragment.kt
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.ext

import android.view.WindowManager
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -90,3 +91,15 @@ fun Fragment.breadcrumb(
)
)
}

fun Fragment.secure() {
this.activity?.window?.addFlags(
WindowManager.LayoutParams.FLAG_SECURE
)
}

fun Fragment.removeSecure() {
this.activity?.window?.clearFlags(
WindowManager.LayoutParams.FLAG_SECURE
)
}
Expand Up @@ -14,6 +14,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import org.mozilla.fenix.R
import org.mozilla.fenix.SecureFragment
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.settings.creditcards.controller.DefaultCreditCardEditorController
Expand All @@ -24,7 +25,7 @@ import org.mozilla.fenix.settings.creditcards.view.CreditCardEditorView
/**
* Display a credit card editor for adding and editing a credit card.
*/
class CreditCardEditorFragment : Fragment(R.layout.fragment_credit_card_editor) {
class CreditCardEditorFragment : SecureFragment(R.layout.fragment_credit_card_editor) {

private lateinit var creditCardEditorState: CreditCardEditorState
private lateinit var creditCardEditorView: CreditCardEditorView
Expand Down
Expand Up @@ -8,7 +8,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_saved_cards.view.*
Expand All @@ -17,6 +16,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.R
import org.mozilla.fenix.SecureFragment
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.showToolbar
Expand All @@ -28,7 +28,7 @@ import org.mozilla.fenix.settings.creditcards.view.CreditCardsManagementView
/**
* Displays a list of saved credit cards.
*/
class CreditCardsManagementFragment : Fragment() {
class CreditCardsManagementFragment : SecureFragment() {

private lateinit var creditCardsStore: CreditCardsFragmentStore
private lateinit var interactor: CreditCardsManagementInteractor
Expand Down

0 comments on commit d9e48fa

Please sign in to comment.