[Xamarin.Android.Build.Tasks] Add directBootAware
if needed. (#2621)
#2637
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #2081
Context? http://work.devdiv.io/727120
The
//application/@android:directBootAware
attribute changeshow process startup semantics work, in non-obvious ways.
Consider the following:
Expected results: An alarm goes off.
Actual results: Nothing happens, and
adb logcat
contains:One of the apparent changes when
directBootAware
is used is that<provider/>
s must also "opt-in" todirectBootAware
.If a
<provider/>
isn't alsodirectBootAware
, then the<provider/>
can't be used before the device is unlocked.Our Bootstrap code within
MonoRuntimeProvider
is "injected" via<provider/>
. Meaning if the app usesdirectBootAware
but theMonoRuntimeProvider
isn'tdirectBootAware
, then the app can'tuse any managed code before the device has been unlocked.
Which is why the
UnsatisfiedLinkError
is generated: theMonoRuntimeProvider
hasn't been created, meaningmono
hasn't beeninitialized, meaning nothing can work until the device is unlocked.
The fix? If anything within
AndroidManifest
sets//*[@android:directBootAware='true']
, then add a@android:directBootAware="true"
attribute to the generated<provider/>
formono.MonoRuntimeProvider
. This will ensure thatmanaged code is properly initialized and can execute after the device
has been rebooted and before the user has unlocked the device.