void updateStorageUsage() {
      // Make sure a callback didn't come at an inopportune time.
      if (mOwner.getActivity() == null) return;
      // Doesn't make sense for stuff that is not an app list.
      if (mApplications == null) return;

      mFreeStorage = 0;
      mAppStorage = 0;
      mTotalStorage = 0;

      if (mFilter == FILTER_APPS_SDCARD) {
        if (mContainerService != null) {
          try {
            final long[] stats =
                mContainerService.getFileSystemStats(
                    Environment.getExternalStorageDirectory().getPath());
            mTotalStorage = stats[0];
            mFreeStorage = stats[1];
          } catch (RemoteException e) {
            Log.w(TAG, "Problem in container service", e);
          }
        }

        if (mApplications != null) {
          final int N = mApplications.getCount();
          for (int i = 0; i < N; i++) {
            ApplicationsState.AppEntry ae = mApplications.getAppEntry(i);
            mAppStorage += ae.externalCodeSize + ae.externalDataSize + ae.externalCacheSize;
          }
        }
      } else {
        if (mContainerService != null) {
          try {
            final long[] stats =
                mContainerService.getFileSystemStats(Environment.getDataDirectory().getPath());
            mTotalStorage = stats[0];
            mFreeStorage = stats[1];
          } catch (RemoteException e) {
            Log.w(TAG, "Problem in container service", e);
          }
        }

        final boolean emulatedStorage = Environment.isExternalStorageEmulated();
        if (mApplications != null) {
          final int N = mApplications.getCount();
          for (int i = 0; i < N; i++) {
            ApplicationsState.AppEntry ae = mApplications.getAppEntry(i);
            mAppStorage += ae.codeSize + ae.dataSize;
            if (emulatedStorage) {
              mAppStorage += ae.externalCodeSize + ae.externalDataSize;
            }
          }
        }
        mFreeStorage += mApplicationsState.sumCacheSizes();
      }

      applyCurrentStorage();
    }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   if (mApplications != null && mApplications.getCount() > position) {
     ApplicationsState.AppEntry entry = mApplications.getAppEntry(position);
     mCurrentPkgName = entry.info.packageName;
     mCurrentUid = entry.info.uid;
     startApplicationDetailsActivity();
   }
 }
  void updateStorageUsage() {
    if (mCurView == VIEW_RUNNING) {
      return;
    }

    long freeStorage = 0;
    long appStorage = 0;
    long totalStorage = 0;
    CharSequence newLabel = null;

    if (mFilterApps == FILTER_APPS_SDCARD) {
      if (mLastShowedInternalStorage) {
        mLastShowedInternalStorage = false;
      }
      newLabel = getActivity().getText(R.string.sd_card_storage);
      mSDCardFileStats.restat(Environment.getExternalStorageDirectory().toString());
      try {
        totalStorage = (long) mSDCardFileStats.getBlockCount() * mSDCardFileStats.getBlockSize();
        freeStorage =
            (long) mSDCardFileStats.getAvailableBlocks() * mSDCardFileStats.getBlockSize();
      } catch (IllegalArgumentException e) {
        // use the old value of mFreeMem
      }
      final int N = mApplicationsAdapter.getCount();
      for (int i = 0; i < N; i++) {
        ApplicationsState.AppEntry ae = mApplicationsAdapter.getAppEntry(i);
        appStorage += ae.externalCodeSize + ae.externalDataSize;
      }
    } else {
      if (!mLastShowedInternalStorage) {
        mLastShowedInternalStorage = true;
      }
      newLabel = getActivity().getText(R.string.internal_storage);
      mDataFileStats.restat("/data");
      try {
        totalStorage = (long) mDataFileStats.getBlockCount() * mDataFileStats.getBlockSize();
        freeStorage = (long) mDataFileStats.getAvailableBlocks() * mDataFileStats.getBlockSize();
      } catch (IllegalArgumentException e) {
      }
      final boolean emulatedStorage = Environment.isExternalStorageEmulated();
      final int N = mApplicationsAdapter.getCount();
      for (int i = 0; i < N; i++) {
        ApplicationsState.AppEntry ae = mApplicationsAdapter.getAppEntry(i);
        appStorage += ae.codeSize + ae.dataSize;
        if (emulatedStorage) {
          appStorage += ae.externalCodeSize + ae.externalDataSize;
        }
      }
      freeStorage += mApplicationsState.sumCacheSizes();
    }
    if (newLabel != null) {
      mStorageChartLabel.setText(newLabel);
    }
    if (totalStorage > 0) {
      mColorBar.setRatios(
          (totalStorage - freeStorage - appStorage) / (float) totalStorage,
          appStorage / (float) totalStorage,
          freeStorage / (float) totalStorage);
      long usedStorage = totalStorage - freeStorage;
      if (mLastUsedStorage != usedStorage) {
        mLastUsedStorage = usedStorage;
        String sizeStr = Formatter.formatShortFileSize(getActivity(), usedStorage);
        mUsedStorageText.setText(
            getActivity().getResources().getString(R.string.service_foreground_processes, sizeStr));
      }
      if (mLastFreeStorage != freeStorage) {
        mLastFreeStorage = freeStorage;
        String sizeStr = Formatter.formatShortFileSize(getActivity(), freeStorage);
        mFreeStorageText.setText(
            getActivity().getResources().getString(R.string.service_background_processes, sizeStr));
      }
    } else {
      mColorBar.setRatios(0, 0, 0);
      if (mLastUsedStorage != -1) {
        mLastUsedStorage = -1;
        mUsedStorageText.setText("");
      }
      if (mLastFreeStorage != -1) {
        mLastFreeStorage = -1;
        mFreeStorageText.setText("");
      }
    }
  }