summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/qdroidutils.cpp94
-rw-r--r--src/utils/qdroidutils.h20
-rw-r--r--src/utils/utils.pro2
3 files changed, 115 insertions, 1 deletions
diff --git a/src/utils/qdroidutils.cpp b/src/utils/qdroidutils.cpp
index 4247826..31ed09c 100644
--- a/src/utils/qdroidutils.cpp
+++ b/src/utils/qdroidutils.cpp
@@ -4,6 +4,7 @@
#ifdef Q_OS_ANDROID_NO_SDK
#include <cutils/android_reboot.h>
#include <hardware/lights.h>
+#include <media/AudioSystem.h>
#else
#include <sys/reboot.h>
#include <QNetworkInterface>
@@ -44,6 +45,99 @@ void QDroidUtils::powerOffSystem()
}
/*!
+ * Sets the master volume to \a volume.
+ * The volume can range from 0 to 100 and is linear.
+ * Changing the master volume will affect all audio streams.
+ *
+ * \sa setStreamVolume()
+ * \sa setMasterMute()
+ */
+void QDroidUtils::setMasterVolume(int volume)
+{
+#ifdef Q_OS_ANDROID_NO_SDK
+ volume = qBound(0, volume, 100);
+ android::AudioSystem::setMasterVolume(android::AudioSystem::linearToLog(volume));
+#endif
+}
+
+/*!
+ * Sets the master mute to \a mute. Setting it to true will disable all
+ * sounds on the device.
+ *
+ * \sa setMasterVolume()
+ * \sa setStreamMute()
+ */
+void QDroidUtils::setMasterMute(bool mute)
+{
+#ifdef Q_OS_ANDROID_NO_SDK
+ android::AudioSystem::setMasterMute(mute);
+#endif
+}
+
+/*!
+ \enum QDroidUtils::AudioStreamType
+ \value DefaultAudioStream
+ The default audio stream
+
+ \value VoiceCallAudioStream
+ The audio stream for phone calls
+
+ \value SystemAudioStream
+ The audio stream for system sounds
+
+ \value RingAudioStream
+ The audio stream for the phone ring
+
+ \value AlarmAudioStream
+ The audio stream for alarms
+
+ \value NotificationAudioStream
+ The audio stream for notifications
+
+ \value BluetoothAudioStream
+ The audio stream for audio transmitted over bluetooth
+
+ \value EnforcedAudibleAudioStream
+ Sounds that cannot be muted by user and must be routed to speaker
+
+ \value DTMFAudioStream
+ The audio stream for DTMF Tones
+
+ \value TTSAudioStream
+ The audio stream for text-to-speech
+*/
+
+/*!
+ * Sets the volume for a specific audio \a stream type to \a volume.
+ * The volume can range from 0 to 100 and is linear.
+ * All streams of the specified type will be affected.
+ *
+ * \sa setMasterVolume()
+ * \sa setStreamMute()
+ */
+void QDroidUtils::setStreamVolume(AudioStreamType streamType, int volume)
+{
+#ifdef Q_OS_ANDROID_NO_SDK
+ volume = qBound(0, volume, 100);
+ android::AudioSystem::setStreamVolume(audio_stream_type_t(streamType),
+ android::AudioSystem::linearToLog(volume), 0);
+#endif
+}
+
+/*!
+ * Mutes all audio \a streams of type \a streamType.
+ *
+ * \sa setStreamVolume()
+ * \sa setMasterMute()
+ */
+void QDroidUtils::setStreamMute(AudioStreamType streamType, bool mute)
+{
+#ifdef Q_OS_ANDROID_NO_SDK
+ android::AudioSystem::setStreamMute(audio_stream_type_t(streamType), mute);
+#endif
+}
+
+/*!
* Sets the display brightness (i.e. the intensity of the backlight)
* to \a value. A value of 255 requests maximum brightness, while 0 requests
* minimum (typically, the backlight turned off).
diff --git a/src/utils/qdroidutils.h b/src/utils/qdroidutils.h
index 52efc4a..7f37f70 100644
--- a/src/utils/qdroidutils.h
+++ b/src/utils/qdroidutils.h
@@ -6,7 +6,22 @@
class Q_DECL_EXPORT QDroidUtils : public QObject
{
Q_OBJECT
+ Q_ENUMS(AudioStreamType)
public:
+ enum AudioStreamType {
+ DefaultAudioStream = -1,
+ VoiceCallAudioStream = 0,
+ SystemAudioStream = 1,
+ RingAudioStream = 2,
+ MusicAudioStream = 3,
+ AlarmAudioStream = 4,
+ NotificationAudioStream = 5,
+ BluetoothAudioStream = 6,
+ EnforcedAudibleAudioStream = 7,
+ DTMFAudioStream = 8,
+ TTSAudioStream = 9
+ };
+
QDroidUtils(QObject* parent = 0) : QObject(parent)
{
}
@@ -21,6 +36,11 @@ public Q_SLOTS:
void rebootSystem();
void powerOffSystem();
+ void setMasterVolume(int volume);
+ void setMasterMute(bool mute);
+ void setStreamVolume(AudioStreamType stream, int volume);
+ void setStreamMute(AudioStreamType stream, bool mute);
+
bool setDisplayBrightness(quint8 value);
QString getIPAddress();
diff --git a/src/utils/utils.pro b/src/utils/utils.pro
index 63ddf42..5711337 100644
--- a/src/utils/utils.pro
+++ b/src/utils/utils.pro
@@ -11,7 +11,7 @@ QT = core network
MODULE = droidutils
load(qt_module)
-android: LIBS += -lhardware -lcutils
+android: LIBS += -lmedia -lhardware -lcutils
HEADERS += \
$$PWD/qdroidutils.h