mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1196358 - update volume setting to database when the volume changing. r=sotaro.
This commit is contained in:
parent
83e2ff143d
commit
08639cbadb
@ -96,6 +96,10 @@ var tests = [
|
||||
ok(true, "JS object wrapped into subject");
|
||||
subject = subject.wrappedJSObject;
|
||||
}
|
||||
if (subject["key"] != TEST_OBSERVER_KEY) {
|
||||
return;
|
||||
}
|
||||
|
||||
function checkProp(name, type, value) {
|
||||
ok(name in subject, "subject." + name + " is present");
|
||||
is(typeof subject[name], type, "subject." + name + " is " + type);
|
||||
|
@ -128,6 +128,23 @@ protected:
|
||||
nsCOMPtr<nsIRunnable> mRunnable;
|
||||
};
|
||||
|
||||
nsCOMPtr<nsISettingsServiceLock>
|
||||
GetSettingServiceLock()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISettingsService> service = do_GetService(SETTINGS_SERVICE, &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISettingsServiceLock> lock;
|
||||
rv = service->CreateLock(nullptr, getter_AddRefs(lock));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
return lock.forget();
|
||||
}
|
||||
|
||||
class AudioProfileData final
|
||||
{
|
||||
public:
|
||||
@ -499,6 +516,12 @@ AudioManager::Observe(nsISupports* aSubject,
|
||||
for (uint32_t idx = 0; idx < VOLUME_TOTAL_NUMBER; ++idx) {
|
||||
if (setting.mKey.EqualsASCII(gVolumeData[idx].mChannelName)) {
|
||||
SetVolumeByCategory(gVolumeData[idx].mCategory, volIndex);
|
||||
nsCOMPtr<nsISettingsServiceLock> lock = GetSettingServiceLock();
|
||||
UpdateVolumeSettingToDatabase(lock.get(),
|
||||
AppendProfileToVolumeSetting(
|
||||
gVolumeData[idx].mChannelName,
|
||||
mPresentProfile).get(),
|
||||
volIndex);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
@ -663,9 +686,6 @@ AudioManager::~AudioManager() {
|
||||
if (NS_FAILED(obs->RemoveObserver(this, AUDIO_CHANNEL_PROCESS_CHANGED))) {
|
||||
NS_WARNING("Failed to remove audio-channel-process-changed!");
|
||||
}
|
||||
|
||||
// Store the present volume setting to setting database.
|
||||
SendVolumeChangeNotification(FindAudioProfileData(mPresentProfile));
|
||||
}
|
||||
|
||||
static StaticRefPtr<AudioManager> sAudioManager;
|
||||
@ -1142,34 +1162,34 @@ AudioManager::InitProfileVolumeFailed(const char* aError)
|
||||
NS_WARNING(aError);
|
||||
}
|
||||
|
||||
void
|
||||
AudioManager::UpdateVolumeSettingToDatabase(nsISettingsServiceLock* aLock,
|
||||
const char* aTopic,
|
||||
uint32_t aVolIndex)
|
||||
{
|
||||
MOZ_ASSERT(aLock);
|
||||
|
||||
mozilla::AutoSafeJSContext cx;
|
||||
JS::Rooted<JS::Value> value(cx);
|
||||
value.setInt32(aVolIndex);
|
||||
aLock->Set(aTopic, value, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
AudioManager::SendVolumeChangeNotification(AudioProfileData* aProfileData)
|
||||
{
|
||||
MOZ_ASSERT(aProfileData);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISettingsService> service = do_GetService(SETTINGS_SERVICE, &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISettingsServiceLock> lock;
|
||||
rv = service->CreateLock(nullptr, getter_AddRefs(lock));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send events to update the Gaia volume
|
||||
mozilla::AutoSafeJSContext cx;
|
||||
JS::Rooted<JS::Value> value(cx);
|
||||
// Change the value of the current volume setting, so that the Gaia can get
|
||||
// correct volume values and update the volume UI. In addition, for reducing
|
||||
// the code dependency, Gaia doesn't need to know the current profile, it
|
||||
// only need to care about different volume categories.
|
||||
nsCOMPtr<nsISettingsServiceLock> lock = GetSettingServiceLock();
|
||||
for (uint32_t idx = 0; idx < VOLUME_TOTAL_NUMBER; ++idx) {
|
||||
value.setInt32(aProfileData->mVolumeTable[gVolumeData[idx].mCategory]);
|
||||
// For reducing the code dependency, Gaia doesn't need to know the current
|
||||
// profile, it only need to care about different volume categories.
|
||||
// However, we need to send the setting volume to the permanent database,
|
||||
// so that we can store the volume setting even if the phone reboots.
|
||||
lock->Set(gVolumeData[idx].mChannelName, value, nullptr, nullptr);
|
||||
lock->Set(AppendProfileToVolumeSetting(gVolumeData[idx].mChannelName,
|
||||
mPresentProfile).get(), value, nullptr, nullptr);
|
||||
uint32_t volSetting = gVolumeData[idx].mCategory;
|
||||
UpdateVolumeSettingToDatabase(lock.get(),
|
||||
gVolumeData[idx].mChannelName,
|
||||
aProfileData->mVolumeTable[volSetting]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
{0x89, 0x10, 0xf9, 0x3c, 0x55, 0xe6, 0x62, 0xec}}
|
||||
#define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1"
|
||||
|
||||
class nsISettingsServiceLock;
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal {
|
||||
class SwitchEvent;
|
||||
@ -167,8 +169,11 @@ private:
|
||||
nsAutoCString AppendProfileToVolumeSetting(const char* aName,
|
||||
AudioOutputProfiles aProfile);
|
||||
|
||||
// Init volume from the settings database.
|
||||
// We store the volume setting in the database, these are related functions.
|
||||
void InitVolumeFromDatabase();
|
||||
void UpdateVolumeSettingToDatabase(nsISettingsServiceLock* aLock,
|
||||
const char* aTopic,
|
||||
uint32_t aVolIndex);
|
||||
|
||||
// Promise functions.
|
||||
void InitProfileVolumeSucceeded();
|
||||
|
Loading…
Reference in New Issue
Block a user