From ac9bfd9f1e55bf29c4e25caf6bfd0b28caee8e2e Mon Sep 17 00:00:00 2001 From: Geoff Brown Date: Tue, 17 Apr 2012 19:44:53 -0400 Subject: [PATCH] Bug 745889: SUT agent/watcher - avoid NullPointerException when there are no running app processes. r=ctalbert, a=test-only --- build/mobile/sutagent/android/DoCommand.java | 16 +++++++++++++--- .../sutagent/android/watcher/WatcherService.java | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/build/mobile/sutagent/android/DoCommand.java b/build/mobile/sutagent/android/DoCommand.java index 30155324a41..83b9c839ebd 100755 --- a/build/mobile/sutagent/android/DoCommand.java +++ b/build/mobile/sutagent/android/DoCommand.java @@ -2388,8 +2388,12 @@ private void CancelNotification() int lcv = 0; String strProcName = ""; 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)) { @@ -2441,7 +2445,10 @@ private void CancelNotification() { sRet = "Successfully killed " + nPID + " " + strProcName + "\n"; 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)) { @@ -2524,12 +2531,15 @@ private void CancelNotification() String sRet = ""; ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE); List lProcesses = aMgr.getRunningAppProcesses(); - int nProcs = lProcesses.size(); + int nProcs = 0; int lcv = 0; String strProcName = ""; int nPID = 0; int nUser = 0; + if (lProcesses != null) + nProcs = lProcesses.size(); + for (lcv = 0; lcv < nProcs; lcv++) { strProcName = lProcesses.get(lcv).processName; diff --git a/build/mobile/sutagent/android/watcher/WatcherService.java b/build/mobile/sutagent/android/watcher/WatcherService.java index 86c3b027700..5a1350afa6d 100644 --- a/build/mobile/sutagent/android/watcher/WatcherService.java +++ b/build/mobile/sutagent/android/watcher/WatcherService.java @@ -495,10 +495,13 @@ public class WatcherService extends Service boolean bRet = false; ActivityManager aMgr = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE); List lProcesses = aMgr.getRunningAppProcesses(); - int nProcs = lProcesses.size(); + int nProcs = 0; int lcv = 0; String strProcName = ""; + if (lProcesses != null) + nProcs = lProcesses.size(); + for (lcv = 0; lcv < nProcs; lcv++) { strProcName = lProcesses.get(lcv).processName; @@ -554,8 +557,12 @@ public class WatcherService extends Service int lcv = 0; String strProcName = ""; 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)) { @@ -598,7 +605,10 @@ public class WatcherService extends Service { sRet = "Successfully killed " + nPID + " " + strProcName + "\n"; 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)) {