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

Commit d5ccb03

Browse files
committed
Set $TMPDIR as well as java.io.tmpdir.
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
1 parent e34b1b8 commit d5ccb03

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

core/java/android/app/ActivityThread.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -6299,7 +6299,13 @@ private void setupGraphicsSupport(Context context) {
62996299
final File cacheDir = context.getCacheDir();
63006300
if (cacheDir != null) {
63016301
// Provide a usable directory for temporary files
6302-
System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath());
6302+
String tmpdir = cacheDir.getAbsolutePath();
6303+
System.setProperty("java.io.tmpdir", tmpdir);
6304+
try {
6305+
android.system.Os.setenv("TMPDIR", tmpdir, true);
6306+
} catch (ErrnoException ex) {
6307+
Log.w(TAG, "Unable to initialize $TMPDIR", ex);
6308+
}
63036309
} else {
63046310
Log.v(TAG, "Unable to initialize \"java.io.tmpdir\" property "
63056311
+ "due to missing cache directory");

core/tests/coretests/src/android/app/activity/ActivityThreadTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public class ActivityThreadTest {
8787
new ActivityTestRule<>(TestActivity.class, true /* initialTouchMode */,
8888
false /* launchActivity */);
8989

90+
@Test
91+
public void testTemporaryDirectory() throws Exception {
92+
assertEquals(System.getProperty("java.io.tmpdir"), System.getenv("TMPDIR"));
93+
}
94+
9095
@Test
9196
public void testDoubleRelaunch() throws Exception {
9297
final Activity activity = mActivityTestRule.launchActivity(new Intent());

0 commit comments

Comments
 (0)