dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

[Android] StrictMode violation caused by IllegalAccessException in ShellSectionRenderer.OnCreateView() during startup #19414

Open BioTurboNick opened 11 months ago

BioTurboNick commented 11 months ago

Description

When investigating ANRs in my app, I turned on StrictMode violation logging. I found that ShellSectionRenderer.OnCreateView() is causing an IllegalAccessException attempting to access the WindowManager, which turned into an IncorrectContextUseViolation.

Steps to Reproduce

No response

Link to public reproduction project repository

MauiApp3.csproj.zip

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

No response

Relevant log output

[StrictMode] StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[StrictMode]    at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2260)
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2196)
[StrictMode]    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[StrictMode]    at crc640ec207abc449b2ca.ShellSectionRenderer.n_onCreateView(Native Method)
[StrictMode]    at crc640ec207abc449b2ca.ShellSectionRenderer.onCreateView(ShellSectionRenderer.java:44)
[StrictMode]    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3114)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:557)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[StrictMode]    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[StrictMode]    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
[StrictMode]    at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
[StrictMode]    at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3042)
[StrictMode]    at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2945)
[StrictMode]    at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3148)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:588)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[StrictMode]    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[StrictMode]    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
[StrictMode]    at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
[StrictMode]    at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3042)
[StrictMode]    at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2952)
[StrictMode]    at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:263)
[StrictMode]    at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:350)
[StrictMode]    at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
[StrictMode]    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1510)
[StrictMode]    at android.app.Activity.performStart(Activity.java:8616)
[StrictMode]    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:4204)
[StrictMode]    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
[StrictMode]    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
[StrictMode]    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
[StrictMode]    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
[StrictMode]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
[StrictMode]    at android.os.Handler.dispatchMessage(Handler.java:106)
[StrictMode]    at android.os.Looper.loopOnce(Looper.java:226)
[StrictMode]    at android.os.Looper.loop(Looper.java:313)
[StrictMode]    at android.app.ActivityThread.main(ActivityThread.java:8762)
[StrictMode]    at java.lang.reflect.Method.invoke(Native Method)
[StrictMode]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[StrictMode]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
[StrictMode] Caused by: java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[StrictMode]    ... 37 more
[ContextImpl] Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[ContextImpl] java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[ContextImpl]   at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[ContextImpl]   at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[ContextImpl]   at crc640ec207abc449b2ca.ShellSectionRenderer.n_onCreateView(Native Method)
[ContextImpl]   at crc640ec207abc449b2ca.ShellSectionRenderer.onCreateView(ShellSectionRenderer.java:44)
[ContextImpl]   at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3114)
[ContextImpl]   at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:557)
[ContextImpl]   at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[ContextImpl]   at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[ContextImpl]   at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
[ContextImpl]   at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
[ContextImpl]   at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3042)
[ContextImpl]   at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2945)
[ContextImpl]   at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3148)
[ContextImpl]   at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:588)
[ContextImpl]   at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[ContextImpl]   at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[ContextImpl]   at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1845)
[ContextImpl]   at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
[ContextImpl]   at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3042)
[ContextImpl]   at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2952)
[ContextImpl]   at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:263)
[ContextImpl]   at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:350)
[ContextImpl]   at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
[ContextImpl]   at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1510)
[ContextImpl]   at android.app.Activity.performStart(Activity.java:8616)
[ContextImpl]   at android.app.ActivityThread.handleStartActivity(ActivityThread.java:4204)
[ContextImpl]   at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
[ContextImpl]   at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
[ContextImpl]   at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
[ContextImpl]   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
[ContextImpl]   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574)
[ContextImpl]   at android.os.Handler.dispatchMessage(Handler.java:106)
[ContextImpl]   at android.os.Looper.loopOnce(Looper.java:226)
[ContextImpl]   at android.os.Looper.loop(Looper.java:313)
[ContextImpl]   at android.app.ActivityThread.main(ActivityThread.java:8762)
[ContextImpl]   at java.lang.reflect.Method.invoke(Native Method)
[ContextImpl]   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[ContextImpl]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
BioTurboNick commented 11 months ago

I don't know if these are truly separate, but I'm seeing similar context violations in ShellFragmentContainer.OnCreateView(), ContentViewGroup.OnMeasure(), RunnableImplementor.Run()

