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

strict mode violation exception prevention #89

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

yanioaioan
Copy link

Please complete the following information:

Library Version 2.2.0
Android 11.0
Describe the Bug:

Using the CustomPowerMenu.Builder and having Strict mode enabled in our Android app we get StrictMode policy violation; ~duration=453 ms: android.os.strictmode.DiskReadViolation exception when trying to inflate our view

Expected Behavior:

Is it possible to provide a way of using for the CustomPowerMenu.Builder which uses AbstractPowerMenu which uses MenuPreferenceManager but NOT read or write to sharedPrefs from within MenuPreferenceManager as it currently stands, so as to avoid the StrictMode policy violation; ~duration=453 ms: android.os.strictmode.DiskReadViolation

@yanioaioan
Copy link
Author

yanioaioan commented Aug 3, 2022

@skydoves would you be able to check my PR, please? (as it's on 'awaiting approval')

@skydoves
Copy link
Owner

skydoves commented Aug 6, 2022

Hi @yanioaioan, thanks for contributing to this PR.
I'm just wondering if reading and writing to SharedPreferences must be run on a worker thread over Android 11. Or does only PowerMenu affects the exception? Thank you!

@yanioaioan
Copy link
Author

Hi @skydoves, thanks for your response. I suppose shared prefs could potentially be accessesed on the background thread, however I am not sure is necessary to be fair. This change should temporarily be allowing disk access anyway and sort that issue anyway.

@yanioaioan
Copy link
Author

Hi @skydoves , actually even my suggestion is not really solving the original problem which is touching the disk in the first place.
With my suggestion we would only allow it temporarily to avoid showing the disk access violation error but the point is more lie
whther we can avoid touching the disk all together, so that when we initialize the library we save one unnecessary disk access?

Copy link
Author

@yanioaioan yanioaioan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skydoves , please check the change suggested. Basically moved sharedPrefs creation out of the MenuPreferenceManager construction. This way, there wouldn't be any disk access violations (by simply initializing the lib), but onlt if the getPosition, setPosition or clearPosition were actually used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants