在Android L版本前,偏好设置,比如用什么打开图片,默认浏览器的设置,这些信息都是保存在packages.xml中了
但是L以及M上,发生了变化。在packages.xml中找不到这些配置了。
这里从源码中去进行查看。
首先在设置图片的默认打开方式时抓取log
05-04 07:47:29.179:I/BufferQueueProducer(449): [android/com.android.internal.app.ResolverActivity](this:0x7faa9f0000,id:108,api:2,p:14842,c:449)queueBuffer: fps=2.29 dur=21386.68 max=20584.78 min=13.74
05-04 07:47:29.180: V/SettingsProvider(997): call(system:sound_effects_enabled)for 0
05-04 07:47:29.180: D/SettingsProvider(997): lookupValue table system cachecontains Key sound_effects_enabled , value = Bundle[
{value=0}
根据Adding preferred activity 发现
调用到了PackageManagerService.java里的addPreferredActivityInternal方法
private void addPreferredActivityInternal
-> scheduleWritePackageRestrictionsLocked(userId);
voidscheduleWritePackageRestrictionsLocked(int userId) {
if (!sUserManager.exists(userId))return;
mDirtyUsers.add(userId);
if(!mHandler.hasMessages(WRITE_PACKAGE_RESTRICTIONS)) {
mHandler.sendEmptyMessageDelayed(WRITE_PACKAGE_RESTRICTIONS,WRITE_SETTINGS_DELAY);
}
}
查找WRITE_PACKAGE_RESTRICTIONS
->
caseWRITE_PACKAGE_RESTRICTIONS: {
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
synchronized (mPackages) {
removeMessages(WRITE_PACKAGE_RESTRICTIONS);
for (int userId :mDirtyUsers) {
mSettings.writePackageRestrictionsLPr(userId);
}
mDirtyUsers.clear();
}
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
} break;
./frameworks/base/services/core/java/com/android/server/pm/Settings.java
-> classSettings {
-> private static final String TAG ="PackageSettings";
void writePackageRestrictionsLPr(int userId)
File userPackagesStateFile =getUserPackagesStateFile(userId);
File backupFile =getUserPackagesStateBackupFile(userId);
//
Log.d(TAG,"=====userPackagesStateFile=" + userPackagesStateFile.getAbsolutePath());
Log.d(TAG,"=====backupFile=" + backupFile.getAbsolutePath());
log
01-01 15:12:28.530: I/PackageManagerService(1064):Adding preferred activity com.google.android.apps.photos/.pager.HostPhotoPagerActivityfor user 0:
01-01 15:12:28.530:I/PackageManagerService(1064): Action:"android.intent.action.VIEW"
01-01 15:12:28.530:I/PackageManagerService(1064): Category: "android.intent.category.DEFAULT"
01-01 15:12:28.530:I/PackageManagerService(1064): Type:"image/jpeg"
01-01 15:12:28.530:I/PackageManagerService(1064): AutoVerify=false
01-01 15:12:28.535: I/PackageSettings(1064):Writing package restrictions for user=0
01-01 15:12:28.535: D/PackageSettings(1064): =====userPackagesStateFile=/data/system/users/0/package-restrictions.xml
01-01 15:12:28.535: D/PackageSettings(1064):=====backupFile=/data/system/users/0/package-restrictions-backup.xml这样就找到了写设置的文件 /data/system/users/0/package-restrictions.xml
./frameworks/base/services/core/java/com/android/server/pm/Settings.java里有其读写的细节