Reading ringtone volume using C++

I am re-writing my notification sound code in Battery Buddy, and there is a bug that needs to be fixed. I have a console-only C++ daemon that makes the sound using QSoundEffect, and the issue is that it doesn’t respect the ringtone volume setting, nor slient mode. There seems to be audioRole property in QML Audio and SoundEffect components, but nothing similar for pure C++…

How can I query the ringtone volume and if the device is in silent mode or not? I guess DBus is the answer here, but The Documentation doesn’t really help… com.jolla.ambienced perhaps?

1 Like

Okay… 1) I’m dumb 2) a good night sleep helped.

I decided to dig up the source code of Nemo Notifications, and there is a property hint called sound-file which looks quite promising…

…but it seems that the commit that introduced it is mere four months old, so I bet it’s not in SFOS 3.4. Might explain why the documentation doesn’t mention it, either.

Back to the QSoundEffect drawing board, then.

QMediaPlayer can play sounds and does provide setAudioRole, but it still doesn’t respect the ringtone volume or silent mode. I guess that doesn’t have the required effect, or there’s a bug in the system.

On the other hand, there is QSoundEffect::category() but I haven’t been able to find a list of available categories anywhere…

This task is getting a bit frustrating… Any pointers appreciated.

Does this help you regarding dbus?

method call time=1609072327.656301 sender=:1.9655 -> serial=66 path=/com/nokia/profiled;; member=set_valuestring "general"string "ringing.alert.volume"string "88"method return time=1609072327.660074 sender=:1.4 -> destination=:1.9655 serial=4869 reply_serial=66boolean true
signal time=1609072327.763880 sender=:1.4 -> destination=(null destination) serial=4870path=/com/nokia/profiled;; member=profile_changedboolean falseboolean falsestring "ambience"array [struct {string "ringing.alert.volume"string "88"string “INTEGER 0-100”}]

Thanks, I think that’s exactly what I need!

Now if I only was familiar with DBus… :smiley:

That set me onto the right path! But dang it was hard for me to find out anything remotely resembling documentation! I first finded any files, ended up finding profiled.service systemd system service file, which in turn just starts /usr/bin/profiled (which outputs nothing with ´–help´). Armed with that binary name, I googled my way to its source code using which I was finally able to, uh, nothing. I don’t know DBus…

But then I found this lovely page in Maemo wiki! Using that as a template I was finally able to come up with something useful!

First I have to check the active profile:

$ dbus-send --type=method_call --print-reply /com/nokia/profiled
   string "general"

Then I can query the actual ringtone volume (until the response was silent which automatically means: don’t make a sound):

dbus-send --type=method_call --print-reply /com/nokia/profiled string:"general" string:"ringing.alert.volume"
   string "60"

So there you go. This is how you can query the active profile and get the ringtone volume. Another interesting query was listing the profiles:

$ dbus-send --type=method_call --print-reply /com/nokia/profiled
   array [
      string "ambience"
      string "general"
      string "meeting"
      string "outdoors"
      string "silent"

So far I have been able to set only general and silent. If the volume is not zero, the profile is general. If the Silent top-menu button is activated, or volume slider dragged to zero, the profile is switched to silent without the general volume getting set. So it’s a bit illogical, but at least I got that figured out before I got into actually writing the code for this!

I think I have earned a beer.

1 Like

Very nice finding!

I’d even say, two! :slight_smile:

I was not that desperate and only tried to check the interface with qdbusviewer which only revealed the signal, no methods!?
But thanks to WMO you found it “easily”! :smiley:

1 Like

Do not rely on profile being only general or silent!
When I just checked my profile was “ambience”!
Later when I modified ambience, ring tone level, ambience … it was only general or silent?

I was able to set profile manually to something different, e.g.
bus-send --print-reply /com/nokia/profiled string:meeting

But ad those profiles are not really supported but we have only this crippled ambience thing I would guess you are fine with profile ‘silent’ and any other value and its level.

1 Like

Actually, no meaning should ever be attached to profile names, applications should basically just track values that are currently active.

While it is guaranteed that couple of profiles like “general” and “silent” always exist, in general what profiles are available / what keys profiles contain / what values they have in each profile depends on what kind of configuration files are installed on the device. And the situation can dynamically change if / when such configuration files are installed, removed or upgraded.

But do note that ambience system works by modifying profiles on the fly. IIRC “ambience” profile was/is used for that purpose. Basically this means that in sailfish profiles can no longer be used in the way they were designed to work in maemo/meego devices - except for that “you should not care about profile names” part.

There is also CLI utility profileclient (pkcon install profileclient ; profileclient -h) that can be used for inspecting current state / making and tracking changes. For example running “profileclient -T” in a shell while changing ambiences / adjusting ringing tone volume via volume keys shows what kind of changes happen under the hood.


There is no need to do that - just use empty string as profile name. That is taken to mean the currently active profile.

dbus-send --type=method_call --print-reply /com/nokia/profiled string: string:ringing.alert.volume
method return time=1609832196.658302 sender=:1.3265 -> destination=:1.3277 serial=8 reply_serial=2
   string "60"

There is aso C library API, e.g.

#include <stdio.h>
#include <libprofile.h>

int main(int argc, char **argv)
    printf("%d\n", profile_get_value_as_int(0, "ringing.alert.volume"));
    return 0;

Thanks for the details! I’ll simplify my code when I get back home accordingly.

It actually makes sense that there are no “profiles” per se but the ambience changing over time instead. Using the empty string is a nice way of accessing the current profile too. I’ll test both ways - Dbus and libprofile.h - to learn more, but I’ll keep the DBus method for now. I really need to learn to use it properly… :slight_smile:

1 Like