@@ -177,13 +177,11 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
177177 percent = fomart .format (((double ) pidMemory / (double ) totalMemorySize ) * 100 );
178178 }
179179
180- // 当应用的cpu使用率大于0时才写入文件中,过滤掉异常数据
181- if (isDouble (processCpuRatio ) && isDouble (totalCpuRatio )) {
180+ if (isPositive (processCpuRatio ) && isPositive (totalCpuRatio )) {
182181 // whether certain device supports traffic statics or not
183- if (traffic == -1 ) {
182+ if (traffic == -1 ) {
184183 EmmageeService .bw .write (mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
185- + totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
186- + "\r \n " );
184+ + totalCpuRatio + "," + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r \n " );
187185 } else {
188186 EmmageeService .bw .write (mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
189187 + totalCpuRatio + "," + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r \n " );
@@ -198,24 +196,24 @@ public ArrayList<String> getCpuRatioInfo(String totalBatt, String currentBatt, S
198196 }
199197 } catch (IOException e ) {
200198 e .printStackTrace ();
201- // PttService.closeOpenedStream()
202199 }
203200 return cpuUsedRatio ;
204201 }
205202
206203 /**
207- * 判断text是否是一个double类型数据
204+ * is text a positive number
208205 *
209206 * @param text
210207 * @return
211208 */
212- private boolean isDouble (String text ) {
209+ private boolean isPositive (String text ) {
210+ Double num ;
213211 try {
214- Double .parseDouble (text );
212+ num = Double .parseDouble (text );
215213 } catch (NumberFormatException e ) {
216214 return false ;
217215 }
218- return true ;
216+ return num >= 0 ;
219217 }
220218
221219}
0 commit comments