Created
October 22, 2013 23:16
-
-
Save nivir/7109855 to your computer and use it in GitHub Desktop.
Android Process Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package it.roy.UtilityManager.gui; | |
import it.roy.UtilityManager.gui.ProcessListAdapters.ProcessListAdapter; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.app.Activity; | |
import android.app.ActivityManager; | |
import android.app.ActivityManager.RunningAppProcessInfo; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.IntentFilter; | |
import android.content.pm.PackageManager; | |
import android.content.res.Configuration; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.AdapterView.OnItemClickListener; | |
import android.widget.ListView; | |
public class ProcessManager extends Activity { | |
private ProcessCore pinfo = null; | |
ActivityManager am = null; | |
private PackagesInfo packageinfo = null; | |
private PackageManager package_manager; | |
private static final int STAT_TASK = 0; | |
protected static final String LOAD_FINISH = "Roy"; | |
private int stat = STAT_TASK; | |
private ProcessListAdapter adapter; | |
private BroadcastReceiver loadFinish = new ProcessManagerListReceiver(); | |
private ArrayList<ProcessDetails> listdp; | |
// -------------------------------Function--------------------------------------- | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); | |
package_manager = this.getApplicationContext().getPackageManager(); | |
packageinfo = new PackagesInfo(this); | |
} | |
ListView getListView() { | |
return (ListView) this.findViewById(R.id.listbody); | |
} | |
// -------------------------------Function--------------------------------------- | |
public void refreshing_process() { | |
setProgressBarIndeterminateVisibility(true); | |
if (stat == STAT_TASK) { | |
Thread t = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
pinfo = new ProcessCore(); | |
get_running_process(); | |
Intent in = new Intent(LOAD_FINISH); | |
ProcessManager.this.sendBroadcast(in); | |
} | |
}); | |
t.start(); | |
} | |
} | |
// -------------------------------Function--------------------------------------- | |
public ProcessCore getProcessInfo() { | |
return pinfo; | |
} | |
// -------------------------------Function--------------------------------------- | |
public PackagesInfo getPackageInfo() { | |
return packageinfo; | |
} | |
// -------------------------------Function--------------------------------------- | |
@Override | |
public void onConfigurationChanged(Configuration newConfig) { | |
super.onConfigurationChanged(newConfig); | |
} | |
// -------------------------------Function--------------------------------------- | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
IntentFilter filter = new IntentFilter(LOAD_FINISH); | |
this.registerReceiver(loadFinish, filter); | |
packageinfo = new PackagesInfo(this); | |
refreshing_process(); | |
} | |
// -------------------------------Function--------------------------------------- | |
private class ProcessManagerListReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(final Context ctx, Intent intent) { | |
ProcessManager.this.setProgressBarIndeterminateVisibility(false); | |
ProcessManager.this.getListView().setAdapter(adapter); | |
ProcessManager.this.getListView().setOnItemClickListener( | |
new OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> arg0, View arg1, | |
int arg2, long arg3) { | |
if (stat == STAT_TASK) { | |
ProcessDetails dp = listdp.get(arg2); | |
ProcessPopUpUtil.getTaskMenuDialog(ProcessManager.this, | |
dp).show(); | |
} | |
} | |
}); | |
} | |
} | |
// -------------------------------Function--------------------------------------- | |
public void get_running_process() { | |
List<RunningAppProcessInfo> list2 = am.getRunningAppProcesses(); | |
listdp = new ArrayList<ProcessDetails>(); | |
for (RunningAppProcessInfo ti : list2) { | |
if (ti.processName.equals("system") | |
|| ti.processName.equals("com.android.phone")) { | |
continue; | |
} | |
ProcessDetails dp = new ProcessDetails(this, ti); | |
dp.fetchApplicationInfo(packageinfo); | |
dp.fetchPackageInfo(); | |
dp.fetchPsRow(pinfo); | |
if (dp.isGoodProcess()) { | |
listdp.add(dp); | |
} | |
} | |
adapter = new ProcessListAdapter(this, listdp); | |
} | |
// -------------------------------Function--------------------------------------- | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
this.unregisterReceiver(loadFinish); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment