From 430a3d3376cfa2c2a03d6f18d28577c34750102c Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Sun, 7 Aug 2011 16:29:05 -0700 Subject: Update to work with the activity manager taking over OOM settings. The values it needs are no longer in properties. Also fix a few problems: bug with apps being left in the services list, sorting of internal storage. Change-Id: Ife9706e004931269c36a7bc37b9dbb016064c2e4 --- .../settings/applications/ApplicationsState.java | 33 ++++++- .../settings/applications/ManageApplications.java | 12 ++- .../applications/RunningProcessesView.java | 108 +++++---------------- .../settings/applications/RunningState.java | 15 ++- 4 files changed, 75 insertions(+), 93 deletions(-) diff --git a/src/com/android/settings/applications/ApplicationsState.java b/src/com/android/settings/applications/ApplicationsState.java index 519c2033a..e0899cb11 100644 --- a/src/com/android/settings/applications/ApplicationsState.java +++ b/src/com/android/settings/applications/ApplicationsState.java @@ -80,6 +80,8 @@ public class ApplicationsState { final long id; String label; long size; + long internalSize; + long externalSize; boolean mounted; @@ -155,7 +157,8 @@ public class ApplicationsState { } }; - public static final Comparator SIZE_COMPARATOR = new Comparator() { + public static final Comparator SIZE_COMPARATOR + = new Comparator() { private final Collator sCollator = Collator.getInstance(); @Override public int compare(AppEntry object1, AppEntry object2) { @@ -165,6 +168,28 @@ public class ApplicationsState { } }; + public static final Comparator INTERNAL_SIZE_COMPARATOR + = new Comparator() { + private final Collator sCollator = Collator.getInstance(); + @Override + public int compare(AppEntry object1, AppEntry object2) { + if (object1.internalSize < object2.internalSize) return 1; + if (object1.internalSize > object2.internalSize) return -1; + return sCollator.compare(object1.label, object2.label); + } + }; + + public static final Comparator EXTERNAL_SIZE_COMPARATOR + = new Comparator() { + private final Collator sCollator = Collator.getInstance(); + @Override + public int compare(AppEntry object1, AppEntry object2) { + if (object1.externalSize < object2.externalSize) return 1; + if (object1.externalSize > object2.externalSize) return -1; + return sCollator.compare(object1.label, object2.label); + } + }; + public static final AppFilter THIRD_PARTY_FILTER = new AppFilter() { public void init() { } @@ -712,8 +737,10 @@ public class ApplicationsState { entry.externalCodeSize = externalCodeSize; entry.externalDataSize = externalDataSize; entry.sizeStr = getSizeStr(entry.size); - entry.internalSizeStr = getSizeStr(getTotalInternalSize(stats)); - entry.externalSizeStr = getSizeStr(getTotalExternalSize(stats)); + entry.internalSize = getTotalInternalSize(stats); + entry.internalSizeStr = getSizeStr(entry.internalSize); + entry.externalSize = getTotalExternalSize(stats); + entry.externalSizeStr = getSizeStr(entry.externalSize); if (DEBUG) Log.i(TAG, "Set size of " + entry.label + " " + entry + ": " + entry.sizeStr); sizeChanged = true; diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index 554ece36e..68c942db6 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -333,7 +333,17 @@ public class ManageApplications extends Fragment implements } switch (mLastSortMode) { case SORT_ORDER_SIZE: - comparatorObj = ApplicationsState.SIZE_COMPARATOR; + switch (mWhichSize) { + case SIZE_INTERNAL: + comparatorObj = ApplicationsState.INTERNAL_SIZE_COMPARATOR; + break; + case SIZE_EXTERNAL: + comparatorObj = ApplicationsState.EXTERNAL_SIZE_COMPARATOR; + break; + default: + comparatorObj = ApplicationsState.SIZE_COMPARATOR; + break; + } break; default: comparatorObj = ApplicationsState.ALPHA_COMPARATOR; diff --git a/src/com/android/settings/applications/RunningProcessesView.java b/src/com/android/settings/applications/RunningProcessesView.java index 1f91c33b7..7c3ebb034 100644 --- a/src/com/android/settings/applications/RunningProcessesView.java +++ b/src/com/android/settings/applications/RunningProcessesView.java @@ -16,6 +16,7 @@ package com.android.settings.applications; +import com.android.internal.util.MemInfoReader; import com.android.settings.R; import android.app.ActivityManager; @@ -24,9 +25,7 @@ import android.app.Fragment; import android.content.Context; import android.content.pm.PackageManager; import android.os.Bundle; -import android.os.StrictMode; import android.os.SystemClock; -import android.os.SystemProperties; import android.preference.PreferenceActivity; import android.text.format.DateUtils; import android.text.format.Formatter; @@ -42,7 +41,6 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.AbsListView.RecyclerListener; -import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -51,9 +49,6 @@ public class RunningProcessesView extends FrameLayout implements AdapterView.OnItemClickListener, RecyclerListener, RunningState.OnRefreshUiListener { - // Memory pages are 4K. - static final long PAGE_SIZE = 4*1024; - long SECONDARY_SERVER_MEM; final HashMap mActiveItems = new HashMap(); @@ -85,9 +80,9 @@ public class RunningProcessesView extends FrameLayout long mLastAvailMemory = -1; Dialog mCurDialog; - - byte[] mBuffer = new byte[1024]; - + + MemInfoReader mMemInfoReader = new MemInfoReader(); + public static class ActiveItem { View mRootView; RunningState.BaseItem mItem; @@ -304,71 +299,7 @@ public class RunningProcessesView extends FrameLayout } } } - - private boolean matchText(byte[] buffer, int index, String text) { - int N = text.length(); - if ((index+N) >= buffer.length) { - return false; - } - for (int i=0; i= '0' && buffer[index] <= '9') { - int start = index; - index++; - while (index < buffer.length && buffer[index] >= '0' - && buffer[index] <= '9') { - index++; - } - String str = new String(buffer, 0, start, index-start); - return ((long)Integer.parseInt(str)) * 1024; - } - index++; - } - return 0; - } - - private long readAvailMem() { - // Permit disk reads here, as /proc/meminfo isn't really "on - // disk" and should be fast. TODO: make BlockGuard ignore - // /proc/ and /sys/ files perhaps? - StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); - try { - long memFree = 0; - long memCached = 0; - FileInputStream is = new FileInputStream("/proc/meminfo"); - int len = is.read(mBuffer); - is.close(); - final int BUFLEN = mBuffer.length; - for (int i=0; i= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND + && pi.importance < ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE && pi.importanceReasonCode == ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) { return true; @@ -718,13 +720,16 @@ public class RunningState { mInterestingProcesses.add(proc); } proc.mCurSeq = mSequence; + proc.mInteresting = true; proc.ensureLabel(pm); + } else { + proc.mInteresting = false; } proc.mRunningSeq = mSequence; proc.mRunningProcessInfo = pi; } - + // Build the chains from client processes to the process they are // dependent on; also remove any old running processes. int NRP = mRunningProcesses.size(); @@ -756,7 +761,7 @@ public class RunningState { int NHP = mInterestingProcesses.size(); for (int i=0; i