Skip to content

Commit f69c812

Browse files
author
Jeff Brown
committed
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
1 parent 4a86019 commit f69c812

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

services/java/com/android/server/SystemServer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.android.server.input.InputManagerService;
5656
import com.android.server.net.NetworkPolicyManagerService;
5757
import com.android.server.net.NetworkStatsService;
58+
import com.android.server.pm.Installer;
5859
import com.android.server.pm.PackageManagerService;
5960
import com.android.server.pm.UserManagerService;
6061
import com.android.server.power.PowerManagerService;
@@ -117,6 +118,7 @@ public void run() {
117118
: Integer.parseInt(factoryTestStr);
118119
final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
119120

121+
Installer installer = null;
120122
AccountManagerService accountManager = null;
121123
ContentService contentService = null;
122124
LightsService lights = null;
@@ -195,6 +197,13 @@ public void run() {
195197
// Critical services...
196198
boolean onlyCore = false;
197199
try {
200+
// Wait for installd to finished starting up so that it has a chance to
201+
// create critical directories such as /data/user with the appropriate
202+
// permissions. We need this to complete before we initialize other services.
203+
Slog.i(TAG, "Waiting for installd to be ready.");
204+
installer = new Installer();
205+
installer.ping();
206+
198207
Slog.i(TAG, "Entropy Mixer");
199208
ServiceManager.addService("entropy", new EntropyMixer());
200209

@@ -234,7 +243,7 @@ public void run() {
234243
onlyCore = true;
235244
}
236245

237-
pm = PackageManagerService.main(context,
246+
pm = PackageManagerService.main(context, installer,
238247
factoryTest != SystemServer.FACTORY_TEST_OFF,
239248
onlyCore);
240249
boolean firstBoot = false;

services/java/com/android/server/pm/Installer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.io.InputStream;
2626
import java.io.OutputStream;
2727

28-
class Installer {
28+
public final class Installer {
2929
private static final String TAG = "Installer";
3030

3131
private static final boolean LOCAL_DEBUG = false;

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,10 @@ void scheduleWritePackageRestrictionsLocked(int userId) {
937937
}
938938
}
939939

940-
public static final IPackageManager main(Context context, boolean factoryTest,
941-
boolean onlyCore) {
942-
PackageManagerService m = new PackageManagerService(context, factoryTest, onlyCore);
940+
public static final IPackageManager main(Context context, Installer installer,
941+
boolean factoryTest, boolean onlyCore) {
942+
PackageManagerService m = new PackageManagerService(context, installer,
943+
factoryTest, onlyCore);
943944
ServiceManager.addService("package", m);
944945
return m;
945946
}
@@ -966,7 +967,8 @@ static String[] splitString(String str, char sep) {
966967
return res;
967968
}
968969

969-
public PackageManagerService(Context context, boolean factoryTest, boolean onlyCore) {
970+
public PackageManagerService(Context context, Installer installer,
971+
boolean factoryTest, boolean onlyCore) {
970972
EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START,
971973
SystemClock.uptimeMillis());
972974

@@ -1004,7 +1006,7 @@ public PackageManagerService(Context context, boolean factoryTest, boolean onlyC
10041006
mSeparateProcesses = null;
10051007
}
10061008

1007-
mInstaller = new Installer();
1009+
mInstaller = installer;
10081010

10091011
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
10101012
Display d = wm.getDefaultDisplay();

0 commit comments

Comments
 (0)