void applyCurrentStorage() { // If view hierarchy is not yet created, no views to update. if (mRootView == null) { return; } if (mTotalStorage > 0) { BidiFormatter bidiFormatter = BidiFormatter.getInstance(); mColorBar.setRatios( (mTotalStorage - mFreeStorage - mAppStorage) / (float) mTotalStorage, mAppStorage / (float) mTotalStorage, mFreeStorage / (float) mTotalStorage); long usedStorage = mTotalStorage - mFreeStorage; if (mLastUsedStorage != usedStorage) { mLastUsedStorage = usedStorage; String sizeStr = bidiFormatter.unicodeWrap( Formatter.formatShortFileSize(mOwner.getActivity(), usedStorage)); mUsedStorageText.setText( mOwner .getActivity() .getResources() .getString(R.string.service_foreground_processes, sizeStr)); } if (mLastFreeStorage != mFreeStorage) { mLastFreeStorage = mFreeStorage; String sizeStr = bidiFormatter.unicodeWrap( Formatter.formatShortFileSize(mOwner.getActivity(), mFreeStorage)); mFreeStorageText.setText( mOwner .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(""); } } }
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(""); } } }
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); } }
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); } }