コード例 #1
0
  void refreshUi(boolean dataChanged) {
    if (dataChanged) {
      ServiceListAdapter adapter = (ServiceListAdapter) (mListView.getAdapter());
      adapter.refreshItems();
      adapter.notifyDataSetChanged();
    }

    if (mDataAvail != null) {
      mDataAvail.run();
      mDataAvail = null;
    }

    // This is the amount of available memory until we start killing
    // background services.
    mMemInfoReader.readMemInfo();
    long availMem =
        mMemInfoReader.getFreeSize() + mMemInfoReader.getCachedSize() - SECONDARY_SERVER_MEM;
    if (availMem < 0) {
      availMem = 0;
    }

    /// M: get total size @{
    long totalSize = mMemInfoReader.getTotalSize();
    /// @}

    synchronized (mState.mLock) {

      /// M: get zram extra available memory @{
      long extraAvailableSize = 0;
      if (SystemProperties.getBoolean("mediatek.virtual_zram_extra", false)) {
        extraAvailableSize += Process.getZramExtraAvailableSize();
      } else {
        final long anonReserve = 15 * 1024 * 1024; // 15MB
        long anonToCompress =
            Process.getLruAnonMemory() - anonReserve - mState.mBackgroundProcessMemory;
        if (anonToCompress > 0) {
          extraAvailableSize =
              (long) (anonToCompress * (1.0f - 1.0f / Process.getZramCompressRatio()));
        }
      }
      Log.i("RunningProcessView", "extraAvailableSize = " + extraAvailableSize);
      availMem += extraAvailableSize;
      /// @}
      if (mLastNumBackgroundProcesses != mState.mNumBackgroundProcesses
          || mLastBackgroundProcessMemory != mState.mBackgroundProcessMemory
          || mLastAvailMemory != availMem) {
        mLastNumBackgroundProcesses = mState.mNumBackgroundProcesses;
        mLastBackgroundProcessMemory = mState.mBackgroundProcessMemory;
        mLastAvailMemory = availMem;
        long freeMem = mLastAvailMemory + mLastBackgroundProcessMemory;

        BidiFormatter bidiFormatter = BidiFormatter.getInstance();
        String sizeStr =
            bidiFormatter.unicodeWrap(Formatter.formatShortFileSize(getContext(), freeMem));

        mBackgroundProcessText.setText(
            getResources().getString(R.string.service_background_processes, sizeStr));

        sizeStr =
            bidiFormatter.unicodeWrap(
                Formatter.formatShortFileSize(
                    getContext(), mMemInfoReader.getTotalSize() - freeMem));

        mForegroundProcessText.setText(
            getResources().getString(R.string.service_foreground_processes, sizeStr));
      }
      if (mLastNumForegroundProcesses != mState.mNumForegroundProcesses
          || mLastForegroundProcessMemory != mState.mForegroundProcessMemory
          || mLastNumServiceProcesses != mState.mNumServiceProcesses
          || mLastServiceProcessMemory != mState.mServiceProcessMemory) {
        mLastNumForegroundProcesses = mState.mNumForegroundProcesses;
        mLastForegroundProcessMemory = mState.mForegroundProcessMemory;
        mLastNumServiceProcesses = mState.mNumServiceProcesses;
        mLastServiceProcessMemory = mState.mServiceProcessMemory;
        /*
        String sizeStr = Formatter.formatShortFileSize(getContext(),
                mLastForegroundProcessMemory + mLastServiceProcessMemory);
        mForegroundProcessText.setText(getResources().getString(
                R.string.service_foreground_processes, sizeStr));
        */
      }
      /// M: get swap usage @{
      float totalMem = totalSize;
      float totalShownMem = availMem + mLastBackgroundProcessMemory + mLastServiceProcessMemory;
      Log.i(
          "RunningProcessView",
          "totalShownMem = "
              + mMemInfoReader.getFreeSize()
              + " + "
              + mMemInfoReader.getCachedSize()
              + " - "
              + SECONDARY_SERVER_MEM
              + " + "
              + mLastBackgroundProcessMemory
              + " + "
              + mLastServiceProcessMemory);
      /// @}
      mColorBar.setRatios(
          (totalMem - totalShownMem) / totalMem,
          mLastServiceProcessMemory / totalMem,
          mLastBackgroundProcessMemory / totalMem);
    }
  }
コード例 #2
0
  void refreshUi(boolean dataChanged) {
    if (dataChanged) {
      ServiceListAdapter adapter = (ServiceListAdapter) (mListView.getAdapter());
      adapter.refreshItems();
      adapter.notifyDataSetChanged();
    }

    if (mDataAvail != null) {
      mDataAvail.run();
      mDataAvail = null;
    }

    // This is the amount of available memory until we start killing
    // background services.
    mMemInfoReader.readMemInfo();
    long availMem =
        mMemInfoReader.getFreeSize() + mMemInfoReader.getCachedSize() - SECONDARY_SERVER_MEM;
    if (availMem < 0) {
      availMem = 0;
    }

    synchronized (mState.mLock) {
      if (mLastNumBackgroundProcesses != mState.mNumBackgroundProcesses
          || mLastBackgroundProcessMemory != mState.mBackgroundProcessMemory
          || mLastAvailMemory != availMem) {
        mLastNumBackgroundProcesses = mState.mNumBackgroundProcesses;
        mLastBackgroundProcessMemory = mState.mBackgroundProcessMemory;
        mLastAvailMemory = availMem;
        long freeMem = mLastAvailMemory + mLastBackgroundProcessMemory;
        BidiFormatter bidiFormatter = BidiFormatter.getInstance();
        String sizeStr =
            bidiFormatter.unicodeWrap(Formatter.formatShortFileSize(getContext(), freeMem));
        mBackgroundProcessText.setText(
            getResources().getString(R.string.service_background_processes, sizeStr));
        sizeStr =
            bidiFormatter.unicodeWrap(
                Formatter.formatShortFileSize(
                    getContext(), mMemInfoReader.getTotalSize() - freeMem));
        mForegroundProcessText.setText(
            getResources().getString(R.string.service_foreground_processes, sizeStr));
      }
      if (mLastNumForegroundProcesses != mState.mNumForegroundProcesses
          || mLastForegroundProcessMemory != mState.mForegroundProcessMemory
          || mLastNumServiceProcesses != mState.mNumServiceProcesses
          || mLastServiceProcessMemory != mState.mServiceProcessMemory) {
        mLastNumForegroundProcesses = mState.mNumForegroundProcesses;
        mLastForegroundProcessMemory = mState.mForegroundProcessMemory;
        mLastNumServiceProcesses = mState.mNumServiceProcesses;
        mLastServiceProcessMemory = mState.mServiceProcessMemory;
        /*
        String sizeStr = Formatter.formatShortFileSize(getContext(),
                mLastForegroundProcessMemory + mLastServiceProcessMemory);
        mForegroundProcessText.setText(getResources().getString(
                R.string.service_foreground_processes, sizeStr));
        */
      }

      float totalMem = mMemInfoReader.getTotalSize();
      float totalShownMem = availMem + mLastBackgroundProcessMemory + mLastServiceProcessMemory;
      mColorBar.setRatios(
          (totalMem - totalShownMem) / totalMem,
          mLastServiceProcessMemory / totalMem,
          mLastBackgroundProcessMemory / totalMem);
    }
  }