For #17785 - Use screenshots setting when adding secure flag

upstream-sync
ekager 3 years ago
parent 1ef4102e13
commit f5b068a453

@ -17,7 +17,7 @@ import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewConfiguration
import android.view.WindowManager
import android.view.WindowManager.LayoutParams.FLAG_SECURE
import androidx.annotation.CallSuper
import androidx.annotation.IdRes
import androidx.annotation.VisibleForTesting
@ -278,6 +278,11 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
override fun onResume() {
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
// See https://github.com/mozilla-mobile/fenix/issues/11153
updateSecureWindowFlags(settings().lastKnownMode)
// Diagnostic breadcrumb for "Display already aquired" crash:
// https://github.com/mozilla-mobile/android-components/issues/7960
breadcrumb(
@ -341,8 +346,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
settings().shouldReturnToBrowser =
components.core.store.state.getNormalOrPrivateTabs(private = false).isNotEmpty()
// Even if screenshots are allowed, we want to hide private content in the recents screen
// See https://github.com/mozilla-mobile/fenix/issues/11153
if (settings().lastKnownMode.isPrivate) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
window.addFlags(FLAG_SECURE)
}
// We will remove this when AC code lands to emit a fact on getTopSites in DefaultTopSitesStorage
@ -850,7 +857,18 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
protected open fun createBrowsingModeManager(initialMode: BrowsingMode): BrowsingModeManager {
return DefaultBrowsingModeManager(initialMode, components.settings) { newMode ->
updateSecureWindowFlags(newMode)
themeManager.currentTheme = newMode
}.also {
updateSecureWindowFlags(initialMode)
}
}
fun updateSecureWindowFlags(mode: BrowsingMode = browsingModeManager.mode) {
if (mode == BrowsingMode.Private && !settings().allowScreenshotsInPrivateMode) {
window.addFlags(FLAG_SECURE)
} else {
window.clearFlags(FLAG_SECURE)
}
}

@ -13,6 +13,7 @@ import androidx.navigation.NavOptions
import androidx.navigation.fragment.NavHostFragment.findNavController
import androidx.navigation.fragment.findNavController
import mozilla.components.concept.base.crash.Breadcrumb
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavHostActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.Components
@ -65,6 +66,7 @@ fun Fragment.hideToolbar() {
*
*/
fun Fragment.redirectToReAuth(destinations: List<Int>, currentDestination: Int?) {
(activity as? HomeActivity)?.updateSecureWindowFlags()
if (currentDestination !in destinations) {
findNavController().popBackStack(R.id.savedLoginsAuthFragment, false)
}

@ -12,7 +12,6 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.os.StrictMode
import android.view.Display.FLAG_SECURE
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@ -85,6 +84,7 @@ import mozilla.components.support.ktx.android.content.res.resolveAttribute
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.Config
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
@ -104,8 +104,9 @@ import org.mozilla.fenix.ext.hideToolbar
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.mozonline.showPrivacyPopWindow
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor
import org.mozilla.fenix.home.sessioncontrol.SessionControlView
@ -121,8 +122,6 @@ import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.whatsnew.WhatsNew
import java.lang.ref.WeakReference
import kotlin.math.min
import org.mozilla.fenix.Config
import org.mozilla.fenix.home.mozonline.showPrivacyPopWindow
@ExperimentalCoroutinesApi
@Suppress("TooManyFunctions", "LargeClass")
@ -407,12 +406,6 @@ class HomeFragment : Fragment() {
}
}
if (browsingModeManager.mode.isPrivate) {
requireActivity().window.addFlags(FLAG_SECURE)
} else {
requireActivity().window.clearFlags(FLAG_SECURE)
}
consumeFrom(requireComponents.core.store) {
updateTabCounter(it)
}
@ -551,7 +544,6 @@ class HomeFragment : Fragment() {
sessionControlView = null
appBarLayout = null
bundleArgs.clear()
requireActivity().window.clearFlags(FLAG_SECURE)
}
override fun onStart() {

@ -5,9 +5,11 @@
package org.mozilla.fenix.settings
import android.os.Bundle
import android.view.WindowManager
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.PrivateShortcutCreateManager
import org.mozilla.fenix.components.metrics.Event
@ -44,7 +46,18 @@ class PrivateBrowsingFragment : PreferenceFragmentCompat() {
}
requirePreference<SwitchPreference>(R.string.pref_key_allow_screenshots_in_private_mode).apply {
onPreferenceChangeListener = SharedPreferenceUpdater()
onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
if ((activity as? HomeActivity)?.browsingModeManager?.mode?.isPrivate == true &&
newValue == false
) {
activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
return super.onPreferenceChange(preference, newValue)
}
}
}
}
}

@ -13,6 +13,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
@ -111,6 +112,14 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
setHasOptionsMenu(true)
}
override fun onResume() {
super.onResume()
activity?.window?.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
}
/**
* As described in #10727, the User should re-auth if the fragment is paused and the user is not
* navigating to SavedLoginsFragment or EditLoginFragment

@ -268,7 +268,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), UserInteractionHandler
private fun setSecureFlagsIfNeeded(private: Boolean) {
if (private && context?.settings()?.allowScreenshotsInPrivateMode == false) {
dialog?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else if (!(activity as HomeActivity).browsingModeManager.mode.isPrivate) {
} else {
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}

Loading…
Cancel
Save