crashanalysis/crashanalyser/com.nokia.s60tools.crashanalyser/src/com/nokia/s60tools/crashanalyser/containers/Summary.java
changeset 4 615035072f7e
parent 0 5ad7ad99af01
child 16 72f198be1c1d
equal deleted inserted replaced
3:431bbaccaec8 4:615035072f7e
    34 	// XML tags
    34 	// XML tags
    35 	public static final String TAG_SEG_HEADER = "seg_header";
    35 	public static final String TAG_SEG_HEADER = "seg_header";
    36 	public static final String TAG_DATE = "date";
    36 	public static final String TAG_DATE = "date";
    37 	public static final String TAG_TIME = "time";
    37 	public static final String TAG_TIME = "time";
    38 	public static final String TAG_UPTIME = "uptime";
    38 	public static final String TAG_UPTIME = "uptime";
       
    39 	public static final String TAG_CRASH_SOURCE = "crash_source";
    39 	public static final String TAG_SEG_HW_INFO = "seg_hw_info";
    40 	public static final String TAG_SEG_HW_INFO = "seg_hw_info";
    40 	public static final String TAG_VERSION = "version_text";
    41 	public static final String TAG_VERSION = "version_text";
    41 	public static final String TAG_VERSIONS = "version_text_list";
    42 	public static final String TAG_VERSIONS = "version_text_list";
    42 	public static final String TAG_PRODUCT_TYPE = "product_type";
    43 	public static final String TAG_PRODUCT_TYPE = "product_type";
    43 	public static final String TAG_PRODUCT_CODE = "product_code";
    44 	public static final String TAG_PRODUCT_CODE = "product_code";
    44 	public static final String TAG_SERIAL_NUMBER = "serial_number";
    45 	public static final String TAG_SERIAL_NUMBER = "serial_number";
       
    46 	public static final String TAG_PRODUCTION_MODE = "production_mode";
    45 	public static final String TAG_SEG_SW_INFO = "seg_sw_info";
    47 	public static final String TAG_SEG_SW_INFO = "seg_sw_info";
    46 	public static final String TAG_LANGUAGE = "language";
    48 	public static final String TAG_LANGUAGE = "language";
    47 	public static final String TAG_CHECKSUM = "checksum";
    49 	public static final String TAG_CHECKSUM = "checksum";
    48 	public static final String TAG_IMEI = "imei";
    50 	public static final String TAG_IMEI = "imei";
    49 	public static final String TAG_SEG_MEMORY_INFO = "seg_memory_info";
    51 	public static final String TAG_SEG_MEMORY_INFO = "seg_memory_info";
    50 	public static final String TAG_RAM = "ram";
    52 	public static final String TAG_RAM = "ram";
       
    53 	public static final String TAG_DRIVE = "drive";
    51 	public static final String TAG_FREE = "free";
    54 	public static final String TAG_FREE = "free";
    52 	
    55 	
    53 	public static final String FORMAT = "%-15s: %s";
    56 	public static final String FORMAT = "%-15s: %s";
    54 
    57 
    55 	// Data
    58 	// Data
    63 	private final String summaryProductType;
    66 	private final String summaryProductType;
    64 	private final String summaryProductCode;
    67 	private final String summaryProductCode;
    65 	private final String summarySerialNumber;
    68 	private final String summarySerialNumber;
    66 	private final String summaryImei;
    69 	private final String summaryImei;
    67 	private final String summaryFreeRam;
    70 	private final String summaryFreeRam;
       
    71 	private final String summaryFreeDisk;
       
    72 	private final String summaryProductionMode;
       
    73 	private final String summaryCrashSource;
    68 	
    74 	
    69 	private Summary(String crashTime, String crashDate, String upTime, String[] swVersion, String language,
    75 	private Summary(String crashTime, String crashDate, String upTime, String[] swVersion, String language,
    70 					String romId, String[] hwVersion, String productType, String productCode, 
    76 					String romId, String[] hwVersion, String productType, String productCode, 
    71 					String serialNumber, String imei, String freeRam) {
    77 					String serialNumber, String productionMode, String crashSource, String imei, String freeRam, String freeDisk) {
    72 		summaryCrashTime = crashTime;
    78 		summaryCrashTime = crashTime;
    73 		summaryCrashDate = crashDate;
    79 		summaryCrashDate = crashDate;
    74 		summaryUpTime = upTime;
    80 		summaryUpTime = upTime;
    75 		summarySwVersion = swVersion.clone();
    81 		summarySwVersion = swVersion.clone();
    76 		summaryLanguage = language;
    82 		summaryLanguage = language;
    79 		summaryProductType = productType;
    85 		summaryProductType = productType;
    80 		summaryProductCode = productCode;
    86 		summaryProductCode = productCode;
    81 		summarySerialNumber = serialNumber;
    87 		summarySerialNumber = serialNumber;
    82 		summaryImei = imei;
    88 		summaryImei = imei;
    83 		summaryFreeRam = freeRam;
    89 		summaryFreeRam = freeRam;
       
    90 		summaryFreeDisk = freeDisk;
       
    91 		summaryProductionMode = productionMode;
       
    92 		summaryCrashSource = crashSource;
    84 	}
    93 	}
    85 	
    94 	
    86 	/**
    95 	/**
    87 	 * Writes summary data into given buffer (i.e. text file)
    96 	 * Writes summary data into given buffer (i.e. text file)
    88 	 * @param out
    97 	 * @param out
   107 		writeLine(out, "Product Type", summaryProductType);
   116 		writeLine(out, "Product Type", summaryProductType);
   108 		writeLine(out, "Product Code", summaryProductCode);
   117 		writeLine(out, "Product Code", summaryProductCode);
   109 		writeLine(out, "Serial Number", summarySerialNumber);
   118 		writeLine(out, "Serial Number", summarySerialNumber);
   110 		writeLine(out, "Imei", summaryImei);
   119 		writeLine(out, "Imei", summaryImei);
   111 		writeLine(out, "Free Ram", summaryFreeRam);
   120 		writeLine(out, "Free Ram", summaryFreeRam);
       
   121 		writeLine(out, "Free Disk Space", summaryFreeDisk);
       
   122 		writeLine(out, "Production Mode", summaryProductionMode);
       
   123 		writeLine(out, "Crash Source", summaryCrashSource);
   112 	}
   124 	}
   113 	
   125 	
   114 	void writeLine(BufferedWriter out, String header, String value) throws IOException {
   126 	void writeLine(BufferedWriter out, String header, String value) throws IOException {
   115 		if (!"".equals(value)) {
   127 		if (!"".equals(value)) {
   116 			out.write(String.format(FORMAT, header, value));
   128 			out.write(String.format(FORMAT, header, value));
   126 	public static Summary read(Element rootElement) {
   138 	public static Summary read(Element rootElement) {
   127 		try {
   139 		try {
   128 			String crashTime = "";
   140 			String crashTime = "";
   129 			String crashDate = "";
   141 			String crashDate = "";
   130 			String upTime = "";
   142 			String upTime = "";
       
   143 			String crashSource = "";
   131 			
   144 			
   132 			// read data under seg_header node
   145 			// read data under seg_header node
   133 			NodeList segHeader = rootElement.getElementsByTagName(TAG_SEG_HEADER);
   146 			NodeList segHeader = rootElement.getElementsByTagName(TAG_SEG_HEADER);
   134 			if (segHeader != null && segHeader.getLength() > 0) {
   147 			if (segHeader != null && segHeader.getLength() > 0) {
   135 				// read crash time
   148 				// read crash time
   159 				if (upTime == null) {
   172 				if (upTime == null) {
   160 					upTime = "";
   173 					upTime = "";
   161 				} else {
   174 				} else {
   162 					upTime = convertUpTime(upTime);
   175 					upTime = convertUpTime(upTime);
   163 				}
   176 				}
       
   177 				
       
   178 				// read crash source
       
   179 				crashSource = XmlUtils.getTextValue((Element)segHeader.item(0), TAG_CRASH_SOURCE);
       
   180 				if(crashSource == null)
       
   181 					crashSource = "";
   164 			}
   182 			}
   165 			
   183 			
   166 			List<String> hwVersions = new ArrayList<String>();
   184 			List<String> hwVersions = new ArrayList<String>();
   167 			String productType = "";
   185 			String productType = "";
   168 			String productCode = "";
   186 			String productCode = "";
   169 			String serialNumber = "";
   187 			String serialNumber = "";
       
   188 			String productionMode = "";
   170 			
   189 			
   171 			// read data under seg_hw_info node
   190 			// read data under seg_hw_info node
   172 			NodeList segHwInfo = rootElement.getElementsByTagName(TAG_SEG_HW_INFO);
   191 			NodeList segHwInfo = rootElement.getElementsByTagName(TAG_SEG_HW_INFO);
   173 			if (segHwInfo != null && segHwInfo.getLength() > 0) {
   192 			if (segHwInfo != null && segHwInfo.getLength() > 0) {
   174 
   193 
   195 				
   214 				
   196 				// read serial number
   215 				// read serial number
   197 				serialNumber = XmlUtils.getTextValue((Element)segHwInfo.item(0), TAG_SERIAL_NUMBER);
   216 				serialNumber = XmlUtils.getTextValue((Element)segHwInfo.item(0), TAG_SERIAL_NUMBER);
   198 				if (serialNumber == null)
   217 				if (serialNumber == null)
   199 					serialNumber = "";
   218 					serialNumber = "";
       
   219 
       
   220 				// read production mode
       
   221 				productionMode = XmlUtils.getTextValue((Element)segHwInfo.item(0), TAG_PRODUCTION_MODE);
       
   222 				if (productionMode == null)
       
   223 					productionMode = "";
   200 			}
   224 			}
   201 			
   225 			
   202 			List<String> swVersions = new ArrayList<String>();
   226 			List<String> swVersions = new ArrayList<String>();
   203 			String language = "";
   227 			String language = "";
   204 			String romId = "";
   228 			String romId = "";
   235 			if (imeiNode != null && imeiNode.getLength() > 0) {
   259 			if (imeiNode != null && imeiNode.getLength() > 0) {
   236 				imei = imeiNode.item(0).getFirstChild().getNodeValue();
   260 				imei = imeiNode.item(0).getFirstChild().getNodeValue();
   237 			}
   261 			}
   238 			
   262 			
   239 			String freeRamAmount = "";
   263 			String freeRamAmount = "";
       
   264 			String freeDiskSpace = "";
       
   265 			
   240 			// read free ram amount
   266 			// read free ram amount
   241 			NodeList segMemoryInfo = rootElement.getElementsByTagName(TAG_SEG_MEMORY_INFO);
   267 			NodeList segMemoryInfo = rootElement.getElementsByTagName(TAG_SEG_MEMORY_INFO);
   242 			if (segMemoryInfo != null && segMemoryInfo.getLength() > 0) {
   268 			if (segMemoryInfo != null && segMemoryInfo.getLength() > 0) {
   243 				NodeList ram = ((Element)segMemoryInfo.item(0)).getElementsByTagName(TAG_RAM);
   269 				NodeList ram = ((Element)segMemoryInfo.item(0)).getElementsByTagName(TAG_RAM);
   244 				if (ram != null && ram.getLength() > 0) {
   270 				if (ram != null && ram.getLength() > 0) {
   245 					freeRamAmount = XmlUtils.getTextValue((Element)ram.item(0), TAG_FREE);
   271 					freeRamAmount = XmlUtils.getTextValue((Element)ram.item(0), TAG_FREE);
   246 					if (freeRamAmount == null)
   272 					if (freeRamAmount == null)
   247 						freeRamAmount = "";
   273 						freeRamAmount = "";
   248 				}
   274 				}
       
   275 				NodeList drive = ((Element)segMemoryInfo.item(0)).getElementsByTagName(TAG_DRIVE);
       
   276 				if (drive != null && drive.getLength() > 0) {
       
   277 					freeDiskSpace = XmlUtils.getTextValue((Element)drive.item(0), TAG_FREE);
       
   278 					if (freeDiskSpace == null)
       
   279 						freeDiskSpace = "";
       
   280 				}
   249 			}
   281 			}
   250 			
   282 			
   251 			return new Summary(crashTime, crashDate, upTime, swVersions.toArray(new String[swVersions.size()]), 
   283 			return new Summary(crashTime, crashDate, upTime, swVersions.toArray(new String[swVersions.size()]), 
   252 								language, romId, hwVersions.toArray(new String[hwVersions.size()]), productType, productCode, serialNumber, imei, freeRamAmount);
   284 								language, romId, hwVersions.toArray(new String[hwVersions.size()]), productType, 
       
   285 								productCode, serialNumber, productionMode, crashSource, imei, freeRamAmount, freeDiskSpace);
   253 		} catch (Exception e) {
   286 		} catch (Exception e) {
   254 			return null;
   287 			return null;
   255 		}
   288 		}
   256 	}
   289 	}
   257 	
   290 	
   300 	}
   333 	}
   301 	
   334 	
   302 	public String getFreeRam() {
   335 	public String getFreeRam() {
   303 		return summaryFreeRam;
   336 		return summaryFreeRam;
   304 	}
   337 	}
       
   338 
       
   339 	public String getFreeDisk() {
       
   340 		return summaryFreeDisk;
       
   341 	}
       
   342 
       
   343 	public String getProductionMode() {
       
   344 		return summaryProductionMode;
       
   345 	}
       
   346 	
       
   347 	public String getCrashSource() {
       
   348 		return summaryCrashSource;
       
   349 	}
       
   350 
   305 	
   351 	
   306 	static String convertUpTime(String uptime) {
   352 	static String convertUpTime(String uptime) {
   307 		try {
   353 		try {
   308 			int secs =Integer.valueOf(uptime); 
   354 			int secs =Integer.valueOf(uptime); 
   309 			int hours =  secs / 3600,
   355 			int hours =  secs / 3600,