Merge "Handle pids coming and going in the memory tracker." into jb-ub-gel-agar

This commit is contained in:
Daniel Sandler
2013-06-26 02:39:45 +00:00
committed by Android (Google) Code Review
+26 -2
View File
@@ -46,6 +46,13 @@ public class WeightWatcher extends LinearLayout {
private static final int MSG_STOP = 2;
private static final int MSG_UPDATE = 3;
static int indexOf(int[] a, int x) {
for (int i=0; i<a.length; i++) {
if (a[i] == x) return i;
}
return -1;
}
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message m) {
@@ -57,9 +64,17 @@ public class WeightWatcher extends LinearLayout {
mHandler.removeMessages(MSG_UPDATE);
break;
case MSG_UPDATE:
int[] pids = mMemoryService.getTrackedProcesses();
final int N = getChildCount();
for (int i=0; i<N; i++) {
((ProcessWatcher) getChildAt(i)).update();
if (pids.length != N) initViews();
else for (int i=0; i<N; i++) {
ProcessWatcher pw = ((ProcessWatcher) getChildAt(i));
if (indexOf(pids, pw.getPid()) < 0) {
initViews();
break;
}
pw.update();
}
mHandler.sendEmptyMessageDelayed(MSG_UPDATE, UPDATE_RATE);
break;
@@ -90,6 +105,7 @@ public class WeightWatcher extends LinearLayout {
}
public void initViews() {
removeAllViews();
int[] processes = mMemoryService.getTrackedProcesses();
for (int i=0; i<processes.length; i++) {
final ProcessWatcher v = new ProcessWatcher(getContext());
@@ -184,6 +200,14 @@ public class WeightWatcher extends LinearLayout {
public void setPid(int pid) {
mPid = pid;
mMemInfo = mMemoryService.getMemInfo(mPid);
if (mMemInfo == null) {
Log.v("WeightWatcher", "Missing info for pid " + mPid + ", removing view: " + this);
initViews();
}
}
public int getPid() {
return mPid;
}
public void update() {