/** * Returns the appropriate working directory for storing application data. The result of this * method is platform dependant: On linux, it will return ~/applicationName, on windows, the * working directory will be located in the user's application data folder. For Mac OS systems, * the working directory will be placed in the proper location in "Library/Application Support". * * <p>This method will also make sure that the working directory exists. When invoked, the * directory and all required subfolders will be created. * * @param applicationName Name of the application, used to determine the working directory. * @return the appropriate working directory for storing application data. */ public static File getWorkingDirectory(final String applicationName) { final String userHome = System.getProperty("user.home", "."); final File workingDirectory; switch (SysInfo.getPlatform()) { case LINUX: case SOLARIS: workingDirectory = new File(userHome, '.' + applicationName + '/'); break; case WINDOWS: final String applicationData = System.getenv("APPDATA"); if (applicationData != null) workingDirectory = new File(applicationData, "." + applicationName + '/'); else workingDirectory = new File(userHome, '.' + applicationName + '/'); break; case MACOS: workingDirectory = new File(userHome, "Library/Application Support/" + applicationName); break; default: return new File("."); } if (!workingDirectory.exists()) if (!workingDirectory.mkdirs()) throw new RuntimeException( "The working directory could not be created: " + workingDirectory); return workingDirectory; }
private static void processTraces(Reader traces, File pingFile) { // Only get native stack if Gecko is running. // Also, unwinding is memory intensive, so only unwind if we have enough memory. final boolean haveNativeStack = GeckoThread.isRunning() ? requestNativeStack(/* unwind */ SysInfo.getMemSize() >= 640) : false; try { OutputStream ping = new BufferedOutputStream(new FileOutputStream(pingFile), TRACES_BLOCK_SIZE); try { fillPingHeader(ping, pingFile.getName()); // Traces file has the format // ----- pid xxx at xxx ----- // Cmd line: org.mozilla.xxx // * stack trace * // ----- end xxx ----- // ----- pid xxx at xxx ----- // Cmd line: com.android.xxx // * stack trace * // ... // If we end the stack dump at the first end marker, // only Fennec stacks will be dumped int size = fillPingBlock(ping, traces, "\n----- end"); if (DEBUG) { Log.d(LOGTAG, "wrote traces, size = " + String.valueOf(size)); } fillPingFooter(ping, haveNativeStack); if (DEBUG) { Log.d(LOGTAG, "finished creating ping file"); } return; } finally { ping.close(); if (haveNativeStack) { releaseNativeStack(); } } } catch (IOException e) { Log.w(LOGTAG, e); } // exception; delete ping file if (pingFile.exists()) { pingFile.delete(); } }
private static void fillPingHeader(OutputStream ping, String slug) throws IOException { // ping file header byte[] data = ("{" + "\"reason\":\"android-anr-report\"," + "\"slug\":" + JSONObject.quote(slug) + "," + "\"payload\":") .getBytes(PING_CHARSET); ping.write(data); if (DEBUG) { Log.d(LOGTAG, "wrote ping header, size = " + String.valueOf(data.length)); } // payload start int size = writePingPayload( ping, ("{" + "\"ver\":1," + "\"simpleMeasurements\":{" + "\"uptime\":" + String.valueOf(getUptimeMins()) + "}," + "\"info\":{" + "\"reason\":\"android-anr-report\"," + "\"OS\":" + JSONObject.quote(SysInfo.getName()) + "," + "\"version\":\"" + String.valueOf(SysInfo.getVersion()) + "\"," + "\"appID\":" + JSONObject.quote(AppConstants.MOZ_APP_ID) + "," + "\"appVersion\":" + JSONObject.quote(AppConstants.MOZ_APP_VERSION) + "," + "\"appName\":" + JSONObject.quote(AppConstants.MOZ_APP_BASENAME) + "," + "\"appBuildID\":" + JSONObject.quote(AppConstants.MOZ_APP_BUILDID) + "," + "\"appUpdateChannel\":" + JSONObject.quote(AppConstants.MOZ_UPDATE_CHANNEL) + "," + // Technically the platform build ID may be different, but we'll never know "\"platformBuildID\":" + JSONObject.quote(AppConstants.MOZ_APP_BUILDID) + "," + "\"locale\":" + JSONObject.quote(Locales.getLanguageTag(Locale.getDefault())) + "," + "\"cpucount\":" + String.valueOf(SysInfo.getCPUCount()) + "," + "\"memsize\":" + String.valueOf(SysInfo.getMemSize()) + "," + "\"arch\":" + JSONObject.quote(SysInfo.getArchABI()) + "," + "\"kernel_version\":" + JSONObject.quote(SysInfo.getKernelVersion()) + "," + "\"device\":" + JSONObject.quote(SysInfo.getDevice()) + "," + "\"manufacturer\":" + JSONObject.quote(SysInfo.getManufacturer()) + "," + "\"hardware\":" + JSONObject.quote(SysInfo.getHardware()) + "}," + "\"androidANR\":\"")); if (DEBUG) { Log.d(LOGTAG, "wrote metadata, size = " + String.valueOf(size)); } // We are at the start of ANR data }
public static SysInfo getSysInfo() { SysInfo sysInfo = new SysInfo(); sysInfo.SerciveHost = getPrefs().getString(PREF_KEY_ServiceHost, "192.168.1.105"); return sysInfo; }