maui
maui copied to clipboard
Catch InvalidProtocolBufferException creating EncryptedSharedPreferences
Description of Change
Creating EncryptedSharedPreferences on some devices throw InvalidProtocolBufferException.
This PR catches this exception instead of throwing it to the consumer.
Issues Fixed
Fixes #13597
Hey there @Cheesebaron! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
Not 100% sure, but perhaps we should remove all keys if this occurs.
Not 100% sure, but perhaps we should remove all keys if this occurs.
What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.
Not 100% sure, but perhaps we should remove all keys if this occurs.
What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.
It is a bug in AndroidX Security that Essentials is currently using, which breaks the Encrypted Shared Preferences when restored from a backup and results in a exception.
Situation should be better with a newer version according to the bug linked in the issue. However, there are no bindings for it 🥲
I asked @moljac on Discord if we could perhaps get a newer version bound, even though there is a policy on not binding pre-release stuff.
Azure Pipelines successfully started running 2 pipeline(s).
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
Not 100% sure, but perhaps we should remove all keys if this occurs.
What is the situation here? When does this occur? Is there any recovery scenario? If not, I'd say indeed wipe it.
It is a bug in AndroidX Security that Essentials is currently using, which breaks the Encrypted Shared Preferences when restored from a backup and results in a exception.
Situation should be better with a newer version according to the bug linked in the issue. However, there are no bindings for it 🥲
I asked @moljac on Discord if we could perhaps get a newer version bound, even though there is a policy on not binding pre-release stuff.
... and I got green light to bind update
https://github.com/xamarin/AndroidX/pull/707
Build error 🙅
D:\a_work\1\s\src\Essentials\src\SecureStorage\SecureStorage.android.cs(113,5): error CS0120: An object reference is required for the non-static field, method, or property 'SecureStorageImplementation.PlatformRemoveAll()' [D:\a_work\1\s\src\Essentials\src\Essentials.csproj::TargetFramework=net7.0-android]
Oopsie. Fixed.
published new previews
https://www.nuget.org/packages/Xamarin.AndroidX.Security.SecurityCrypto/1.1.0-alpha05 https://www.nuget.org/packages/Xamarin.AndroidX.Security.SecurityCrypto.Ktx/1.1.0-alpha05
/azp run
Azure Pipelines successfully started running 2 pipeline(s).
hi I still have the same issue and app is crashing

See also:
- https://learn.microsoft.com/en-us/answers/questions/1001662/suddenly-getting-securestorage-issues-in-maui
Would strongly recommend backporting this to .net 7. There is no recovery path when it starts happening randomly, and in my experience, even catching exceptions is not sufficient - there are exceptions that bubble up the stack and cause crashes.
/backport to net7.0
Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5270320306