Bug 745889: SUT agent/watcher - avoid NullPointerException when there are no running app processes. r=ctalbert, a=test-only

This commit is contained in:
Geoff Brown 2012-04-17 19:44:53 -04:00
Родитель 6ebdca02df
Коммит ac9bfd9f1e
2 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -2388,8 +2388,12 @@ private void CancelNotification()
int lcv = 0; int lcv = 0;
String strProcName = ""; String strProcName = "";
int nPID = 0; int nPID = 0;
int nProcs = 0;
for (lcv = 0; lcv < lProcesses.size(); lcv++) if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++)
{ {
if (lProcesses.get(lcv).processName.contains(sProcName)) if (lProcesses.get(lcv).processName.contains(sProcName))
{ {
@ -2441,7 +2445,10 @@ private void CancelNotification()
{ {
sRet = "Successfully killed " + nPID + " " + strProcName + "\n"; sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
lProcesses = aMgr.getRunningAppProcesses(); lProcesses = aMgr.getRunningAppProcesses();
for (lcv = 0; lcv < lProcesses.size(); lcv++) nProcs = 0;
if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++)
{ {
if (lProcesses.get(lcv).processName.contains(sProcName)) if (lProcesses.get(lcv).processName.contains(sProcName))
{ {
@ -2524,12 +2531,15 @@ private void CancelNotification()
String sRet = ""; String sRet = "";
ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE); ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE);
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses(); List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
int nProcs = lProcesses.size(); int nProcs = 0;
int lcv = 0; int lcv = 0;
String strProcName = ""; String strProcName = "";
int nPID = 0; int nPID = 0;
int nUser = 0; int nUser = 0;
if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++) for (lcv = 0; lcv < nProcs; lcv++)
{ {
strProcName = lProcesses.get(lcv).processName; strProcName = lProcesses.get(lcv).processName;

Просмотреть файл

@ -495,10 +495,13 @@ public class WatcherService extends Service
boolean bRet = false; boolean bRet = false;
ActivityManager aMgr = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE); ActivityManager aMgr = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses(); List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
int nProcs = lProcesses.size(); int nProcs = 0;
int lcv = 0; int lcv = 0;
String strProcName = ""; String strProcName = "";
if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++) for (lcv = 0; lcv < nProcs; lcv++)
{ {
strProcName = lProcesses.get(lcv).processName; strProcName = lProcesses.get(lcv).processName;
@ -554,8 +557,12 @@ public class WatcherService extends Service
int lcv = 0; int lcv = 0;
String strProcName = ""; String strProcName = "";
int nPID = 0; int nPID = 0;
int nProcs = 0;
for (lcv = 0; lcv < lProcesses.size(); lcv++) if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++)
{ {
if (lProcesses.get(lcv).processName.contains(sProcName)) if (lProcesses.get(lcv).processName.contains(sProcName))
{ {
@ -598,7 +605,10 @@ public class WatcherService extends Service
{ {
sRet = "Successfully killed " + nPID + " " + strProcName + "\n"; sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
lProcesses = aMgr.getRunningAppProcesses(); lProcesses = aMgr.getRunningAppProcesses();
for (lcv = 0; lcv < lProcesses.size(); lcv++) nProcs = 0;
if (lProcesses != null)
nProcs = lProcesses.size();
for (lcv = 0; lcv < nProcs; lcv++)
{ {
if (lProcesses.get(lcv).processName.contains(sProcName)) if (lProcesses.get(lcv).processName.contains(sProcName))
{ {