1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
private int run(String[] args) {
...
if (mMainCategories.size() == 0) { mMainCategories.add(Intent.CATEGORY_LAUNCHER); mMainCategories.add(Intent.CATEGORY_MONKEY); } if (mSeed == 0) { mSeed = System.currentTimeMillis() + System.identityHashCode(this); } if (mVerbose > 0) { Logger.out.println(":Monkey: seed=" + mSeed + " count=" + mCount); MonkeyUtils.getPackageFilter().dump(); if (mMainCategories.size() != 0) { Iterator<String> it = mMainCategories.iterator(); while (it.hasNext()) { Logger.out.println(":IncludeCategory: " + it.next()); } } } if (!checkInternalConfiguration()) { return -2; } if (!getSystemInterfaces()) { return -3; } if (!getMainApps()) { return -4; } mRandom = new Random(mSeed); if (mScriptFileNames != null && mScriptFileNames.size() == 1) { mEventSource = new MonkeySourceScript(mRandom, mScriptFileNames.get(0), mThrottle, mRandomizeThrottle, mProfileWaitTime, mDeviceSleepTime); mEventSource.setVerbose(mVerbose); mCountEvents = false; } else if (mScriptFileNames != null && mScriptFileNames.size() > 1) { if (mSetupFileName != null) { mEventSource = new MonkeySourceRandomScript(mSetupFileName, mScriptFileNames, mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime, mRandomizeScript); mCount++; } else { mEventSource = new MonkeySourceRandomScript(mScriptFileNames, mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime, mRandomizeScript); } mEventSource.setVerbose(mVerbose); mCountEvents = false; } else if (mServerPort != -1) { try { mEventSource = new MonkeySourceNetwork(mServerPort); } catch (IOException e) { Logger.out.println("Error binding to network socket."); return -5; } mCount = Integer.MAX_VALUE; } else { if (mVerbose >= 2) { Logger.out.println("// Seeded: " + mSeed); } mEventSource = new MonkeySourceRandom(mRandom, mMainApps, mThrottle, mRandomizeThrottle, mPermissionTargetSystem); mEventSource.setVerbose(mVerbose); for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) { if (mFactors[i] <= 0.0f) { ((MonkeySourceRandom) mEventSource).setFactors(i, mFactors[i]); } } ((MonkeySourceRandom) mEventSource).generateActivity(); } if (!mEventSource.validate()) { return -5; } if (mGenerateHprof) { signalPersistentProcesses(); } mNetworkMonitor.start(); int crashedAtCycle = 0; try { crashedAtCycle = runMonkeyCycles(); } finally { new MonkeyRotationEvent(Surface.ROTATION_0, false).injectEvent( mWm, mAm, mVerbose); } mNetworkMonitor.stop(); synchronized (this) { if (mRequestAnrTraces) { reportAnrTraces(); mRequestAnrTraces = false; } if (mRequestAnrBugreport){ Logger.out.println("Print the anr report"); getBugreport("anr_" + mReportProcessName + "_"); mRequestAnrBugreport = false; } if (mRequestWatchdogBugreport) { Logger.out.println("Print the watchdog report"); getBugreport("anr_watchdog_"); mRequestWatchdogBugreport = false; } if (mRequestAppCrashBugreport){ getBugreport("app_crash" + mReportProcessName + "_"); mRequestAppCrashBugreport = false; } if (mRequestDumpsysMemInfo) { reportDumpsysMemInfo(); mRequestDumpsysMemInfo = false; } if (mRequestPeriodicBugreport){ getBugreport("Bugreport_"); mRequestPeriodicBugreport = false; } if (mWatchdogWaiting) { mWatchdogWaiting = false; notifyAll(); } } if (mGenerateHprof) { signalPersistentProcesses(); if (mVerbose > 0) { Logger.out.println("// Generated profiling reports in /data/misc"); } } try { mAm.setActivityController(null, true); mNetworkMonitor.unregister(mAm); } catch (RemoteException e) { if (crashedAtCycle >= mCount) { crashedAtCycle = mCount - 1; } } if (mVerbose > 0) { Logger.out.println(":Dropped: keys=" + mDroppedKeyEvents + " pointers=" + mDroppedPointerEvents + " trackballs=" + mDroppedTrackballEvents + " flips=" + mDroppedFlipEvents + " rotations=" + mDroppedRotationEvents); } mNetworkMonitor.dump(); if (crashedAtCycle < mCount - 1) { Logger.err.println("** System appears to have crashed at event " + crashedAtCycle + " of " + mCount + " using seed " + mSeed); return crashedAtCycle; } else { if (mVerbose > 0) { Logger.out.println("// Monkey finished"); } return 0; } }
|