Add Subject config flag to avoid WindowManager bug #683
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.
For issue #657.
This bug occurs during tracker initialisation when a) an Android application context from a dependency injection framework is passed in, and b) the Android StrictMode rule
detectIncorrectContextUse()
is set for the app.That rule is violated when creating
Subject
, inSubject.setDefaultScreenResolution()
, because it uses a deprecated method, viaWindowManager
, to fetch the screen size. The resolution set there in Subject is added to the payload as the "res" property, which eventually becomes the "dvce_screenwidth/height" columns.The current preferred way is
DisplayManager
or from thecontext.resources
. We already use the context Resources to get the screen resolution for the mobile/platform context entity.Unfortunately,
WindowManager
gives a different answer fromDisplayManager
/Resources
. The old way includes the menu bar at the top of the screen but that's not included anymore. Changing how Subject fetches the size is therefore a breaking change.This PR adds a new flag to
SubjectConfiguration
. When set to true (false is default), the default Subject screen size is obtained from the context Resources andWindowManager
is not accessed - meaning no StrictMode violation.Currently, the flag is set up just like the other Subject properties. This doesn't seem necessary since it's only used in Subject initialisation.
SubjectController
doesn't really need it, but it inherits fromSubjectConfigurationInterface
. Anyway, it's Friday evening and this fix works.