maui icon indicating copy to clipboard operation
maui copied to clipboard

Stop Android from pinning native references to system services

Open aritchie opened this issue 1 year ago • 15 comments

Android system services can have their pointers disposed of causing pinned MAUI references to error.

Description of Change

Remove all private references in Android Essentials. Resolve the service from Application.Context.GetSystemService each time

Issues Fixed

https://github.com/dotnet/maui/issues/22204

Fixes # 22204

aritchie avatar May 07 '24 19:05 aritchie

Hey there @aritchie! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@mattleibow do you recall why we ended up pinning these?

It looks like the change to do so happened in https://github.com/dotnet/maui/pull/5407 but I'm not seeing any explanation of the choice of approach.

Redth avatar May 07 '24 19:05 Redth

I don't think there will be much of a perf hit here. It isn't called enough to really matter, however, I can also keep the private reference and watch the Handle == IntPtr.Zero to resolve the service again

aritchie avatar May 07 '24 20:05 aritchie

/azp run

jsuarezruiz avatar May 08 '24 10:05 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar May 08 '24 10:05 azure-pipelines[bot]

I think this was done to try make everything faster, but we were never able to measure before net7.

Since none of these are coming up in the recent perf logs, we can just get the new service each time. If we suddenly see spikes in the perf dashboards then we can revisit.

mattleibow avatar May 08 '24 13:05 mattleibow

@Redth mentioned to me offline that maybe we have the field to prevent the GC from collecting it. But, I am not sure if that was more just for iOS.

mattleibow avatar May 08 '24 14:05 mattleibow

/azp run

jsuarezruiz avatar May 13 '24 13:05 jsuarezruiz

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar May 13 '24 13:05 azure-pipelines[bot]

@aritchie any reason not to mark this ready for review?

PureWeen avatar May 13 '24 18:05 PureWeen

@PureWeen There was some debate around performance. I can check the Handle to keep a reference pinned, but I don't think it was necessary. Other than that, I haven't been able to get the sensor testing to work.

aritchie avatar May 13 '24 18:05 aritchie

@aritchie what do you mean by this:

I haven't been able to get the sensor testing to work.

Does the essentials sample app not run or something?

mattleibow avatar May 15 '24 14:05 mattleibow

@mattleibow Ya I've been having issues with it. I've basically written a side chunk of code to test with for now. I just haven't had the time to go back to sensors.

aritchie avatar May 15 '24 15:05 aritchie

maybe we broke everything. We basically did 2 major changes to the build system these last few days so all is bad. Hopefully we can fix things soon and all the samples start running again :)

mattleibow avatar May 16 '24 19:05 mattleibow

/rebase

PureWeen avatar May 17 '24 14:05 PureWeen