对于插拔SD卡有声音的问题:SD卡的挂载流程大致如此,MountServie实际上还会通知PackageManagerService,因为这里分析的是SD卡挂载从底层到上层的表现,因此这里暂不分析。简约流程图如下:
上面提示的词:mtk/packages/apps/SystemUpdate/res/values/strings.xml: <string name="sdcard_unmount">SD card is unmounted</string>
/frameworks/base/core/res/res/values-en-rGB/strings.xml: <string name="ext_media_nomedia_notification_title" product="default" msgid="89025
18030404381318">"Removed SD card"</string>
经过分析这个流程的所有模块都没有调用声音的地方。所以就只有根据log找声音播放的位置了
bug所在位置:\frameworks\base\services,
下面的 NotificationManagerService.java
player.playAsync(soundUri, user, looping, audioStreamType);这个是播放声音的地方
1、调用流程是这样的:
在systemui模块中有个StorageNotification.java文件。
@Override
publicvoidonStorageStateChanged(final String path,final String oldState,final String newState) {
mAsyncEventHandler.post(new Runnable() {
@Override
publicvoid run() {
onStorageStateChangedAsync(path, oldState, newState);
}
});
}
-----------------------------------------------------------------
这个函数不断检测存储的状态。然后调用run()里面的onStorageStateChangedAsync函数。根据跟踪代码发现,有很多种情况,这里将最主要的几种
第一种:
else if (newState.equals(Environment.MEDIA_UNMOUNTED))里面有函数
setMediaStorageNotification(path, 0, 0, 0, false, false, false, null);
第二种:
else if (newState.equals(Environment.MEDIA_REMOVED)) {
里面也调用函数:
setMediaStorageNotification(
path,
title,
message,
com.android.internal.R.drawable.stat_notify_sdcard_usb,
true, false, true, null);
第三种:
else if (newState.equals(Environment.MEDIA_BAD_REMOVAL))
里面调用函数:
setMediaStorageNotification(
path,
title,
message,
com.android.internal.R.drawable.stat_sys_warning,
true, true, true, null);
-------------------------------------------------------------------
他们调用setMediaStorageNotification函数中倒数第三个参数是boolean sound,是设置声音的。这个函数又调用:
\frameworks\base\core\java\android\app路径下地NotificationManager.java文件中的notificationManager.notifyAsUser(null, notificationId, mUsbStorageNotification,UserHandle.ALL);
然后再不断的往下调用,最后调用NotificationManagerService.java文件中的
player.playAsync(soundUri, user, looping, audioStreamType);这个是播放声音的地方
所以对于t卡拔出来有声音是因为满足条件newState.equals(Environment.MEDIA_BAD_REMOVAL),最后将声音的哪个参数改写为false就可以去掉声音了。