一。我们先来看Settings代码
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的内部类。
二。查看framework中的SeekBarVolumizer
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的记录。
三。通过log分析
查到这里代码暂时不好查了。
这时我们来看下滑动闹铃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呢?
四。分析build.prop
我们再到设备上 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
完美解决。