List of usage examples for android.os Environment getLegacyExternalStorageDirectory
@UnsupportedAppUsage public static File getLegacyExternalStorageDirectory()
From source file:org.wso2.emm.agent.api.RuntimeInfo.java
/** * Returns the device LogCat//from w ww. j ava2s . c om */ public String getLogCat(String logLevel) { String filePath = Environment.getLegacyExternalStorageDirectory() + "/logcat.log"; try { String[] cmd = new String[] { "logcat", "-d", "-v", "time", logLevel }; Process process = Runtime.getRuntime().exec(cmd); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; PrintWriter writer = new PrintWriter(filePath, "UTF-8"); while ((line = bufferedReader.readLine()) != null) { writer.println(line); } writer.close(); } catch (IOException e) { Log.e(TAG, "getLog failed", e); } return filePath; }
From source file:org.wso2.emm.system.service.EMMSystemService.java
/** * Returns the device LogCat//w ww . j av a 2 s . c o m */ public void getLogCat(String command) { try { JSONObject commandObj = new JSONObject(command); String filePath = Environment.getLegacyExternalStorageDirectory() + "/logcat" + commandObj.getInt("operation_id") + ".log"; String[] cmd = new String[] { "logcat", "-d", "-v", "time", commandObj.getString("log_level") }; Process process = Runtime.getRuntime().exec(cmd); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; PrintWriter writer = new PrintWriter(filePath, "UTF-8"); while ((line = bufferedReader.readLine()) != null) { writer.println(line); } writer.close(); CommonUtils.callAgentApp(context, Constants.Operation.LOGCAT, commandObj.getInt("operation_id"), filePath); } catch (IOException e) { Log.e(TAG, "getLog failed", e); } catch (JSONException e) { Log.e(TAG, "Unable to parse command string", e); } }
From source file:com.android.server.MountService.java
@VisibleForTesting public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) { // TODO: allow caller to provide Environment for full testing // TODO: extend to support OBB mounts on secondary external storage // Only adjust paths when storage is emulated if (!Environment.isExternalStorageEmulated()) { return canonicalPath; }// w w w. j a va 2s. c o m String path = canonicalPath.toString(); // First trim off any external storage prefix final UserEnvironment userEnv = new UserEnvironment(userId); // /storage/emulated/0 final String externalPath = userEnv.getExternalStorageDirectory().getAbsolutePath(); // /storage/emulated_legacy final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory().getAbsolutePath(); if (path.startsWith(externalPath)) { path = path.substring(externalPath.length() + 1); } else if (path.startsWith(legacyExternalPath)) { path = path.substring(legacyExternalPath.length() + 1); } else { return canonicalPath; } // Handle special OBB paths on emulated storage final String obbPath = "Android/obb"; if (path.startsWith(obbPath)) { path = path.substring(obbPath.length() + 1); if (forVold) { return new File(Environment.getEmulatedStorageObbSource(), path).getAbsolutePath(); } else { final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER); return new File(ownerEnv.buildExternalStorageAndroidObbDirs()[0], path).getAbsolutePath(); } } // Handle normal external storage paths if (forVold) { return new File(Environment.getEmulatedStorageSource(userId), path).getAbsolutePath(); } else { return new File(userEnv.getExternalDirsForApp()[0], path).getAbsolutePath(); } }