问题描述
Android13 上进行SD卡格式化,格式化后显示的SD卡容量为0,退出重新进入,显示正常。
源码分析
首先在Settings
->Storage
页面,切换到SD card,页面将显示SD card的存储信息
代码位于packages/apps/Settings/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
java
复制代码
@Override public void onResume() { super.onResume(); if (mIsLoadedFromCache) { mIsLoadedFromCache = false; } else { mStorageEntries.clear(); mStorageEntries.addAll( StorageUtils.getAllStorageEntries(getContext(), mStorageManager)); Log.d("jasonwan", "---refreshUi-09---"); //刷新UI refreshUi(); } mStorageManager.registerListener(mStorageEventListener); } private void refreshUi() { mStorageSelectionController.setStorageEntries(mStorageEntries); mStorageSelectionController.setSelectedStorageEntry(mSelectedStorageEntry); //设置已选择的存储项 mStorageUsageProgressBarController.setSelectedStorageEntry(mSelectedStorageEntry); mOptionMenuController.setSelectedStorageEntry(mSelectedStorageEntry); getActivity().invalidateOptionsMenu(); // To prevent flicker, hides secondary users preference. // onReceivedSizes will set it visible for private storage. setSecondaryUsersVisible(false); if (!mSelectedStorageEntry.isMounted()) { // Set null volume to hide category stats. mPreferenceController.setVolume(null); return; } Log.d("jasonwan", " mStorageCacheHelper.hasCachedSizeInfo()="+mStorageCacheHelper.hasCachedSizeInfo()); Log.d("jasonwan", " mSelectedStorageEntry.isPrivate()="+mSelectedStorageEntry.isPrivate()); //sdcard属于public volume,因此这里的isPrivate()为false if (mStorageCacheHelper.hasCachedSizeInfo() && mSelectedStorageEntry.isPrivate()) { StorageCacheHelper.StorageCache cachedData = mStorageCacheHelper.retrieveCachedSize(); mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); mPreferenceController.setUsedSize(cachedData.totalUsedSize); mPreferenceController.setTotalSize(cachedData.totalSize); Log.d("jasonwan", " totalUsedSize="+cachedData.totalUsedSize+", totalSize="+cachedData.totalSize); } if (mSelectedStorageEntry.isPrivate()) { mStorageInfo = null; mAppsResult = null; // Hide the loading spinner if there is cached data. if (mStorageCacheHelper.hasCachedSizeInfo()) { //TODO(b/220259287): apply cache mechanism to secondary user mPreferenceController.onLoadFinished(mAppsResult, mUserId); } else { maybeSetLoading(isQuotaSupported()); // To prevent flicker, sets null volume to hide category preferences. // onReceivedSizes will setVolume with the volume of selected storage. mPreferenceController.setVolume(null); } // Stats data is only available on private volumes. getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this); getLoaderManager() .restartLoader(VOLUME_SIZE_JOB_ID, Bundle.EMPTY, new VolumeSizeCallbacks()); getLoaderManager().restartLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks()); } else { mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo()); } }
在refreshUi
方法中,会进行容量大小的显示,sdcard因为是public volume,所以isPrivate()
方法为false,sdcard的容量大小计算及显示在mStorageUsageProgressBarController.setSelectedStorageEntry(mSelectedStorageEntry)
中
java
复制代码
/** Set Sto