[android] check if ringtone picker is available before launching

Also refuse file:// Uri as they cause a FileUriExposedException as in #1485
This commit is contained in:
Torsten Grote
2019-11-05 12:03:00 -03:00
parent 383367f0c8
commit 533e01e881

View File

@@ -511,7 +511,12 @@ public class SettingsFragment extends PreferenceFragmentCompat
else uri = Uri.parse(ringtoneUri);
i.putExtra(EXTRA_RINGTONE_EXISTING_URI, uri);
}
startActivityForResult(i, REQUEST_RINGTONE);
if (i.resolveActivity(requireActivity().getPackageManager()) != null) {
startActivityForResult(i, REQUEST_RINGTONE);
} else {
Toast.makeText(getContext(), R.string.cannot_load_ringtone,
LENGTH_SHORT).show();
}
return true;
}
@@ -646,7 +651,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
} else {
// The user chose a ringtone other than the default
Ringtone r = RingtoneManager.getRingtone(getContext(), uri);
if (r == null) {
if (r == null || "file".equals(uri.getScheme())) {
Toast.makeText(getContext(), R.string.cannot_load_ringtone,
LENGTH_SHORT).show();
} else {