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

Exit PiP when launched externally with Intents #6768

Merged
Merged
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
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/focus/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ open class MainActivity : LocaleAwareAppCompatActivity() {
updateSecureWindowFlags()
super.onCreate(savedInstanceState)

// Checks if Activity is currently in PiP mode if launched from external intents, then exits it
checkAndExitPiP()

if (!isTaskRoot) {
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN == intent.action) {
finish()
Expand Down Expand Up @@ -112,6 +115,14 @@ open class MainActivity : LocaleAwareAppCompatActivity() {
AppReviewUtils.showAppReview(this)
}

private fun checkAndExitPiP() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode && intent != null) {
// Exit PiP mode
moveTaskToBack(false)
startActivity(Intent(this, this::class.java).setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT))
}
}

final override fun onUserLeaveHint() {
val browserFragment =
supportFragmentManager.findFragmentByTag(BrowserFragment.FRAGMENT_TAG) as BrowserFragment?
Expand Down