Proper fix for java.io.tmpdir/user.home mutability

Fix for java.io.tmpdir and user.home property (in the
System.initProperties) being set as a immutable default.

Change-Id: Ic74a990fb4a472a62f52552c4a8c339adf92aafb
diff --git a/ojluni/src/main/java/java/lang/System.java b/ojluni/src/main/java/java/lang/System.java
index 04358db..4b7cca9 100755
--- a/ojluni/src/main/java/java/lang/System.java
+++ b/ojluni/src/main/java/java/lang/System.java
@@ -570,9 +570,8 @@
         p.put("user.language", "en");
         p.put("user.region", "US");
 
-        StructPasswd passwd = null;
         try {
-            passwd = Libcore.os.getpwuid(Libcore.os.getuid());
+            StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
             p.put("user.name", passwd.pw_name);
         } catch (ErrnoException exception) {
             throw new AssertionError(exception);
@@ -593,18 +592,24 @@
         // Override built-in properties with settings from the command line.
         parsePropertyAssignments(p, runtime.properties());
 
+        // Save user.home and java.io.tmpdir
+        String userHome = (String)p.remove("user.home");
+        String javaIoTmpdir = (String)p.remove("java.io.tmpdir");
+
         Properties result = new PropertiesWithNonOverrideableDefaults(p);
         // On Android, each app gets its own temporary directory.
         // (See android.app.ActivityThread.) This is just a fallback default,
         // useful only on the host.
-        result.put("java.io.tmpdir", "/tmp");
+        result.put("java.io.tmpdir",
+            (javaIoTmpdir == null || javaIoTmpdir.isEmpty()) ? "/tmp" : javaIoTmpdir);
 
         // Android has always had an empty "user.home" (see docs for getProperty).
         // This is not useful for normal android apps which need to use android specific
         // APIs such as {@code Context.getFilesDir} and {@code Context.getCacheDir} but
         // we make it changeable for backward compatibility, so that they can change it
         // to a writeable location if required.
-        result.put("user.home", passwd.pw_dir);
+        result.put("user.home",
+            (userHome == null || userHome.isEmpty()) ? "" : userHome);
 
         return result;
     }