diff --git a/dom/system/b2g/AudioManager.cpp b/dom/system/b2g/AudioManager.cpp new file mode 100644 index 000000000000..694516119a2f --- /dev/null +++ b/dom/system/b2g/AudioManager.cpp @@ -0,0 +1,130 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is B2G Audio Manager. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Philipp von Weitershausen + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "AudioManager.h" +#include + +using namespace mozilla::dom::telephony; +using namespace android; + +NS_IMPL_ISUPPORTS1(AudioManager, nsIAudioManager) + +NS_IMETHODIMP +AudioManager::GetMicrophoneMuted(bool* aMicrophoneMuted) +{ + if (AudioSystem::isMicrophoneMuted(aMicrophoneMuted)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::SetMicrophoneMuted(bool aMicrophoneMuted) +{ + if (AudioSystem::muteMicrophone(aMicrophoneMuted)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::GetMasterVolume(float* aMasterVolume) +{ + if (AudioSystem::getMasterVolume(aMasterVolume)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::SetMasterVolume(float aMasterVolume) +{ + if (AudioSystem::setMasterVolume(aMasterVolume)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::GetMasterMuted(bool* aMasterMuted) +{ + if (AudioSystem::getMasterMute(aMasterMuted)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::SetMasterMuted(bool aMasterMuted) +{ + if (AudioSystem::setMasterMute(aMasterMuted)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::GetPhoneState(PRInt32* aState) +{ + *aState = mPhoneState; + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::SetPhoneState(PRInt32 aState) +{ + if (AudioSystem::setPhoneState(aState)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::SetForceForUse(PRInt32 aUsage, PRInt32 aForce) +{ + if (AudioSystem::setForceUse((AudioSystem::force_use)aUsage, + (AudioSystem::forced_config)aForce)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +AudioManager::GetForceForUse(PRInt32 aUsage, PRInt32* aForce) { + *aForce = AudioSystem::getForceUse((AudioSystem::force_use)aUsage); + return NS_OK; +} diff --git a/dom/system/b2g/AudioManager.h b/dom/system/b2g/AudioManager.h new file mode 100644 index 000000000000..49d9a29d12f8 --- /dev/null +++ b/dom/system/b2g/AudioManager.h @@ -0,0 +1,72 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is B2G Audio Manager. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Philipp von Weitershausen + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef mozilla_dom_system_b2g_audiomanager_h__ +#define mozilla_dom_system_b2g_audiomanager_h__ + +#include "nsIAudioManager.h" + + +// {b2b51423-502d-4d77-89b3-7786b562b084} +#define NS_AUDIOMANAGER_CID {0x94f6fd70, 0x7615, 0x4af9, \ + {0x89, 0x10, 0xf9, 0x3c, 0x55, 0xe6, 0x62, 0xec}} +#define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1" + +namespace mozilla { +namespace dom { +namespace telephony { + +class AudioManager : public nsIAudioManager +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIAUDIOMANAGER + + AudioManager() : mPhoneState(PHONE_STATE_CURRENT) + { + } + +protected: + PRInt32 mPhoneState; +}; + + +} /* namespace telephony */ +} /* namespace dom */ +} /* namespace mozilla */ + +#endif // mozilla_dom_system_b2g_audiomanager_h__ diff --git a/dom/system/b2g/Makefile.in b/dom/system/b2g/Makefile.in index 8707a6a02404..722115bdca93 100644 --- a/dom/system/b2g/Makefile.in +++ b/dom/system/b2g/Makefile.in @@ -54,7 +54,14 @@ CPPSRCS = \ RadioManager.cpp \ $(NULL) -XPIDLSRCS = nsIRadioWorker.idl +ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) +CPPSRCS += AudioManager.cpp +endif + +XPIDLSRCS = \ + nsIAudioManager.idl \ + nsIRadioWorker.idl \ + $(NULL) LOCAL_INCLUDES = \ -I$(topsrcdir)/dom/base \ diff --git a/dom/system/b2g/nsIAudioManager.idl b/dom/system/b2g/nsIAudioManager.idl new file mode 100644 index 000000000000..6586c9ae2bbc --- /dev/null +++ b/dom/system/b2g/nsIAudioManager.idl @@ -0,0 +1,90 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is B2G Audio Manager. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Philipp von Weitershausen + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +[scriptable, builtinclass, uuid(d2124467-7209-4b2e-a91a-cf3f90681e3c)] +interface nsIAudioManager : nsISupports +{ + /** + * Microphone muted? + */ + attribute boolean microphoneMuted; + + /** + * The master volume. + */ + attribute float masterVolume; + + /** + * Master volume muted? + */ + attribute boolean masterMuted; + + /** + * Set the phone's audio mode. + */ + const long PHONE_STATE_INVALID = -2; + const long PHONE_STATE_CURRENT = -1; + const long PHONE_STATE_NORMAL = 0; + const long PHONE_STATE_RINGTONE = 1; + const long PHONE_STATE_IN_CALL = 2; + const long PHONE_STATE_IN_COMMUNICATION = 3; + + attribute long phoneState; + + /** + * Configure a particular device ("force") to be used for one of the uses + * (communication, media playback, etc.) + */ + const long FORCE_NONE = 0; // the default + const long FORCE_SPEAKER = 1; + const long FORCE_HEADPHONES = 2; + const long FORCE_BT_SCO = 3; + const long FORCE_BT_A2DP = 4; + const long FORCE_WIRED_ACCESSORY = 5; + const long FORCE_BT_CAR_DOCK = 6; + const long FORCE_BT_DESK_DOCK = 7; + + const long USE_COMMUNICATION = 0; + const long USE_MEDIA = 1; + const long USE_RECORD = 2; + const long USE_DOCK = 3; + + void setForceForUse(in long usage, in long force); + long getForceForUse(in long usage); +}; diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 45281cf7b5ee..2e5e09549943 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -131,6 +131,11 @@ using mozilla::dom::indexedDB::IndexedDatabaseManager; #ifdef MOZ_B2G_RIL #include "RadioManager.h" using mozilla::dom::telephony::RadioManager; +#include "nsITelephone.h" +#endif +#ifdef MOZ_WIDGET_GONK +#include "AudioManager.h" +using mozilla::dom::telephony::AudioManager; #endif // Editor stuff @@ -346,7 +351,9 @@ RadioInterfaceConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) } #endif -#ifndef MOZ_WIDGET_GONK +#ifdef MOZ_WIDGET_GONK +NS_GENERIC_FACTORY_CONSTRUCTOR(AudioManager) +#else #if defined(XP_UNIX) || \ defined(_WINDOWS) || \ defined(machintosh) || \ @@ -854,6 +861,9 @@ NS_DEFINE_NAMED_CID(INDEXEDDB_MANAGER_CID); NS_DEFINE_NAMED_CID(TELEPHONYRADIO_CID); NS_DEFINE_NAMED_CID(TELEPHONYRADIOINTERFACE_CID); #endif +#ifdef MOZ_WIDGET_GONK +NS_DEFINE_NAMED_CID(NS_AUDIOMANAGER_CID); +#endif #ifdef ENABLE_EDITOR_API_LOG NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_CID); #else @@ -993,6 +1003,9 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kTELEPHONYRADIO_CID, true, NULL, RadioManagerConstructor }, { &kTELEPHONYRADIOINTERFACE_CID, true, NULL, RadioInterfaceConstructor }, #endif +#ifdef MOZ_WIDGET_GONK + { &kNS_AUDIOMANAGER_CID, true, NULL, AudioManagerConstructor }, +#endif #ifdef ENABLE_EDITOR_API_LOG { &kNS_HTMLEDITOR_CID, false, NULL, nsHTMLEditorLogConstructor }, #else @@ -1126,6 +1139,9 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { TELEPHONYRADIO_CONTRACTID, &kTELEPHONYRADIO_CID }, { TELEPHONYRADIOINTERFACE_CONTRACTID, &kTELEPHONYRADIOINTERFACE_CID }, #endif +#ifdef MOZ_WIDGET_GONK + { NS_AUDIOMANAGER_CONTRACTID, &kNS_AUDIOMANAGER_CID }, +#endif #ifdef ENABLE_EDITOR_API_LOG { "@mozilla.org/editor/htmleditor;1", &kNS_HTMLEDITOR_CID }, #else diff --git a/toolkit/library/Makefile.in b/toolkit/library/Makefile.in index ea7772c42ca4..c285afb49034 100644 --- a/toolkit/library/Makefile.in +++ b/toolkit/library/Makefile.in @@ -422,7 +422,10 @@ OS_LIBS += -lGLESv2 endif ifeq (gonk,$(MOZ_WIDGET_TOOLKIT)) -OS_LIBS += -lui +OS_LIBS += \ + -lui \ + -lmedia \ + $(NULL) endif EXTRA_DEPS += \