SettingsProvider資料儲存位置
老早之前SettingProvider資料儲存的位置在手機目錄/data/data/com.android.providers.settings/databases下
不過目前的Android版本雖然也有這個目錄,其中卻沒有對應的檔案在,本文是看下當前的資料到底儲存在哪裡。
程式碼在在/home/lgy/code/mtk6797/frameworks/base/packages/SettingsProvider
插入流程分析
從插入程式碼為線索分析:
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
- public Uri insert(Uri uri, ContentValues values) {
- ...
- switch (table) {
- ...
- case TABLE_SYSTEM: {
- if (insertSystemSetting(name, value, UserHandle.getCallingUserId())) {
- return Uri.withAppendedPath(Settings.System.CONTENT_URI, name);
- }
- } break;
- ...
- }
- private boolean insertSystemSetting(String name, String value, int requestingUserId) {
- ...
- return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT);
- }
- private boolean mutateSystemSetting(String name, String value, int runAsUserId,
- int operation) {
- ...
- case MUTATION_OPERATION_INSERT: {
- validateSystemSettingValue(name, value);
- return mSettingsRegistry
- .insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM,
- owningUserId, name, value, getCallingPackage());
- }
- ...
- }
- public boolean insertSettingLocked(int type, int userId, String name, String value,
- ...
- final boolean success = settingsState.insertSettingLocked(name, value, packageName);
- ...
- }
SettingsState是另一個檔案
- public boolean insertSettingLocked(String name, String value, String packageName) {
- ...
- updateMemoryUsagePerPackageLocked(packageName, oldValue, value);
- scheduleWriteIfNeededLocked();
- ...
- }
- private void scheduleWriteIfNeededLocked() {
- if (!mDirty) {
- mDirty = true;
- writeStateAsyncLocked();
- }
- }
- private void writeStateAsyncLocked() {
- final long currentTimeMillis = SystemClock.uptimeMillis();
- if (mWriteScheduled) {
- mHandler.removeMessages(MyHandler.MSG_PERSIST_SETTINGS);
- // If enough time passed, write without holding off anymore.
- final long timeSinceLastNotWrittenMutationMillis = currentTimeMillis
- - mLastNotWrittenMutationTimeMillis;
- if (timeSinceLastNotWrittenMutationMillis >= MAX_WRITE_SETTINGS_DELAY_MILLIS) {
- mHandler.obtainMessage(MyHandler.MSG_PERSIST_SETTINGS).sendToTarget();
- return;
- }
- // Hold off a bit more as settings are frequently changing.
- final long maxDelayMillis = Math.max(mLastNotWrittenMutationTimeMillis
- + MAX_WRITE_SETTINGS_DELAY_MILLIS - currentTimeMillis, 0);
- final long writeDelayMillis = Math.min(WRITE_SETTINGS_DELAY_MILLIS, maxDelayMillis);
- Message message = mHandler.obtainMessage(MyHandler.MSG_PERSIST_SETTINGS);
- mHandler.sendMessageDelayed(message, writeDelayMillis);
- }
- ...
- }
- private void doWriteState() {
- ...
- AtomicFile destination = new AtomicFile(mStatePersistFile);
- ...
- FileOutputStream out = null;
- try {
- out = destination.startWrite();
- XmlSerializer serializer = Xml.newSerializer();
- serializer.setOutput(out, StandardCharsets.UTF_8.name());
- serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
- serializer.startDocument(null, true);
- serializer.startTag(null, TAG_SETTINGS);
- serializer.attribute(null, ATTR_VERSION, String.valueOf(version));
- final int settingCount = settings.size();
- for (int i = 0; i < settingCount; i++) {
- Setting setting = settings.valueAt(i);
- writeSingleSetting(mVersion, serializer, setting.getId(), setting.getName(),
- setting.getValue(), setting.getPackageName());
- if (DEBUG_PERSISTENCE) {
- Slog.i(LOG_TAG, "[PERSISTED]" + setting.getName() + "=" + setting.getValue());
- }
- }
- serializer.endTag(null, TAG_SETTINGS);
- serializer.endDocument();
- destination.finishWrite(out);
- ...
- }
檔案地址確認
SettingsState中的成員
- private final File mStatePersistFile;
在SettingsProvider中
- private void ensureSettingsStateLocked(int key) {
- if (mSettingsStates.get(key) == null) {
- final int maxBytesPerPackage = getMaxBytesPerPackageForType(getTypeFromKey(key));
- SettingsState settingsState = new SettingsState(mLock, getSettingsFile(key), key,
- maxBytesPerPackage);
- mSettingsStates.put(key, settingsState);
- }
- }
- private File getSettingsFile(int key) {
- if (isGlobalSettingsKey(key)) {
- final int userId = getUserIdFromKey(key);
- return new File(Environment.getUserSystemDirectory(userId),
- SETTINGS_FILE_GLOBAL);
- } else if (isSystemSettingsKey(key)) {
- final int userId = getUserIdFromKey(key);
- return new File(Environment.getUserSystemDirectory(userId),
- SETTINGS_FILE_SYSTEM);
- } else if (isSecureSettingsKey(key)) {
- final int userId = getUserIdFromKey(key);
- return new File(Environment.getUserSystemDirectory(userId),
- SETTINGS_FILE_SECURE);
- } else {
- throw new IllegalArgumentException("Invalid settings key:" + key);
- }
- }
frameworks/base/core/java/android/os/Environment.java
- public static File getUserSystemDirectory(int userId) {
- return new File(new File(getSystemSecureDirectory(), "users"), Integer.toString(userId));
- }
- public static File getSystemSecureDirectory() {
- if (isEncryptedFilesystemEnabled()) { //加密檔案系統分支,預設是關閉的
- return new File(SECURE_DATA_DIRECTORY, "system");
- } else {
- return new File(DATA_DIRECTORY, "system");
- }
- }
- private static final File DATA_DIRECTORY
- = getDirectory("ANDROID_DATA", "/data");
獲取到DATA_DIRECTORY後,後續還要新增"/ " + "system" + "/" + "users" + "/" + userId的值
例如我測試的手機上是/data/system/users/0,該目錄的settings_global.xml,settings_secure.xml和settings_system.xml三個xml檔案就是SettingsProvider中的資料檔案。
相關文章
- Redis資料儲存位置匯出資料Redis
- gitlab資料庫儲存位置Gitlab資料庫
- 修改MySQL資料庫儲存位置datadirMySql資料庫
- 本地儲存VS雲端儲存:區別不只是資料存放位置
- 修改docker的預設儲存位置及映象儲存位置Docker
- 微信資料夾儲存在什麼位置?如何修改儲存路徑
- 資料儲存--檔案儲存
- 資料儲存位置記憶體圖及一個題目記憶體
- [MySQL]為什麼非聚簇索引不儲存資料位置MySql索引
- Java五種儲存位置Java
- Podman修改 image儲存位置
- 資料儲存
- 資料儲存(1):從資料儲存看人類文明-資料儲存器發展歷程
- win10桌面儲存位置怎麼修改_win10修改桌面儲存位置教程Win10
- 資料儲存:CoreData
- iOS 資料儲存iOS
- IOS資料儲存iOS
- 智慧合約語言 Solidity 教程系列4 - 資料儲存位置分析Solid
- 修改docker映象儲存位置的方法Docker
- RAC變更ASMSPFILE儲存位置(轉)ASM
- SAPI訓練檔案儲存位置API
- store下載檔案儲存位置
- wsl遷移儲存位置(轉載)
- win10中怎麼改變桌面資料夾儲存位置_win10移動更改桌面資料夾儲存路徑教程Win10
- Flutter持久化儲存之資料庫儲存Flutter持久化資料庫
- 資料儲存--面向列的儲存設計
- 資料儲存(歸檔解檔,沙河儲存)
- 聚焦資料時代新儲存需求,浪潮儲存的新儲存之道
- 資料儲存-領存高速海量資料記錄儲存模組產品介紹
- SRAM資料儲存原理
- TiDB資料儲存TiDB
- java 資料儲存方式Java
- Hive之 資料儲存Hive
- 列式儲存資料庫資料庫
- k8s之資料儲存-配置儲存K8S
- IOS資料儲存之檔案沙盒儲存iOS
- 資料成本:雲端儲存成本高嗎如何節省資料儲存成本
- Git儲存內容的位置與方式Git