浅析Android情景模式流程

此篇是基于MTK平台Android6.0的.情景模式分析,情景模式就是通常手机里面的”标准””静音””会议””户外”这几种模式,这几种模式的区别就在于音量,震动,静音,所以可以说情景模式就是建立在音量改变的基础上的.所以下面就主要的分析情景模式里面的比较重要的两个方面,一是铃声的设置问题,二是音量调节分析,情景模式只是一种覆盖而已,主要还是基于Android设置里面的铃声设置,音量调节,具体还会牵扯到很多地方,这里只是大致介绍下流程,其他还有待继续研究.
(一)铃声设置
手机里面的铃声资源主要分为music,ringtone,alarm,podcast,notification这几类,系统刚启动的时候会去扫描手机里面的多媒体文件,并把这些文件放入数据库中,扫描部分的代码在
frameworks\base\media\java\android\media\MediaScanner.java中
public Uri doScanFile(String path, String mimeType, long lastModified,
long fileSize, boolean isDirectory, boolean scanAlways, boolean noMedia) {
Uri result = null;
// long t1 = System.currentTimeMillis();
try {FileEntry entry = beginFile(path, mimeType, lastModified,
fileSize, isDirectory, noMedia);
// if this file was just inserted via mtp, set the rowid to zero
// (even though it already exists in the database), to trigger
// the correct code path for updating its entry
if (mMtpObjectHandle != 0) {
entry.mRowId = 0;
}
// rescan for metadata if file was modified since last scan
if (entry != null && (entry.mLastModifiedChanged || scanAlways)) {
if (noMedia) {
result = endFile(entry, false, false, false, false, false);
} else {
String lowpath = path.toLowerCase(Locale.ROOT);
boolean ringtones = (lowpath.indexOf(RINGTONES_DIR) > 0);
boolean notifications = (lowpath.indexOf(NOTIFICATIONS_DIR) > 0);
boolean alarms = (lowpath.indexOf(ALARMS_DIR) > 0);
boolean podcasts = (lowpath.indexOf(PODCAST_DIR) > 0);
boolean music = (lowpath.indexOf(MUSIC_DIR) > 0) ||
(!ringtones && !notifications && !alarms && !podcasts);
boolean isaudio = MediaFile.isAudioFileType(mFileType);
boolean isvideo = MediaFile.isVideoFileType(mFileType);
boolean isimage = MediaFile.isImageFileType(mFileType);
/**
* M: TODO google use new method to generate path, we need test it later.
* because fork process can access external storage
*/
if (isaudio || isvideo || isimage) {
path = Environment.maybeTranslateEmulatedPathToInternal(new File(path))
.getAbsolutePath();
}
// we only extract metadata for audio and video files
if (isaudio || isvideo) {
processFile(path, mimeType, this);
}
if (isimage) {
/// M: Decodes OMA DRM 1.0 FL image’s width and height(ALPS00335107)
if (IS_SUPPORT_DRM && lowpath.endsWith(“.dcf”)) {
processDcfImageFile(path);
} else {
processImageFile(path);
}
}
result = endFile(entry, ringtones, notifications, alarms, music, podcasts);
}
}
} catch (RemoteException e) {
Log.e(TAG, “RemoteException in MediaScanner.scanFile()”, e);
}
// long t2 = System.currentTimeMillis();
// Log.v(TAG, “scanFile: ” + path + ” took ” + (t2-t1));
return result;
}

private Uri endFile(FileEntry entry, boolean ringtones, boolean notifications,
boolean alarms, boolean music, boolean podcasts){
….. …… ….
if (MediaFile.isAudioFileType(mFileType) && (rowId == 0 || mMtpObjectHandle != 0)) {
// Only set these for new entries. For existing entries, they
// may have been modified later, and we want to keep the current
// values so that custom ringtones still show up in the ringtone
// picker.
values.put(Audio.Media.IS_RINGTONE, ringtones);
values.put(Audio.Media.IS_NOTIFICATION, notifications);
values.put(Audio.Media.IS_ALARM, alarms);
values.put(Audio.Media.IS_MUSIC, music);
values.put(Audio.Media.IS_PODCAST, podcasts);
}
最终扫描进数据库中,数据库的位置在/data/data/com.android.providers.media/databases目录下,里面有SD卡和内存的数据库,现在截内存图如下:这里写图片描述
这四个字段同时有且只有一个字段为1,也就是对于一个多媒体文件只能是这四种中的一种,默认为0,如果是某种类型,则android系统默认置为1,所以当要判断是那种类型的媒体资源时只要判断相应字段值哪个是1就可以了.
以上这只是系统刚启动时将媒体文件扫描进数据库中,库里的数据将以contentProvider的形式对外提供服务.接下来就是设置里面的那些铃声的加载问题了.
当点击”手机铃声”或者”通知铃声”或 “闹钟

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值