From f69c812f49cb2dea296cd319984e58af026f4c3a Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Wed, 12 Sep 2012 17:00:34 -0700 Subject: Wait for installd to finish starting before booting. Fixes a race condition where the system server might try to access /data/user/0 before it was created. In so doing, the system server could end up creating a directory in that location with the wrong permissions and everything would promptly crash. Bug: 7151686 Change-Id: I349c12fd2b9685d2e7f6305e74f6bf7d5816b752 --- services/java/com/android/server/SystemServer.java | 11 ++++++++++- services/java/com/android/server/pm/Installer.java | 2 +- .../java/com/android/server/pm/PackageManagerService.java | 12 +++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 439844101c97..90783b740ca1 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -55,6 +55,7 @@ import com.android.server.display.DisplayManagerService; import com.android.server.input.InputManagerService; import com.android.server.net.NetworkPolicyManagerService; import com.android.server.net.NetworkStatsService; +import com.android.server.pm.Installer; import com.android.server.pm.PackageManagerService; import com.android.server.pm.UserManagerService; import com.android.server.power.PowerManagerService; @@ -117,6 +118,7 @@ class ServerThread extends Thread { : Integer.parseInt(factoryTestStr); final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0")); + Installer installer = null; AccountManagerService accountManager = null; ContentService contentService = null; LightsService lights = null; @@ -195,6 +197,13 @@ class ServerThread extends Thread { // Critical services... boolean onlyCore = false; try { + // Wait for installd to finished starting up so that it has a chance to + // create critical directories such as /data/user with the appropriate + // permissions. We need this to complete before we initialize other services. + Slog.i(TAG, "Waiting for installd to be ready."); + installer = new Installer(); + installer.ping(); + Slog.i(TAG, "Entropy Mixer"); ServiceManager.addService("entropy", new EntropyMixer()); @@ -234,7 +243,7 @@ class ServerThread extends Thread { onlyCore = true; } - pm = PackageManagerService.main(context, + pm = PackageManagerService.main(context, installer, factoryTest != SystemServer.FACTORY_TEST_OFF, onlyCore); boolean firstBoot = false; diff --git a/services/java/com/android/server/pm/Installer.java b/services/java/com/android/server/pm/Installer.java index 85de3494bd9b..ad85c0d6fa4e 100644 --- a/services/java/com/android/server/pm/Installer.java +++ b/services/java/com/android/server/pm/Installer.java @@ -25,7 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -class Installer { +public final class Installer { private static final String TAG = "Installer"; private static final boolean LOCAL_DEBUG = false; diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 01a9b4b7b0a4..ba63efde13cd 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -937,9 +937,10 @@ public class PackageManagerService extends IPackageManager.Stub { } } - public static final IPackageManager main(Context context, boolean factoryTest, - boolean onlyCore) { - PackageManagerService m = new PackageManagerService(context, factoryTest, onlyCore); + public static final IPackageManager main(Context context, Installer installer, + boolean factoryTest, boolean onlyCore) { + PackageManagerService m = new PackageManagerService(context, installer, + factoryTest, onlyCore); ServiceManager.addService("package", m); return m; } @@ -966,7 +967,8 @@ public class PackageManagerService extends IPackageManager.Stub { return res; } - public PackageManagerService(Context context, boolean factoryTest, boolean onlyCore) { + public PackageManagerService(Context context, Installer installer, + boolean factoryTest, boolean onlyCore) { EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START, SystemClock.uptimeMillis()); @@ -1004,7 +1006,7 @@ public class PackageManagerService extends IPackageManager.Stub { mSeparateProcesses = null; } - mInstaller = new Installer(); + mInstaller = installer; WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); Display d = wm.getDefaultDisplay(); -- cgit v1.2.3-59-g8ed1b