FileDocCategorySizeDatePackage
ProcessErrorsTest.javaAPI DocAndroid 1.5 API4126Wed May 06 22:42:02 BST 2009com.android.smoketest

ProcessErrorsTest

public class ProcessErrorsTest extends android.test.AndroidTestCase
This smoke test is designed to quickly sniff for any error conditions encountered after initial startup.

Fields Summary
private final String
TAG
protected android.app.ActivityManager
mActivityManager
Constructors Summary
Methods Summary
private java.lang.StringreportListContents(java.util.List errList)
This helper function will dump the actual error reports.

param
errList The error report containing one or more error records.
return
Returns a string containing all of the errors.

        if (errList == null) return null;

        StringBuilder builder = new StringBuilder();

        Iterator<ActivityManager.ProcessErrorStateInfo> iter = errList.iterator();
        while (iter.hasNext()) {
            ActivityManager.ProcessErrorStateInfo entry = iter.next();

            String condition;
            switch (entry.condition) {
            case ActivityManager.ProcessErrorStateInfo.CRASHED:
                condition = "CRASHED";
                break;
            case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING:
                condition = "ANR";
                break;
            default:
                condition = "<unknown>";
            break;
            }

            String stackTrace = null;
            try {
                if (entry.crashData != null) {
                    CrashData cd = RuntimeInit.unmarshallException(entry.crashData);
                    stackTrace = cd.toString();
                }
            } catch (RuntimeException e) { }
            if (stackTrace == null) {
                stackTrace = "<no stack trace>";
            }

            final String entryReport = "Process error " + condition + " " + entry.shortMsg +
                                        " detected in " + entry.processName + " " + entry.tag + 
                                        ". \n" + stackTrace;

            builder.append(entryReport).append("  ");
        }
        return builder.toString();
    
public voidsetUp()


    
         
        super.setUp();
        mActivityManager = (ActivityManager) 
                getContext().getSystemService(Context.ACTIVITY_SERVICE);
    
public voidtestNoProcessErrors()

        List<ActivityManager.ProcessErrorStateInfo> errList;        
        errList = mActivityManager.getProcessesInErrorState();
        
        // note: this contains information about each process that is currently in an error
        // condition.  if the list is empty (null) then "we're good".  
        
        // if the list is non-empty, then it's useful to report the contents of the list
        // we'll put a copy in the log, and we'll report it back to the framework via the assert.
        final String reportMsg = reportListContents(errList);
        if (reportMsg != null) {
            Log.w(TAG, reportMsg);
        }
        
        // report a non-empty list back to the test framework
        assertNull(reportMsg, errList);
    
public voidtestSetUpConditions()

        assertNotNull(mActivityManager);