Bug 845342 - Move about:memory and related dump files to the downloads dir on android. r=njn a=lsblakk
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -127,19 +127,16 @@
#include "nsXPCOMPrivate.h"
#include "sampler.h"
#include <stdio.h>
#include <string.h>
#ifdef WIN32
#include <io.h>
#include <process.h>
#endif
-#ifdef ANDROID
-#include <sys/stat.h>
-#endif
#ifdef XP_WIN
#include <windows.h>
#endif
#include "mozilla/CondVar.h"
#include "mozilla/Likely.h"
#include "mozilla/Mutex.h"
@@ -1595,45 +1592,42 @@ private:
{
nsPrintfCString filename("%s.%d%s%s.log",
aPrefix,
base::GetCurrentProcId(),
mFilenameIdentifier.IsEmpty() ? "" : ".",
NS_ConvertUTF16toUTF8(mFilenameIdentifier).get());
// Get the log directory either from $MOZ_CC_LOG_DIRECTORY or from our
- // platform's temp directory.
+ // platform's temp directory. For Android, first try the downloads
+ // directory which is world-readable rather than the temp directory
+ // which is not.
nsCOMPtr<nsIFile> logFile;
- if (char* env = PR_GetEnv("MOZ_CC_LOG_DIRECTORY")) {
+ char* env;
+ if (env = PR_GetEnv("MOZ_CC_LOG_DIRECTORY")) {
NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
getter_AddRefs(logFile));
- } else {
+ }
+#ifdef ANDROID
+ if (!logFile && (env = PR_GetEnv("DOWNLOADS_DIRECTORY"))) {
+ NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true,
+ getter_AddRefs(logFile));
+ }
+#endif
+ if (!logFile) {
// Ask NSPR to point us to the temp directory.
NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(logFile));
}
NS_ENSURE_TRUE(logFile, nullptr);
nsresult rv = logFile->AppendNative(filename);
NS_ENSURE_SUCCESS(rv, nullptr);
rv = logFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
NS_ENSURE_SUCCESS(rv, nullptr);
-#ifdef ANDROID
- {
- // On android the default system umask is 0077 which makes these files
- // unreadable to the shell user. In order to pull the dumps off a non-rooted
- // device we need to chmod them to something world-readable.
- // XXX why not logFile->SetPermissions(0644);
- nsAutoCString path;
- rv = logFile->GetNativePath(path);
- if (NS_SUCCEEDED(rv)) {
- chmod(path.get(), 0644);
- }
- }
-#endif
return logFile.forget();
}
FILE *mStream;
nsCOMPtr<nsIFile> mOutFile;
bool mWantAllTraces;
bool mDisableLog;
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -478,39 +478,36 @@ MakeFilename(const char *aPrefix, const
aPrefix,
NS_ConvertUTF16toUTF8(aIdentifier).get(),
getpid(), aSuffix);
}
static nsresult
OpenTempFile(const nsACString &aFilename, nsIFile* *aFile)
{
- nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
- NS_ENSURE_SUCCESS(rv, rv);
+#ifdef ANDROID
+ // For Android, first try the downloads directory which is world-readable
+ // rather than the temp directory which is not.
+ if (char *env = PR_GetEnv("DOWNLOADS_DIRECTORY")) {
+ NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true, aFile);
+ }
+#endif
+ nsresult rv;
+ if (!*aFile) {
+ rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
nsCOMPtr<nsIFile> file(*aFile);
rv = file->AppendNative(aFilename);
NS_ENSURE_SUCCESS(rv, rv);
rv = file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
NS_ENSURE_SUCCESS(rv, rv);
-#ifdef ANDROID
- {
- // On android the default system umask is 0077 which makes these files
- // unreadable to the shell user. In order to pull the dumps off a non-rooted
- // device we need to chmod them to something world-readable.
- // XXX why not logFile->SetPermissions(0644);
- nsAutoCString path;
- rv = file->GetNativePath(path);
- if (NS_SUCCEEDED(rv)) {
- chmod(path.get(), 0644);
- }
- }
-#endif
return NS_OK;
}
#ifdef MOZ_DMD
struct DMDWriteState
{
static const size_t kBufSize = 4096;
char mBuf[kBufSize];