Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ObjectDisposedException: ObjectDisposed_Generic ObjectDisposed_ObjectName_Name, Android.OS.PowerManager #22204

Closed
mattgagnon2 opened this issue May 3, 2024 · 6 comments
Assignees
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@mattgagnon2
Copy link

mattgagnon2 commented May 3, 2024

Description

When running our application without a charging cable plugged in, the application will crash at any point below 50% battery charge. There is currently no reference the the Battery object. If the application is running and the charging cable is plugged in, the same crash occurs.

Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable )
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod(String , IJavaPeerable , JniArgumentValue* )
Android.OS.PowerManager.get_IsPowerSaveMode()
Microsoft.Maui.Devices.BatteryImplementation.get_EnergySaverStatus()
Microsoft.Maui.Devices.BatteryImplementation.OnEnergySaverChanged()
Microsoft.Maui.Devices.EnergySaverBroadcastReceiver.OnReceive(Context , Intent )
Android.Content.BroadcastReceiver.n_OnReceive_Landroid_content_Context_Landroid_content_Intent_(IntPtr jnienv, IntPtr native__this, IntPtr native_context, IntPtr native_intent)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_V(_JniMarshal_PPLL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1)

I believe that a third party component, Shiny Jobs, is disposing the the PowerManager after the battery implementation has retrieved it.

Steps to Reproduce

  1. Start the app
  2. Unplug the usb cable
  3. Wait for the battery info to change

Link to public reproduction project repository

ObjectDisposedSample

Version with bug

8.0.21

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

No response

Did you find any workaround?

Keep the usb cable plugged in

Relevant log output

No response

@mattgagnon2 mattgagnon2 added the t/bug Something isn't working label May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@samhouts samhouts added area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info partner/android Issues for the Android SDK labels May 3, 2024
@PureWeen PureWeen added the s/needs-repro Attach a solution or code which reproduces the issue label May 3, 2024
@mattgagnon2
Copy link
Author

Updated with repo steps and sample repo

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels May 7, 2024
@aritchie
Copy link
Contributor

aritchie commented May 7, 2024

@mattgagnon2 No. I'm disposing of my attachment to a native service. That does not effect others pulling in that instance.

@mattgagnon2
Copy link
Author

I am just trying to find a solution. You can confirm with the sample app attached and repo steps that the exception is thrown when the trying to get the EnergySaverStatus or when the OnEnergySaverStatusChanged event is run, and if you comment out the line 31 in MauiProgram that registers the job to run, the exception doesn't happen. Shiny has a using statement of
using var pm = this.platform.GetSystemService<Android.OS.PowerManager>(Context.PowerService);
that I thought might be disposing the PowerManager and thus throwing the exception.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 11, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio 17.10 Preview 7.0 (8.0.21). Can repro on android platform with sample project.
image

@mattleibow
Copy link
Member

This is now fixed by #22281

@github-project-automation github-project-automation bot moved this from Todo to Done in MAUI SDK Ongoing Jun 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

6 participants