PowerMenu icon indicating copy to clipboard operation
PowerMenu copied to clipboard

strict mode violation exception prevention

Open yanioaioan opened this issue 2 years ago • 4 comments

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 avatar Jun 23 '22 09:06 yanioaioan

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

yanioaioan avatar Aug 03 '22 14:08 yanioaioan

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!

skydoves avatar Aug 06 '22 06:08 skydoves

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 avatar Aug 08 '22 08:08 yanioaioan

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?

yanioaioan avatar Aug 30 '22 07:08 yanioaioan