consp1racy / android-support-preference

Android Preferences according to Material design specs
Apache License 2.0
331 stars 49 forks source link

Ringtone picker issues #105

Closed dirkam closed 6 years ago

dirkam commented 6 years ago

Hi,

Using 2.2.0 with 27.1.1 (preference-v7 27.0.2) support lib. Got a few ringtones related fatal/non-fatal crash reports. Not sure if they are related, but didn't want to open separate issues just yet, let me know. Seemingly very rare issues and can't reproduce them.

HTC, Android 6

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.net.Uri.getCanonicalUri()' on a null object reference
       at android.media.Ringtone.play(Ringtone.java:436)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.run(XpRingtonePreferenceDialogFragment.java:529)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:168)
       at android.app.ActivityThread.main(ActivityThread.java:5845)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)

Motorola Android 8

Non-fatal Exception: java.lang.IllegalStateException: No cursor that can return names
       at com.android.internal.database.SortCursor.getColumnNames(SortCursor.java:251)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.loadRingtoneManager(XpRingtonePreferenceDialogFragment.java:1225)
       at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2355)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1451)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
       at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
       at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
       at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6494)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Pixel Android P (most probably Beta)

Non-fatal Exception: java.lang.NoSuchMethodException: getInternalRingtones []
       at java.lang.Class.getMethod(Class.java:2068)
       at java.lang.Class.getDeclaredMethod(Class.java:2047)
       at net.xpece.android.support.preference.RingtoneManagerCompat.(RingtoneManagerCompat.java:39)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.loadRingtoneManager(XpRingtonePreferenceDialogFragment.java:1187)
       at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2355)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1451)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
       at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
       at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
       at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6649)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)

Pixel Android P (most probably Beta)

Non-fatal Exception: java.lang.NoSuchFieldException: No field mCursor in class Landroid/media/RingtoneManager; (declaration of 'android.media.RingtoneManager' appears in /system/framework/framework.jar)
       at java.lang.Class.getDeclaredField(Class.java)
       at net.xpece.android.support.preference.RingtoneManagerCompat.(RingtoneManagerCompat.java:30)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.loadRingtoneManager(XpRingtonePreferenceDialogFragment.java:1187)
       at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2355)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1451)
       at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
       at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
       at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
       at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
       at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6649)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
consp1racy commented 6 years ago

Thanks for all the reports. It looks like the library is not compatible with Android P, because we can no longer access some private fields and methods in the framework. I'll get to work on the essentials.

dirkam commented 6 years ago

On P Emulator it works fine. I'll update my Pixel to P during the weekend and I'll test this myself as well.

consp1racy commented 6 years ago

There were two issues on Android P: 1) ringtone picker would show no ringtones 2) XpAppCompatSpinner would crash

Both of these issues are now fixed. Try this commit:

implementation 'com.github.consp1racy:android-support-preference:e590280557'

It also includes changes mentioned here: https://github.com/consp1racy/android-support-preference/issues/81#issuecomment-388210163 You can check the changelog here: CHANGELOG.md

dirkam commented 6 years ago

How did you reproduce these issues on P? Tried it but it works for me. How can I use this commit? It says "Unable to resolve".

consp1racy commented 6 years ago

You'll also need to define the jitpack repo. Put this at the end of your app module build.gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dirkam commented 6 years ago

It's been defined there, probably I tried to use it too soon.

Now it gives Error:cannot access ParametersAreNonnullByDefault when trying to build the app.

consp1racy commented 6 years ago

That's just weird. Ok, make sure you have the google() and jcenter() repos as well.

If that doesn't work declare a dependency on https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305/3.0.2 The instructions for Gradle are on the page.

Do you extend and implement your own preferences?

dirkam commented 6 years ago

I do have a custom preference extending net.xpece.android.support.preference.DialogPreference and one net.xpece.android.support.preference.SeekBarDialogPreference

consp1racy commented 6 years ago

As for the first fatal report, I've made it a non-fatal and put some more logging around it. RingtoneManager created a Ringtone object with a null Uri. That can happen in 3 places. Logging should help me pinpoint where exactly did it happen.

I've also hopefully fixed your problems with consuming a snapshot version of library from jitpack. It turns out all annotations need to be in build classpath so Proguard can access them. All annotations are now implementation dependency of this library.

That makes all issues mentioned in this thread resolved. I'll close this for now and we can monitor the Ringtones with null Uri in a new issue later.