Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 57ca221882695bd6a52549f4d9ea3b812e6fe87c
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 16:09:30 2021
[GH] [FragmentStrictMode] Detect <fragment> tag usage
## Proposed Changes
- Detect `<fragment>` tag usage inside XML layouts
## Testing
Test: See `FragmentStrictModeTest#detectFragmentTagUsage`
## Issues Fixed
Fixes: 153738235
This is an imported pull request fromhttps://github.com/androidx/androidx/pull/141 .
Resolves #141
Github-Pr-Head-Sha: 4ea052596e4341b9f11bcf335e2bc38045a91f19
GitOrigin-RevId: 62e7487aa4874eef6bb556490e193717cf937251
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentTagUsageViolation.java
https://android-review.googlesource.com/1649748
Branch: androidx-main
commit 57ca221882695bd6a52549f4d9ea3b812e6fe87c
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 16:09:30 2021
[GH] [FragmentStrictMode] Detect <fragment> tag usage
## Proposed Changes
- Detect `<fragment>` tag usage inside XML layouts
## Testing
Test: See `FragmentStrictModeTest#detectFragmentTagUsage`
## Issues Fixed
Fixes: 153738235
This is an imported pull request from
Resolves #141
Github-Pr-Head-Sha: 4ea052596e4341b9f11bcf335e2bc38045a91f19
GitOrigin-RevId: 62e7487aa4874eef6bb556490e193717cf937251
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentTagUsageViolation.java
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit ea9e9a8978b26c9cd05ec0794f90ac11b2be06e6
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Dec 03 14:33:34 2020
Ensure onPrepareOptionsMenu considers parent menu visibility
onCreateOptionsMenu already has child fragment consider parent menu
visiblity but onPrepareOptionsMenu does not. This means that child
fragments that have parents with no menu, will still get a callback to
onPrepareOptionsMenu, which will result in a crash.
We should make sure onPrepareOptionsMenu also considers if the parent
menu is visible.
RelNote: "`onPrepareOptionsMenu()` now follows the same logic as
`onCreateOptionsMenu()` and is no longer called when a parent fragment
calls `setMenuVisibility(false)`."
Test: OptionsMenuFragmentTest
Bug: 173203654
Change-Id: Id7de8156980c09e6ece0d977950b4844eb10d516
M fragment/fragment/src/androidTest/java/androidx/fragment/app/OptionsMenuFragmentTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android-review.googlesource.com/1516804
Branch: androidx-master-dev
commit ea9e9a8978b26c9cd05ec0794f90ac11b2be06e6
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Dec 03 14:33:34 2020
Ensure onPrepareOptionsMenu considers parent menu visibility
onCreateOptionsMenu already has child fragment consider parent menu
visiblity but onPrepareOptionsMenu does not. This means that child
fragments that have parents with no menu, will still get a callback to
onPrepareOptionsMenu, which will result in a crash.
We should make sure onPrepareOptionsMenu also considers if the parent
menu is visible.
RelNote: "`onPrepareOptionsMenu()` now follows the same logic as
`onCreateOptionsMenu()` and is no longer called when a parent fragment
calls `setMenuVisibility(false)`."
Test: OptionsMenuFragmentTest
Bug: 173203654
Change-Id: Id7de8156980c09e6ece0d977950b4844eb10d516
M fragment/fragment/src/androidTest/java/androidx/fragment/app/OptionsMenuFragmentTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
il...@google.com <il...@google.com> #4
This has been fixed internally and will be available in Fragment 1.3.0-rc01
.
Description
Build: AI-201.8743.12.41.6953283, 202011050241,
AI-201.8743.12.41.6953283, JRE 1.8.0_242-release-1644-b3-6222593x64 JetBrains s.r.o, OS Linux(amd64) v5.4.0-53-generic, screens 3440x1440
AS: 4.1.1; Kotlin plugin: 1.4.10-release-Studio4.1-1; Android Gradle Plugin: 4.1.1; Gradle: 6.5; NDK: from local.properties: (not specified), latest from SDK: 21.3.6528147; LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: 3.16.3
Affected version:
androidx.fragment:fragment-ktx:1.2.5
Note: It looks like all versions starting from 1.2+ are affected
Description
When you have view pager with nested fragment that shows menu it will crash if you try to access menu items from
onPrepareOptionsMenu
.Steps to reproduce
ViewPager
Fragment1
Fragment2
Fragment2
add nestedFragment21
and enablesetHasOptionsMenu(true)
, also add new menu specific to this fragmentFragment21
fromonPrepareOptionsMenu
Expected behavior
onPrepareOptionsMenu
should never be called if menu is not inflatedActual behavior
onPrepareOptionsMenu
Additional information
Looking through the changes I was able to pinpoint it to this behavior change:https://android.googlesource.com/platform/frameworks/support/+/4809e01d4153a5ba68cb68f36544baa1b90738c0
We are now also checking for parent menu visibility but only in
dispatchCreateOptionsMenu
, which means we would calldispatchPrepareOptionsMenu
with no menu inflated since we skipped it.Possible fix
dispatch*Menu
methods, ordispatchCreateOptionsMenu
Demo repository:
You can find repository with repro steps here:https://github.com/vovkab/fragment-menu-crash