summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2011-08-07 16:29:05 -0700
committerDianne Hackborn <hackbod@google.com>2011-08-07 16:29:05 -0700
commit430a3d3376cfa2c2a03d6f18d28577c34750102c (patch)
treecd0980c81b0f96b74ec37a9dd8c6a8e7bdafef1c
parent2826bc4ca52686f6863409e36eaea1a7f45de3eb (diff)
downloadpackages_apps_Settings-430a3d3376cfa2c2a03d6f18d28577c34750102c.tar.gz
packages_apps_Settings-430a3d3376cfa2c2a03d6f18d28577c34750102c.tar.bz2
packages_apps_Settings-430a3d3376cfa2c2a03d6f18d28577c34750102c.zip
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
-rw-r--r--src/com/android/settings/applications/ApplicationsState.java33
-rw-r--r--src/com/android/settings/applications/ManageApplications.java12
-rw-r--r--src/com/android/settings/applications/RunningProcessesView.java108
-rw-r--r--src/com/android/settings/applications/RunningState.java15
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<AppEntry> SIZE_COMPARATOR = new Comparator<AppEntry>() {
+ public static final Comparator<AppEntry> SIZE_COMPARATOR
+ = new Comparator<AppEntry>() {
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<AppEntry> INTERNAL_SIZE_COMPARATOR
+ = new Comparator<AppEntry>() {
+ 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<AppEntry> EXTERNAL_SIZE_COMPARATOR
+ = new Comparator<AppEntry>() {
+ 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<View, ActiveItem> mActiveItems = new HashMap<View, ActiveItem>();
@@ -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<N; i++) {
- if (buffer[index+i] != text.charAt(i)) {
- return false;
- }
- }
- return true;
- }
-
- private long extractMemValue(byte[] buffer, int index) {
- while (index < buffer.length && buffer[index] != '\n') {
- if (buffer[index] >= '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<len && (memFree == 0 || memCached == 0); i++) {
- if (matchText(mBuffer, i, "MemFree")) {
- i += 7;
- memFree = extractMemValue(mBuffer, i);
- } else if (matchText(mBuffer, i, "Cached")) {
- i += 6;
- memCached = extractMemValue(mBuffer, i);
- }
- while (i < BUFLEN && mBuffer[i] != '\n') {
- i++;
- }
- }
- return memFree + memCached;
- } catch (java.io.FileNotFoundException e) {
- } catch (java.io.IOException e) {
- } finally {
- StrictMode.setThreadPolicy(savedPolicy);
- }
- return 0;
- }
-
void refreshUi(boolean dataChanged) {
if (dataChanged) {
ServiceListAdapter adapter = (ServiceListAdapter)(mListView.getAdapter());
@@ -383,11 +314,13 @@ public class RunningProcessesView extends FrameLayout
// This is the amount of available memory until we start killing
// background services.
- long availMem = readAvailMem() - SECONDARY_SERVER_MEM;
+ 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
@@ -395,10 +328,14 @@ public class RunningProcessesView extends FrameLayout
mLastNumBackgroundProcesses = mState.mNumBackgroundProcesses;
mLastBackgroundProcessMemory = mState.mBackgroundProcessMemory;
mLastAvailMemory = availMem;
- String sizeStr = Formatter.formatShortFileSize(getContext(),
- mLastAvailMemory + mLastBackgroundProcessMemory);
+ long freeMem = mLastAvailMemory + mLastBackgroundProcessMemory;
+ String sizeStr = Formatter.formatShortFileSize(getContext(), freeMem);
mBackgroundProcessText.setText(getResources().getString(
R.string.service_background_processes, sizeStr));
+ sizeStr = Formatter.formatShortFileSize(getContext(),
+ mMemInfoReader.getTotalSize() - freeMem);
+ mForegroundProcessText.setText(getResources().getString(
+ R.string.service_foreground_processes, sizeStr));
}
if (mLastNumForegroundProcesses != mState.mNumForegroundProcesses
|| mLastForegroundProcessMemory != mState.mForegroundProcessMemory
@@ -408,15 +345,18 @@ public class RunningProcessesView extends FrameLayout
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 = availMem + mLastBackgroundProcessMemory
- + mLastForegroundProcessMemory + mLastServiceProcessMemory;
- mColorBar.setRatios(mLastForegroundProcessMemory/totalMem,
+ float totalMem = mMemInfoReader.getTotalSize();
+ float totalShownMem = availMem + mLastBackgroundProcessMemory
+ + mLastServiceProcessMemory;
+ mColorBar.setRatios((totalMem-totalShownMem)/totalMem,
mLastServiceProcessMemory/totalMem,
mLastBackgroundProcessMemory/totalMem);
}
@@ -482,10 +422,10 @@ public class RunningProcessesView extends FrameLayout
mAdapter.setShowBackground(false);
}
});
-
- // Magic! Implementation detail! Don't count on this!
- SECONDARY_SERVER_MEM =
- Integer.valueOf(SystemProperties.get("ro.SECONDARY_SERVER_MEM"))*PAGE_SIZE;
+
+ ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
+ mAm.getMemoryInfo(memInfo);
+ SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold;
}
public void doPause() {
diff --git a/src/com/android/settings/applications/RunningState.java b/src/com/android/settings/applications/RunningState.java
index e9053b9ea..552aa56d0 100644
--- a/src/com/android/settings/applications/RunningState.java
+++ b/src/com/android/settings/applications/RunningState.java
@@ -28,7 +28,6 @@ import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
-import android.os.Debug;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
@@ -250,7 +249,9 @@ public class RunningState {
ActivityManager.RunningAppProcessInfo mRunningProcessInfo;
MergedItem mMergedItem;
-
+
+ boolean mInteresting;
+
// Purely for sorting.
boolean mIsSystem;
boolean mIsStarted;
@@ -616,7 +617,8 @@ public class RunningState {
return true;
}
if ((pi.flags&ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT) == 0
- && pi.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
+ && pi.importance >= 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<NHP; i++) {
ProcessItem proc = mInterestingProcesses.get(i);
- if (mRunningProcesses.get(proc.mPid) == null) {
+ if (!proc.mInteresting || mRunningProcesses.get(proc.mPid) == null) {
changed = true;
mInterestingProcesses.remove(i);
i--;