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

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

一。我们先来看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文件不存在。

--- 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  

解决

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. *#06#等关键码判断文件 SpecialCharSequenceMgr.java 2.音效 Control...
    帅气的外表之下阅读 4,047评论 1 1
  • Tcp/IP通信也是不安全的,在传输的时候也可能出现漏洞 查看正在运行的进程 adb shell ps -A |g...
    远远飘着云阅读 4,609评论 0 0
  • 如果爱情是一场你追我赶的旅程 ,那么先付出的人就是注定的失败者!先动心的人伤的最惨。连爱都没说出口的人简直就是跟...
    葁喜宝阅读 436评论 0 0
  • 星期一 晴 每日一我 7点半起床,买芭比点的米浆,鸡蛋,菜包当早饭。 中午去上尊巴,午饭吃西兰花,炖鸡蛋,米饭。 ...
    sophietyl阅读 92评论 0 0