[StrictMode] StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[StrictMode]    at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2260)
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2196)
[StrictMode]    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[StrictMode]    at crc640ec207abc449b2ca.ShellFragmentContainer.n_onCreateView(Native Method)
[StrictMode]    at crc640ec207abc449b2ca.ShellFragmentContainer.onCreateView(ShellFragmentContainer.java:41)
[StrictMode]    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3114)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:557)
[StrictMode]    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:272)
[StrictMode]    at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1943)
[StrictMode]    at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1839)
[StrictMode]    at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1751)
[StrictMode]    at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317)
[StrictMode]    at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:341)
[StrictMode]    at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:276)
[StrictMode]    at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:67)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:8291)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:924)
[StrictMode]    at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:107)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:9344)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9302)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:9289)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1676)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1622)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:687)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4604)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4307)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4873)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:527)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:149)
[StrictMode]    at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43)
[StrictMode]    at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:2376)
[StrictMode]    at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:953)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1273)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1818)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1584)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at com.android.internal.policy.DecorView.onLayout(DecorView.java:1431)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4917)
[StrictMode]    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4240)
[StrictMode]    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3116)
[StrictMode]    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10885)
[StrictMode]    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1301)
[StrictMode]    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1309)
[StrictMode]    at android.view.Choreographer.doCallbacks(Choreographer.java:923)
[StrictMode]    at android.view.Choreographer.doFrame(Choreographer.java:852)
[StrictMode]    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1283)
[StrictMode]    at android.os.Handler.handleCallback(Handler.java:942)
[StrictMode]    at android.os.Handler.dispatchMessage(Handler.java:99)
[StrictMode]    at android.os.Looper.loopOnce(Looper.java:226)
[StrictMode]    at android.os.Looper.loop(Looper.java:313)
[StrictMode]    at android.app.ActivityThread.main(ActivityThread.java:8762)
[StrictMode]    at java.lang.reflect.Method.invoke(Native Method)
[StrictMode]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[StrictMode]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
[StrictMode] Caused by: java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[StrictMode]    ... 96 more
[StrictMode] StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[StrictMode]    at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2260)
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2196)
[StrictMode]    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[StrictMode]    at crc6452ffdc5b34af3a0f.ContentViewGroup.n_onMeasure(Native Method)
[StrictMode]    at crc6452ffdc5b34af3a0f.ContentViewGroup.onMeasure(ContentViewGroup.java:59)
[StrictMode]    at android.view.View.measure(View.java:27731)
[StrictMode]    at crc640ec207abc449b2ca.ShellPageContainer.n_onMeasure(Native Method)
[StrictMode]    at crc640ec207abc449b2ca.ShellPageContainer.onMeasure(ShellPageContainer.java:66)
[StrictMode]    at android.view.View.measure(View.java:27731)
[StrictMode]    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
[StrictMode]    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
[StrictMode]    at android.view.View.measure(View.java:27731)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView$LayoutManager.measureChildWithMargins(RecyclerView.java:10124)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1688)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1622)
[StrictMode]    at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:687)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4604)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4307)
[StrictMode]    at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4873)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:527)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:149)
[StrictMode]    at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43)
[StrictMode]    at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:2376)
[StrictMode]    at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:953)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1273)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1818)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1584)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
[StrictMode]    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
[StrictMode]    at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
[StrictMode]    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
[StrictMode]    at com.android.internal.policy.DecorView.onLayout(DecorView.java:1431)
[StrictMode]    at android.view.View.layout(View.java:24969)
[StrictMode]    at android.view.ViewGroup.layout(ViewGroup.java:6784)
[StrictMode]    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4917)
[StrictMode]    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4240)
[StrictMode]    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3116)
[StrictMode]    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10885)
[StrictMode]    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1301)
[StrictMode]    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1309)
[StrictMode]    at android.view.Choreographer.doCallbacks(Choreographer.java:923)
[StrictMode]    at android.view.Choreographer.doFrame(Choreographer.java:852)
[StrictMode]    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1283)
[StrictMode]    at android.os.Handler.handleCallback(Handler.java:942)
[StrictMode]    at android.os.Handler.dispatchMessage(Handler.java:99)
[StrictMode]    at android.os.Looper.loopOnce(Looper.java:226)
[StrictMode]    at android.os.Looper.loop(Looper.java:313)
[StrictMode]    at android.app.ActivityThread.main(ActivityThread.java:8762)
[StrictMode]    at java.lang.reflect.Method.invoke(Native Method)
[StrictMode]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[StrictMode]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
[StrictMode] Caused by: java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[StrictMode]    ... 88 more
[StrictMode] StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[StrictMode]    at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2260)
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2196)
[StrictMode]    at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[StrictMode]    at mono.java.lang.RunnableImplementor.n_run(Native Method)
[StrictMode]    at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
[StrictMode]    at android.os.Handler.handleCallback(Handler.java:942)
[StrictMode]    at android.os.Handler.dispatchMessage(Handler.java:99)
[StrictMode]    at android.os.Looper.loopOnce(Looper.java:226)
[StrictMode]    at android.os.Looper.loop(Looper.java:313)
[StrictMode]    at android.app.ActivityThread.main(ActivityThread.java:8762)
[StrictMode]    at java.lang.reflect.Method.invoke(Native Method)
[StrictMode]    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[StrictMode]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
[StrictMode] Caused by: java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[StrictMode]    at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[StrictMode]    ... 11 more
[ContextImpl] Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen.
[ContextImpl] java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:crc64388215b9f0c408ca.MainApplication@485b95c
[ContextImpl]   at android.app.ContextImpl.getSystemService(ContextImpl.java:2195)
[ContextImpl]   at android.content.ContextWrapper.getSystemService(ContextWrapper.java:917)
[ContextImpl]   at mono.java.lang.RunnableImplementor.n_run(Native Method)
[ContextImpl]   at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
[ContextImpl]   at android.os.Handler.handleCallback(Handler.java:942)
[ContextImpl]   at android.os.Handler.dispatchMessage(Handler.java:99)
[ContextImpl]   at android.os.Looper.loopOnce(Looper.java:226)
[ContextImpl]   at android.os.Looper.loop(Looper.java:313)
[ContextImpl]   at android.app.ActivityThread.main(ActivityThread.java:8762)
[ContextImpl]   at java.lang.reflect.Method.invoke(Native Method)
[ContextImpl]   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
[ContextImpl]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
ghost commented 10 months ago

Hi @BioTurboNick. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

BioTurboNick commented 10 months ago

I've added a repro to the OP. It's just the stock MAUI default project with StrictMode turned on. The error will show in the debug logs.

ghost commented 10 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.