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

Ringtone picker crashes on Q #120

Closed
dirkam opened this issue Aug 9, 2019 · 4 comments
Closed

Ringtone picker crashes on Q #120

dirkam opened this issue Aug 9, 2019 · 4 comments
Assignees
Labels
bug-android A bug in Android. subject-ringtone Issues targeting ringtone resolution and playback.

Comments

@dirkam
Copy link

dirkam commented Aug 9, 2019

Can you please take a look at this? It crashes on devices running Q beta (latest beta 6 and possibly beta 5).

Fatal Exception: java.lang.NumberFormatException: For input string: "default"
       at java.lang.Long.parseLong + 594(Long.java:594)
       at java.lang.Long.parseLong + 636(Long.java:636)
       at android.content.ContentUris.parseId + 89(ContentUris.java:89)
       at android.media.RingtoneManager.getRingtonePosition + 513(RingtoneManager.java:513)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.onPrepareDialogBuilder + 310(XpRingtonePreferenceDialogFragment.java:310)
       at androidx.preference.PreferenceDialogFragmentCompat.onCreateDialog + 155(PreferenceDialogFragmentCompat.java:155)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.onCreateDialog + 179(XpRingtonePreferenceDialogFragment.java:179)
       at androidx.fragment.app.DialogFragment.onGetLayoutInflater + 330(DialogFragment.java:330)
       at net.xpece.android.support.preference.XpRingtonePreferenceDialogFragment.onActivityCreated + 169(XpRingtonePreferenceDialogFragment.java:169)
       at androidx.fragment.app.Fragment.performActivityCreated + 2460(Fragment.java:2460)
       at androidx.fragment.app.FragmentManagerImpl.moveToState + 1483(FragmentManagerImpl.java:1483)
       at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState + 1784(FragmentManagerImpl.java:1784)
       at androidx.fragment.app.FragmentManagerImpl.moveToState + 1852(FragmentManagerImpl.java:1852)
       at androidx.fragment.app.BackStackRecord.executeOps + 802(BackStackRecord.java:802)
       at androidx.fragment.app.FragmentManagerImpl.executeOps + 2625(FragmentManagerImpl.java:2625)
       at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether + 2411(FragmentManagerImpl.java:2411)
       at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute + 2366(FragmentManagerImpl.java:2366)
       at androidx.fragment.app.FragmentManagerImpl.execPendingActions + 2273(FragmentManagerImpl.java:2273)
       at androidx.fragment.app.FragmentManagerImpl$1.run + 733(FragmentManagerImpl.java:733)
       at android.os.Handler.handleCallback + 883(Handler.java:883)
       at android.os.Handler.dispatchMessage + 100(Handler.java:100)
       at android.os.Looper.loop + 214(Looper.java:214)
       at android.app.ActivityThread.main + 7356(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 492(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main + 930(ZygoteInit.java:930)
@consp1racy
Copy link
Owner

Until Android Q is released to AOSP I'm blind.

I can implement a fallback to system picker in the library. In the meantime the easiest workaround for you is to put the following in your settings fragment:

@Override
public void onDisplayPreferenceDialog(@NonNull Preference preference) {
    if (preference instanceof RingtonePreference && Build.VERSION.SDK_INT >= 29) {
        final Intent i = ((RingtonePreference) preference).buildRingtonePickerIntent();
        startActivityForResult(i, 0xf00);
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0xf00) {
        findRingtonePreference().onActivityResult(data);
    }
    super.onActivityResult(requestCode, resultCode, data);
}

private RingtonePreference findRingtonePreference() {
    // get your ringtone preference by key here
}

Let's keep the issue open for tracking.

@consp1racy consp1racy self-assigned this Aug 14, 2019
@consp1racy consp1racy added the subject-ringtone Issues targeting ringtone resolution and playback. label Aug 14, 2019
@consp1racy
Copy link
Owner

consp1racy commented Aug 24, 2019

Depending on your input and preference setup the workaround may not work for you. The system picker may also crash. Basically you can feed it

  • Default Uri only if you enabled Default item in the list.
  • Silent Uri only if you enabled Silent item in the list.
  • Any other Uri that ends with a number.

Previously RingtoneManager.getRingtonePosition would return -1. Now it crashes when the Uri doesn't end with a number.

I'll report this to Google. Reported to Google: https://issuetracker.google.com/issues/139935440


As for your Uri that's ending with "default" I don't know where that came from. The standard Uris are:

  • content://com.android.settings/system/ringtone
  • content://com.android.settings/system/notification_sound
  • content://com.android.settings/system/alarm_alert

What can you tell me about the device the crash occurred on?

consp1racy added a commit that referenced this issue Aug 24, 2019
System ringtone picker could crash media server when supplied Uri
didn't end with number.
Local process could crash when supplied Uri didn't end with number.

#120
https://issuetracker.google.com/issues/139935440
consp1racy added a commit that referenced this issue Aug 24, 2019
System ringtone picker could crash media server when supplied Uri
didn't end with number.
Local process could crash when supplied Uri didn't end with number.

#120
https://issuetracker.google.com/issues/139935440
@consp1racy
Copy link
Owner

This is now fixed in 4dae391 (2.x-dev) and 6d5ebc7 (3.x-dev).

RingtonePreference.buildRingtonePickerIntent will also safeguard against this issue.

@consp1racy consp1racy added the bug-android A bug in Android. label Aug 24, 2019
@consp1racy
Copy link
Owner

Released in 3.0.0 on Maven Central.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-android A bug in Android. subject-ringtone Issues targeting ringtone resolution and playback.
Projects
None yet
Development

No branches or pull requests

2 participants