Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Set $TMPDIR as well as java.io.tmpdir.
Browse files Browse the repository at this point in the history
This helps functions like tmpnam() and tmpfile() to "just work", like
their Java equivalents.

Bug: https://issuetracker.google.com/36991167
Bug: http://b/174682340
Test: atest FrameworksCoreTests:android.app.activity.ActivityThreadTest
Change-Id: Ife785f0ca69a34ba2c6b5d1e8e23f8b883d8fc8f
  • Loading branch information
enh-google committed Sep 8, 2021
1 parent e34b1b8 commit d5ccb03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/java/android/app/ActivityThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -6299,7 +6299,13 @@ private void setupGraphicsSupport(Context context) {
final File cacheDir = context.getCacheDir();
if (cacheDir != null) {
// Provide a usable directory for temporary files
System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath());
String tmpdir = cacheDir.getAbsolutePath();
System.setProperty("java.io.tmpdir", tmpdir);
try {
android.system.Os.setenv("TMPDIR", tmpdir, true);
} catch (ErrnoException ex) {
Log.w(TAG, "Unable to initialize $TMPDIR", ex);
}
} else {
Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property "
+ "due to missing cache directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public class ActivityThreadTest {
new ActivityTestRule<>(TestActivity.class, true /* initialTouchMode */,
false /* launchActivity */);

@Test
public void testTemporaryDirectory() throws Exception {
assertEquals(System.getProperty("java.io.tmpdir"), System.getenv("TMPDIR"));
}

@Test
public void testDoubleRelaunch() throws Exception {
final Activity activity = mActivityTestRule.launchActivity(new Intent());
Expand Down

0 comments on commit d5ccb03

Please sign in to comment.