修改setting中storage部分的总内存显示

2019-12-06  本文已影响0人  梧叶已秋声

setting下的总内存显示的关键使StorageDashboardFragment中的updateBytes中的mStorageInfo.totalBytes参数。这个目前显示的是internal memory的总大小,但是客户需要加上内置sdcard的大小。

//vendor\mediatek\proprietary\packages\xx\xx\src\com\android\settings\deviceinfo\StorageDashboardFragment.java
public class StorageDashboardFragment extends DashboardFragment
    implements LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
    ..........
    private void onReceivedSizes() {
      if (mStorageInfo != null) {
            long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
            mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
      ..........
    }
    ..........
}

修改如下。

   /**
     * 判断SD卡是否可用
     *
     * @return true : 可用<br>false : 不可用
     */
    public static boolean isSDCardEnable() {
        return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
    }

    /**
     * 获取手机外部总空间大小
     *
     * @return 总大小,字节为单位
     */
    static public long getTotalExternalMemorySize() {
        if (isSDCardEnable()) {
            //获取SDCard根目录
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long totalBlocks = stat.getBlockCount();
            return totalBlocks * blockSize;
        } else {
            return -1;
        }
    }
  ..........
    private void onReceivedSizes() {
      if (mStorageInfo != null) {
            long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
            mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes + getTotalExternalMemorySize());
      ..........
    }

由于这个源码中的AndroidManifest.xml已经有了权限申请所以不需要额外添加。

上一篇下一篇

猜你喜欢

热点阅读