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

Stop Android from pinning native references to system services #22281

Merged
merged 2 commits into from May 27, 2024

Conversation

aritchie
Copy link
Contributor

@aritchie aritchie commented May 7, 2024

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

#22204

Fixes # 22204

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label May 7, 2024
Copy link
Contributor

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.

@Redth Redth requested a review from mattleibow May 7, 2024 19:51
@Redth
Copy link
Member

Redth commented May 7, 2024

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

It looks like the change to do so happened in #5407 but I'm not seeing any explanation of the choice of approach.

@aritchie
Copy link
Contributor Author

aritchie commented May 7, 2024

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

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

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.

@Redth Redth added this to the Backlog milestone May 8, 2024
@mattleibow
Copy link
Member

@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.

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

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

@aritchie
Copy link
Contributor Author

@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.

@PureWeen PureWeen added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label May 15, 2024
@mattleibow
Copy link
Member

@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?

@aritchie
Copy link
Contributor Author

@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.

@mattleibow
Copy link
Member

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 :)

@PureWeen
Copy link
Member

PureWeen commented May 17, 2024

/rebase

@aritchie aritchie marked this pull request as ready for review May 24, 2024 01:58
@aritchie aritchie requested a review from a team as a code owner May 24, 2024 01:58
@rmarinho rmarinho merged commit 37b875a into dotnet:main May 27, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info community ✨ Community Contribution platform/android 🤖
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants