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
This commit is contained in:
@@ -80,6 +80,8 @@ public class ApplicationsState {
|
|||||||
final long id;
|
final long id;
|
||||||
String label;
|
String label;
|
||||||
long size;
|
long size;
|
||||||
|
long internalSize;
|
||||||
|
long externalSize;
|
||||||
|
|
||||||
boolean mounted;
|
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();
|
private final Collator sCollator = Collator.getInstance();
|
||||||
@Override
|
@Override
|
||||||
public int compare(AppEntry object1, AppEntry object2) {
|
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 static final AppFilter THIRD_PARTY_FILTER = new AppFilter() {
|
||||||
public void init() {
|
public void init() {
|
||||||
}
|
}
|
||||||
@@ -712,8 +737,10 @@ public class ApplicationsState {
|
|||||||
entry.externalCodeSize = externalCodeSize;
|
entry.externalCodeSize = externalCodeSize;
|
||||||
entry.externalDataSize = externalDataSize;
|
entry.externalDataSize = externalDataSize;
|
||||||
entry.sizeStr = getSizeStr(entry.size);
|
entry.sizeStr = getSizeStr(entry.size);
|
||||||
entry.internalSizeStr = getSizeStr(getTotalInternalSize(stats));
|
entry.internalSize = getTotalInternalSize(stats);
|
||||||
entry.externalSizeStr = getSizeStr(getTotalExternalSize(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
|
if (DEBUG) Log.i(TAG, "Set size of " + entry.label + " " + entry
|
||||||
+ ": " + entry.sizeStr);
|
+ ": " + entry.sizeStr);
|
||||||
sizeChanged = true;
|
sizeChanged = true;
|
||||||
|
@@ -333,8 +333,18 @@ public class ManageApplications extends Fragment implements
|
|||||||
}
|
}
|
||||||
switch (mLastSortMode) {
|
switch (mLastSortMode) {
|
||||||
case SORT_ORDER_SIZE:
|
case SORT_ORDER_SIZE:
|
||||||
|
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;
|
comparatorObj = ApplicationsState.SIZE_COMPARATOR;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
comparatorObj = ApplicationsState.ALPHA_COMPARATOR;
|
comparatorObj = ApplicationsState.ALPHA_COMPARATOR;
|
||||||
break;
|
break;
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import com.android.internal.util.MemInfoReader;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
@@ -24,9 +25,7 @@ import android.app.Fragment;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
@@ -42,7 +41,6 @@ import android.widget.ListView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.AbsListView.RecyclerListener;
|
import android.widget.AbsListView.RecyclerListener;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -51,9 +49,6 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
implements AdapterView.OnItemClickListener, RecyclerListener,
|
implements AdapterView.OnItemClickListener, RecyclerListener,
|
||||||
RunningState.OnRefreshUiListener {
|
RunningState.OnRefreshUiListener {
|
||||||
|
|
||||||
// Memory pages are 4K.
|
|
||||||
static final long PAGE_SIZE = 4*1024;
|
|
||||||
|
|
||||||
long SECONDARY_SERVER_MEM;
|
long SECONDARY_SERVER_MEM;
|
||||||
|
|
||||||
final HashMap<View, ActiveItem> mActiveItems = new HashMap<View, ActiveItem>();
|
final HashMap<View, ActiveItem> mActiveItems = new HashMap<View, ActiveItem>();
|
||||||
@@ -86,7 +81,7 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
|
|
||||||
Dialog mCurDialog;
|
Dialog mCurDialog;
|
||||||
|
|
||||||
byte[] mBuffer = new byte[1024];
|
MemInfoReader mMemInfoReader = new MemInfoReader();
|
||||||
|
|
||||||
public static class ActiveItem {
|
public static class ActiveItem {
|
||||||
View mRootView;
|
View mRootView;
|
||||||
@@ -305,70 +300,6 @@ 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) {
|
void refreshUi(boolean dataChanged) {
|
||||||
if (dataChanged) {
|
if (dataChanged) {
|
||||||
ServiceListAdapter adapter = (ServiceListAdapter)(mListView.getAdapter());
|
ServiceListAdapter adapter = (ServiceListAdapter)(mListView.getAdapter());
|
||||||
@@ -383,7 +314,9 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
|
|
||||||
// This is the amount of available memory until we start killing
|
// This is the amount of available memory until we start killing
|
||||||
// background services.
|
// background services.
|
||||||
long availMem = readAvailMem() - SECONDARY_SERVER_MEM;
|
mMemInfoReader.readMemInfo();
|
||||||
|
long availMem = mMemInfoReader.getFreeSize() + mMemInfoReader.getCachedSize()
|
||||||
|
- SECONDARY_SERVER_MEM;
|
||||||
if (availMem < 0) {
|
if (availMem < 0) {
|
||||||
availMem = 0;
|
availMem = 0;
|
||||||
}
|
}
|
||||||
@@ -395,10 +328,14 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
mLastNumBackgroundProcesses = mState.mNumBackgroundProcesses;
|
mLastNumBackgroundProcesses = mState.mNumBackgroundProcesses;
|
||||||
mLastBackgroundProcessMemory = mState.mBackgroundProcessMemory;
|
mLastBackgroundProcessMemory = mState.mBackgroundProcessMemory;
|
||||||
mLastAvailMemory = availMem;
|
mLastAvailMemory = availMem;
|
||||||
String sizeStr = Formatter.formatShortFileSize(getContext(),
|
long freeMem = mLastAvailMemory + mLastBackgroundProcessMemory;
|
||||||
mLastAvailMemory + mLastBackgroundProcessMemory);
|
String sizeStr = Formatter.formatShortFileSize(getContext(), freeMem);
|
||||||
mBackgroundProcessText.setText(getResources().getString(
|
mBackgroundProcessText.setText(getResources().getString(
|
||||||
R.string.service_background_processes, sizeStr));
|
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
|
if (mLastNumForegroundProcesses != mState.mNumForegroundProcesses
|
||||||
|| mLastForegroundProcessMemory != mState.mForegroundProcessMemory
|
|| mLastForegroundProcessMemory != mState.mForegroundProcessMemory
|
||||||
@@ -408,15 +345,18 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
mLastForegroundProcessMemory = mState.mForegroundProcessMemory;
|
mLastForegroundProcessMemory = mState.mForegroundProcessMemory;
|
||||||
mLastNumServiceProcesses = mState.mNumServiceProcesses;
|
mLastNumServiceProcesses = mState.mNumServiceProcesses;
|
||||||
mLastServiceProcessMemory = mState.mServiceProcessMemory;
|
mLastServiceProcessMemory = mState.mServiceProcessMemory;
|
||||||
|
/*
|
||||||
String sizeStr = Formatter.formatShortFileSize(getContext(),
|
String sizeStr = Formatter.formatShortFileSize(getContext(),
|
||||||
mLastForegroundProcessMemory + mLastServiceProcessMemory);
|
mLastForegroundProcessMemory + mLastServiceProcessMemory);
|
||||||
mForegroundProcessText.setText(getResources().getString(
|
mForegroundProcessText.setText(getResources().getString(
|
||||||
R.string.service_foreground_processes, sizeStr));
|
R.string.service_foreground_processes, sizeStr));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
float totalMem = availMem + mLastBackgroundProcessMemory
|
float totalMem = mMemInfoReader.getTotalSize();
|
||||||
+ mLastForegroundProcessMemory + mLastServiceProcessMemory;
|
float totalShownMem = availMem + mLastBackgroundProcessMemory
|
||||||
mColorBar.setRatios(mLastForegroundProcessMemory/totalMem,
|
+ mLastServiceProcessMemory;
|
||||||
|
mColorBar.setRatios((totalMem-totalShownMem)/totalMem,
|
||||||
mLastServiceProcessMemory/totalMem,
|
mLastServiceProcessMemory/totalMem,
|
||||||
mLastBackgroundProcessMemory/totalMem);
|
mLastBackgroundProcessMemory/totalMem);
|
||||||
}
|
}
|
||||||
@@ -483,9 +423,9 @@ public class RunningProcessesView extends FrameLayout
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Magic! Implementation detail! Don't count on this!
|
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||||
SECONDARY_SERVER_MEM =
|
mAm.getMemoryInfo(memInfo);
|
||||||
Integer.valueOf(SystemProperties.get("ro.SECONDARY_SERVER_MEM"))*PAGE_SIZE;
|
SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPause() {
|
public void doPause() {
|
||||||
|
@@ -28,7 +28,6 @@ import android.content.pm.PackageItemInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Debug;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -251,6 +250,8 @@ public class RunningState {
|
|||||||
|
|
||||||
MergedItem mMergedItem;
|
MergedItem mMergedItem;
|
||||||
|
|
||||||
|
boolean mInteresting;
|
||||||
|
|
||||||
// Purely for sorting.
|
// Purely for sorting.
|
||||||
boolean mIsSystem;
|
boolean mIsSystem;
|
||||||
boolean mIsStarted;
|
boolean mIsStarted;
|
||||||
@@ -616,7 +617,8 @@ public class RunningState {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((pi.flags&ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT) == 0
|
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
|
&& pi.importanceReasonCode
|
||||||
== ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) {
|
== ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) {
|
||||||
return true;
|
return true;
|
||||||
@@ -718,7 +720,10 @@ public class RunningState {
|
|||||||
mInterestingProcesses.add(proc);
|
mInterestingProcesses.add(proc);
|
||||||
}
|
}
|
||||||
proc.mCurSeq = mSequence;
|
proc.mCurSeq = mSequence;
|
||||||
|
proc.mInteresting = true;
|
||||||
proc.ensureLabel(pm);
|
proc.ensureLabel(pm);
|
||||||
|
} else {
|
||||||
|
proc.mInteresting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc.mRunningSeq = mSequence;
|
proc.mRunningSeq = mSequence;
|
||||||
@@ -756,7 +761,7 @@ public class RunningState {
|
|||||||
int NHP = mInterestingProcesses.size();
|
int NHP = mInterestingProcesses.size();
|
||||||
for (int i=0; i<NHP; i++) {
|
for (int i=0; i<NHP; i++) {
|
||||||
ProcessItem proc = mInterestingProcesses.get(i);
|
ProcessItem proc = mInterestingProcesses.get(i);
|
||||||
if (mRunningProcesses.get(proc.mPid) == null) {
|
if (!proc.mInteresting || mRunningProcesses.get(proc.mPid) == null) {
|
||||||
changed = true;
|
changed = true;
|
||||||
mInterestingProcesses.remove(i);
|
mInterestingProcesses.remove(i);
|
||||||
i--;
|
i--;
|
||||||
|
Reference in New Issue
Block a user