Skip to content

Make conversation notification sound configurable - #305

Merged
thestinger merged 1 commit into
GrapheneOS:mainfrom
RankoR-GOS:fix-in-conversation-notification-sound
Sep 18, 2026
Merged

thestinger merged 1 commit into
GrapheneOS:mainfrom
RankoR-GOS:fix-in-conversation-notification-sound

Conversation

@RankoR

@RankoR RankoR commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Closes #298

@RankoR
RankoR force-pushed the fix-in-conversation-notification-sound branch from 36c4e7d to 6ffd807 Compare September 13, 2026 20:29
@RankoR
RankoR requested a review from m4pl September 13, 2026 20:30
@RankoR
RankoR force-pushed the fix-in-conversation-notification-sound branch 2 times, most recently from 437699b to 9655bc9 Compare September 13, 2026 20:59
Comment on lines 99 to +104
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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +32 to +34
val ringtone = RingtoneUtil.getNotificationRingtoneUri(conversationId, null)
?.let { RingtoneManager.getRingtone(context, it) }
?: return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines +36 to +39
ringtone.audioAttributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +41 to +45
ringtone.isLooping = false

playing?.stop()
playing = ringtone
ringtone.play()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Comment thread src/com/android/messaging/util/InConversationSound.kt
@RankoR
RankoR force-pushed the fix-in-conversation-notification-sound branch from 9655bc9 to ec09b2c Compare September 17, 2026 17:02
@RankoR
RankoR requested a review from inthewaves September 17, 2026 19:59
@thestinger
thestinger merged commit ed5d74c into GrapheneOS:main Sep 18, 2026
7 checks passed
@RankoR
RankoR deleted the fix-in-conversation-notification-sound branch September 18, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove notification sound in chat screen

3 participants