diff options
author | Yabin Cui <yabinc@google.com> | 2017-02-15 18:42:12 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-02-15 18:42:12 +0000 |
commit | 1653ecc3553efcf9f5c91ba0bd2530e7a4fbd5df (patch) | |
tree | db6cccb5f854d4eeed95ae4e9ecebe22352f2c84 | |
parent | 192dd54bbd15c048a6478e4e8585a7e2603b55ce (diff) | |
parent | 7cc9a395fc1d9a97324afea72b004c1b51d35594 (diff) | |
download | googletest-1653ecc3553efcf9f5c91ba0bd2530e7a4fbd5df.tar.gz |
gtest: fix Android temp dir. am: 5f9167db37 am: 664afb1eb4
am: 7cc9a395fc
Change-Id: I7fdc0b8a066b018eec2990e1c6da986fc8f63fe3
-rw-r--r-- | googletest/src/gtest-port.cc | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 0162fac4..e8f8d89a 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -952,24 +952,10 @@ class CapturedStream { # else // There's no guarantee that a test has write access to the current // directory, so we create the temporary file in the /tmp directory - // instead. We use /tmp on most systems, and /sdcard on Android. - // That's because Android doesn't have /tmp. + // instead. # if GTEST_OS_LINUX_ANDROID - // Note: Android applications are expected to call the framework's - // Context.getExternalStorageDirectory() method through JNI to get - // the location of the world-writable SD Card directory. However, - // this requires a Context handle, which cannot be retrieved - // globally from native code. Doing so also precludes running the - // code as part of a regular standalone executable, which doesn't - // run in a Dalvik process (e.g. when running it through 'adb shell'). - // - // The location /sdcard is directly accessible from native code - // and is the only location (unofficially) supported by the Android - // team. It's generally a symlink to the real SD Card mount point - // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or - // other OEM-customized locations. Never rely on these, and always - // use /sdcard. - char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX"; + ::std::string name_template_buf = TempDir() + "gtest_captured_stream.XXXXXX"; + char* name_template = &name_template_buf[0]; # else char name_template[] = "/tmp/captured_stream.XXXXXX"; # endif // GTEST_OS_LINUX_ANDROID @@ -1067,7 +1053,22 @@ std::string TempDir() { else return std::string(temp_dir) + "\\"; #elif GTEST_OS_LINUX_ANDROID - return "/sdcard/"; + // Android doesn't have /tmp, and /sdcard is no longer accessible from + // app context starting from Android O. On Android, /data/local/tmp + // is usually used as the temporary directory. But processes running + // in app context can't write to /data/local/tmp, so also try the + // current directory. + if (access("/data/local/tmp", R_OK | W_OK | X_OK) == 0) { + return "/data/local/tmp/"; + } + std::string result = "./"; + char* cwd = getcwd(NULL, 0); + if (cwd != NULL) { + result = cwd; + result += "/"; + free(cwd); + } + return result; #else return "/tmp/"; #endif // GTEST_OS_WINDOWS_MOBILE |