Merge "Set $TMPDIR as well as java.io.tmpdir."

This commit is contained in:
Elliott Hughes
2021-09-14 16:49:24 +00:00
committed by Gerrit Code Review
2 changed files with 12 additions and 1 deletions

View File

@@ -6299,7 +6299,13 @@ public final class ActivityThread extends ClientTransactionHandler {
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");

View File

@@ -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());