小记 cm-11中,“设置-音量中,调节闹钟音量,无声音预览播放”bug fix

rt,cm11中,在设置Settings中,调节音乐或通知音量,都有声音预览,唯独调节闹钟没有。

[b]一。我们先来看Settings代码[/b]

SoundSettings.java是声音设置界面,具体的音量调节界面是RingerVolumePreference.java,但是这个类里没有针对滑动seekbar做任何播放操作,只有预览播放的回调protected void onSampleStarting(SeekBarVolumizer volumizer) {。


在RingerVolumePreference.java的onBindDialogView(View view)绑定方法中,
可以看到不同铃声seekbar的绑定。

for (int i = 0; i < SEEKBAR_ID.length; i++) {
SeekBar seekBar = (SeekBar) view.findViewById(SEEKBAR_ID[i]);
mSeekBars[i] = seekBar;
if (SEEKBAR_TYPE[i] == AudioManager.STREAM_MUSIC) {
mSeekBarVolumizer[i] = new SeekBarVolumizer(getContext(), seekBar,
SEEKBAR_TYPE[i], getMediaVolumeUri(getContext()));
} else {
mSeekBarVolumizer[i] = new SeekBarVolumizer(getContext(), seekBar,
SEEKBAR_TYPE[i]);
}
Uri u = getMediaVolumeUri(getContext());
Log.d("cchen", "uri " + u);
}


但是注意SeekBarVolumizer这个类,从名字上也能看出是单独定义的控件。

经过查找
SeekBarVolumizer是
frameworks/base/core/java/android/preference/VolumePreference.java的内部类。

[b]二。查看framework中的SeekBarVolumizer[/b]


SeekBarVolumizer中
initSeekBar的初始化方法

if (defaultUri == null) {
if (mStreamType == AudioManager.STREAM_RING) {
defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
} else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
} else {
defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
}
}

mRingtone = RingtoneManager.getRingtone(mContext, defaultUri);

if (mRingtone != null) {
mRingtone.setStreamType(mStreamType);
}

可以看到闹铃的seekbar绑定的是Settings.System.DEFAULT_ALARM_ALERT_URI。
但是在SettingsProvider数据里,system这张表中,经过查询,只有38|notification_sound|content://media/internal/audio/media/71

却没有Settings.System.DEFAULT_ALARM_ALERT_URI的记录。


[b]三。通过log分析[/b]

查到这里代码暂时不好查了。
这时我们来看下滑动闹铃seekbar的adb log


D/MediaPlayer( 3081): Couldn't open file on client side, trying server side
E/MediaPlayerService( 2551): Couldn't open fd for content://settings/system/alarm_alert
E/MediaPlayer( 3081): Unable to create media player



可以看待播放器的日志,是setUri时候报了错误。
再往下,可以查到MediaScanner.java中,获取默认铃声的代码


private void setDefaultRingtoneFileNames() {
mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.RINGTONE);
mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.NOTIFICATION_SOUND);
mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.ALARM_ALERT);
}



可以看到是寻找build.prop中的键值对 ro.config.alarm_alert
我们通过adb shell getprop | grep alarm
可以看到ro.config.alarm_alert=Alarm_Classic.ogg,有这一栏。
那为什么SettingsProvider中有notification_sound却没有alarm_alert呢?

[b]四。分析build.prop[/b]

我们再到设备上 adb shell find | grep Alarm_Classic.ogg,发现设备上根本没有这个文件。
system/media/audio/alarms下面也确实没有,那我们已经找到这个问题的root cause了。
即:ro.config.alarm_alert=Alarm_Classic.ogg中的ogg文件不存在。

---------------------------
fix办法:

--- a/target/product/core_base.mk
+++ b/target/product/core_base.mk
@@ -18,7 +18,7 @@

PRODUCT_PROPERTY_OVERRIDES := \
ro.config.notification_sound=OnTheHunt.ogg \
- ro.config.alarm_alert=Alarm_Classic.ogg
+ ro.config.alarm_alert=Alarm_Beep_03.ogg




完美解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值