Make conversation notification sound configurable - #305
thestinger merged 1 commit into
Conversation
36c4e7d to
6ffd807
Compare
437699b to
9655bc9
Compare
| public static void onMessageReceived(final String conversationId, | ||
| @Nullable final ParticipantData sender, @Nullable final MessageData message) { | ||
| final Context context = Factory.get().getApplicationContext(); | ||
| if (DataModel.get().isNewMessageObservable(conversationId)) { | ||
| InConversationSound.playIfEnabled(conversationId); | ||
| } |
There was a problem hiding this comment.
BugleActionToasts#onMessageReceived is called inside of a database transaction (https://github.com/GrapheneOS/Messaging/blob/main/src/com/android/messaging/datamodel/action/ReceiveSmsMessageAction.java#L137-L155), so InConversationSound.playIfEnabled(conversationId); is being called inside of one
| val ringtone = RingtoneUtil.getNotificationRingtoneUri(conversationId, null) | ||
| ?.let { RingtoneManager.getRingtone(context, it) } | ||
| ?: return |
There was a problem hiding this comment.
This can block inside of a Messaging app database transaction waiting for mediaserver to finish: https://github.com/GrapheneOS/platform_frameworks_av/blob/7a46fb37eae0e57496e4242007449ca56c957ce7/media/libmedia/mediaplayer.cpp#L305-L326
RingtoneManager.getRingtone(...)
-> Ringtone.createLocalMediaPlayer()
-> MediaPlayer.prepare() (documentation for this says "blocks until MediaPlayer is ready for playback")
-> JNI native MediaPlayer::prepare()
-> Binder: service-side player.prepareAsync()
-> mSignal.wait(mLock)
| ringtone.audioAttributes = AudioAttributes.Builder() | ||
| .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) | ||
| .setUsage(AudioAttributes.USAGE_NOTIFICATION) | ||
| .build() |
There was a problem hiding this comment.
RingtoneManager.getRingtone(context, uri) creates a local MediaPlayer and synchronously calls MediaPlayer.prepare()
Although this looks like a simple variable reassignment in Kotlin, doing this ringtone.audioAttributes recreates/prepares that MediaPlayer again: https://github.com/GrapheneOS/platform_frameworks_base/blob/17/media/java/android/media/Ringtone.java#L161-L168
| ringtone.isLooping = false | ||
|
|
||
| playing?.stop() | ||
| playing = ringtone | ||
| ringtone.play() |
There was a problem hiding this comment.
This drops the 5 seconds limit from the old code in BugleNotifications:
// Stop the sound after five seconds to handle continuous ringtones
ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() {
@Override
public void run() {
player.stop();
}
}, 5000);9655bc9 to
ec09b2c
Compare
Closes #298