Merge "Add trace code to system server."

This commit is contained in:
Yasuhiro Matsuda
2015-09-02 12:54:23 +00:00
committed by Gerrit Code Review
6 changed files with 337 additions and 178 deletions

View File

@@ -77,6 +77,8 @@ public final class Trace {
public static final long TRACE_TAG_POWER = 1L << 17; public static final long TRACE_TAG_POWER = 1L << 17;
/** @hide */ /** @hide */
public static final long TRACE_TAG_PACKAGE_MANAGER = 1L << 18; public static final long TRACE_TAG_PACKAGE_MANAGER = 1L << 18;
/** @hide */
public static final long TRACE_TAG_SYSTEM_SERVER = 1L << 19;
private static final long TRACE_TAG_NOT_READY = 1L << 63; private static final long TRACE_TAG_NOT_READY = 1L << 63;
private static final int MAX_SECTION_NAME_LEN = 127; private static final int MAX_SECTION_NAME_LEN = 127;

View File

@@ -182,8 +182,18 @@ public class ZygoteInit {
static void preload() { static void preload() {
Log.d(TAG, "begin preload"); Log.d(TAG, "begin preload");
preloadClasses(); try {
preloadResources(); Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClasses");
preloadClasses();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
try {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadResources");
preloadResources();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
preloadOpenGL(); preloadOpenGL();
preloadSharedLibraries(); preloadSharedLibraries();
// Ask the WebViewFactory to do any initialization that must run in the zygote process, // Ask the WebViewFactory to do any initialization that must run in the zygote process,
@@ -264,6 +274,7 @@ public class ZygoteInit {
} }
try { try {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClass " + line);
if (false) { if (false) {
Log.v(TAG, "Preloading " + line + "..."); Log.v(TAG, "Preloading " + line + "...");
} }
@@ -287,6 +298,8 @@ public class ZygoteInit {
throw (RuntimeException) t; throw (RuntimeException) t;
} }
throw new RuntimeException(t); throw new RuntimeException(t);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
} }
} }
@@ -300,7 +313,9 @@ public class ZygoteInit {
runtime.setTargetHeapUtilization(defaultUtilization); runtime.setTargetHeapUtilization(defaultUtilization);
// Fill in dex caches with classes, fields, and methods brought in by preloading. // Fill in dex caches with classes, fields, and methods brought in by preloading.
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadDexCaches");
runtime.preloadDexCaches(); runtime.preloadDexCaches();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
// Bring back root. We'll need it later if we're in the zygote. // Bring back root. We'll need it later if we're in the zygote.
if (droppedPriviliges) { if (droppedPriviliges) {
@@ -561,42 +576,57 @@ public class ZygoteInit {
public static void main(String argv[]) { public static void main(String argv[]) {
try { try {
RuntimeInit.enableDdms();
// Start profiling the zygote initialization.
SamplingProfilerIntegration.start();
boolean startSystemServer = false; boolean startSystemServer = false;
String socketName = "zygote"; String socketName = "zygote";
String abiList = null; String abiList = null;
for (int i = 1; i < argv.length; i++) { try {
if ("start-system-server".equals(argv[i])) { Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygoteInit");
startSystemServer = true; RuntimeInit.enableDdms();
} else if (argv[i].startsWith(ABI_LIST_ARG)) { // Start profiling the zygote initialization.
abiList = argv[i].substring(ABI_LIST_ARG.length()); SamplingProfilerIntegration.start();
} else if (argv[i].startsWith(SOCKET_NAME_ARG)) {
socketName = argv[i].substring(SOCKET_NAME_ARG.length()); for (int i = 1; i < argv.length; i++) {
} else { if ("start-system-server".equals(argv[i])) {
throw new RuntimeException("Unknown command line argument: " + argv[i]); startSystemServer = true;
} else if (argv[i].startsWith(ABI_LIST_ARG)) {
abiList = argv[i].substring(ABI_LIST_ARG.length());
} else if (argv[i].startsWith(SOCKET_NAME_ARG)) {
socketName = argv[i].substring(SOCKET_NAME_ARG.length());
} else {
throw new RuntimeException("Unknown command line argument: " + argv[i]);
}
} }
if (abiList == null) {
throw new RuntimeException("No ABI list supplied.");
}
registerZygoteSocket(socketName);
try {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ZygotePreload");
EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
SystemClock.uptimeMillis());
preload();
EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
SystemClock.uptimeMillis());
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
// Finish profiling the zygote initialization.
SamplingProfilerIntegration.writeZygoteSnapshot();
// Do an initial gc to clean up after startup
try {
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PostZygoteInitGC");
gcAndFinalize();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
} finally {
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
} }
if (abiList == null) {
throw new RuntimeException("No ABI list supplied.");
}
registerZygoteSocket(socketName);
EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_START,
SystemClock.uptimeMillis());
preload();
EventLog.writeEvent(LOG_BOOT_PROGRESS_PRELOAD_END,
SystemClock.uptimeMillis());
// Finish profiling the zygote initialization.
SamplingProfilerIntegration.writeZygoteSnapshot();
// Do an initial gc to clean up after startup
gcAndFinalize();
// Disable tracing so that forked processes do not inherit stale tracing tags from // Disable tracing so that forked processes do not inherit stale tracing tags from
// Zygote. // Zygote.
Trace.setTracingEnabled(false); Trace.setTracingEnabled(false);

View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#define ATRACE_TAG ATRACE_TAG_DALVIK
#define LOG_TAG "AndroidRuntime" #define LOG_TAG "AndroidRuntime"
//#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0
@@ -23,6 +24,7 @@
#include <binder/IServiceManager.h> #include <binder/IServiceManager.h>
#include <utils/Log.h> #include <utils/Log.h>
#include <utils/misc.h> #include <utils/misc.h>
#include <utils/Trace.h>
#include <binder/Parcel.h> #include <binder/Parcel.h>
#include <utils/threads.h> #include <utils/threads.h>
#include <cutils/properties.h> #include <cutils/properties.h>
@@ -1400,6 +1402,7 @@ static const RegJNIRec gRegJNI[] = {
*/ */
/*static*/ int AndroidRuntime::startReg(JNIEnv* env) /*static*/ int AndroidRuntime::startReg(JNIEnv* env)
{ {
ATRACE_NAME("RegisterAndroidNatives");
/* /*
* This hook causes all future threads created in this process to be * This hook causes all future threads created in this process to be
* attached to the JavaVM. (This needs to go away in favor of JNI * attached to the JavaVM. (This needs to go away in favor of JNI

View File

@@ -17,6 +17,7 @@
package com.android.server; package com.android.server;
import android.content.Context; import android.content.Context;
import android.os.Trace;
import android.util.Slog; import android.util.Slog;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@@ -75,43 +76,48 @@ public class SystemServiceManager {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends SystemService> T startService(Class<T> serviceClass) { public <T extends SystemService> T startService(Class<T> serviceClass) {
final String name = serviceClass.getName();
Slog.i(TAG, "Starting " + name);
// Create the service.
if (!SystemService.class.isAssignableFrom(serviceClass)) {
throw new RuntimeException("Failed to create " + name
+ ": service must extend " + SystemService.class.getName());
}
final T service;
try { try {
Constructor<T> constructor = serviceClass.getConstructor(Context.class); final String name = serviceClass.getName();
service = constructor.newInstance(mContext); Slog.i(TAG, "Starting " + name);
} catch (InstantiationException ex) { Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartService " + name);
throw new RuntimeException("Failed to create service " + name
+ ": service could not be instantiated", ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service must have a public constructor with a Context argument", ex);
} catch (NoSuchMethodException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service must have a public constructor with a Context argument", ex);
} catch (InvocationTargetException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service constructor threw an exception", ex);
}
// Register it. // Create the service.
mServices.add(service); if (!SystemService.class.isAssignableFrom(serviceClass)) {
throw new RuntimeException("Failed to create " + name
+ ": service must extend " + SystemService.class.getName());
}
final T service;
try {
Constructor<T> constructor = serviceClass.getConstructor(Context.class);
service = constructor.newInstance(mContext);
} catch (InstantiationException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service could not be instantiated", ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service must have a public constructor with a Context argument", ex);
} catch (NoSuchMethodException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service must have a public constructor with a Context argument", ex);
} catch (InvocationTargetException ex) {
throw new RuntimeException("Failed to create service " + name
+ ": service constructor threw an exception", ex);
}
// Start it. // Register it.
try { mServices.add(service);
service.onStart();
} catch (RuntimeException ex) { // Start it.
throw new RuntimeException("Failed to start service " + name try {
+ ": onStart threw an exception", ex); service.onStart();
} catch (RuntimeException ex) {
throw new RuntimeException("Failed to start service " + name
+ ": onStart threw an exception", ex);
}
return service;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
return service;
} }
/** /**
@@ -127,18 +133,22 @@ public class SystemServiceManager {
mCurrentPhase = phase; mCurrentPhase = phase;
Slog.i(TAG, "Starting phase " + mCurrentPhase); Slog.i(TAG, "Starting phase " + mCurrentPhase);
try {
final int serviceLen = mServices.size(); Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "OnBootPhase " + phase);
for (int i = 0; i < serviceLen; i++) { final int serviceLen = mServices.size();
final SystemService service = mServices.get(i); for (int i = 0; i < serviceLen; i++) {
try { final SystemService service = mServices.get(i);
service.onBootPhase(mCurrentPhase); try {
} catch (Exception ex) { service.onBootPhase(mCurrentPhase);
throw new RuntimeException("Failed to boot service " } catch (Exception ex) {
+ service.getClass().getName() throw new RuntimeException("Failed to boot service "
+ ": onBootPhase threw an exception during phase " + service.getClass().getName()
+ mCurrentPhase, ex); + ": onBootPhase threw an exception during phase "
+ mCurrentPhase, ex);
}
} }
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
} }

View File

@@ -186,6 +186,7 @@ import android.os.ServiceManager;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.Trace;
import android.os.UpdateLock; import android.os.UpdateLock;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -1780,7 +1781,9 @@ public final class ActivityManagerService extends ActivityManagerNative
} }
case FINISH_BOOTING_MSG: { case FINISH_BOOTING_MSG: {
if (msg.arg1 != 0) { if (msg.arg1 != 0) {
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
finishBooting(); finishBooting();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
} }
if (msg.arg2 != 0) { if (msg.arg2 != 0) {
enableScreenAfterBoot(); enableScreenAfterBoot();
@@ -6285,7 +6288,9 @@ public final class ActivityManagerService extends ActivityManagerNative
mBootAnimationComplete = true; mBootAnimationComplete = true;
} }
if (callFinishBooting) { if (callFinishBooting) {
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
finishBooting(); finishBooting();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
} }
} }
@@ -6311,7 +6316,9 @@ public final class ActivityManagerService extends ActivityManagerNative
} }
if (booting) { if (booting) {
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "FinishBooting");
finishBooting(); finishBooting();
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
} }
if (enableScreen) { if (enableScreen) {

View File

@@ -43,6 +43,7 @@ import android.os.ServiceManager;
import android.os.StrictMode; import android.os.StrictMode;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.dreams.DreamService; import android.service.dreams.DreamService;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@@ -176,81 +177,87 @@ public final class SystemServer {
} }
private void run() { private void run() {
// If a device's clock is before 1970 (before 0), a lot of try {
// APIs crash dealing with negative numbers, notably Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitBeforeStartServices");
// java.io.File#setLastModified, so instead we fake it and // If a device's clock is before 1970 (before 0), a lot of
// hope that time from cell towers or NTP fixes it shortly. // APIs crash dealing with negative numbers, notably
if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { // java.io.File#setLastModified, so instead we fake it and
Slog.w(TAG, "System clock is before 1970; setting to 1970."); // hope that time from cell towers or NTP fixes it shortly.
SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
} Slog.w(TAG, "System clock is before 1970; setting to 1970.");
SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
}
// Here we go! // Here we go!
Slog.i(TAG, "Entered the Android system server!"); Slog.i(TAG, "Entered the Android system server!");
EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis());
// In case the runtime switched since last boot (such as when // In case the runtime switched since last boot (such as when
// the old runtime was removed in an OTA), set the system // the old runtime was removed in an OTA), set the system
// property so that it is in sync. We can't do this in // property so that it is in sync. We can't do this in
// libnativehelper's JniInvocation::Init code where we already // libnativehelper's JniInvocation::Init code where we already
// had to fallback to a different runtime because it is // had to fallback to a different runtime because it is
// running as root and we need to be the system user to set // running as root and we need to be the system user to set
// the property. http://b/11463182 // the property. http://b/11463182
SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary()); SystemProperties.set("persist.sys.dalvik.vm.lib.2", VMRuntime.getRuntime().vmLibrary());
// Enable the sampling profiler. // Enable the sampling profiler.
if (SamplingProfilerIntegration.isEnabled()) { if (SamplingProfilerIntegration.isEnabled()) {
SamplingProfilerIntegration.start(); SamplingProfilerIntegration.start();
mProfilerSnapshotTimer = new Timer(); mProfilerSnapshotTimer = new Timer();
mProfilerSnapshotTimer.schedule(new TimerTask() { mProfilerSnapshotTimer.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
SamplingProfilerIntegration.writeSnapshot("system_server", null); SamplingProfilerIntegration.writeSnapshot("system_server", null);
} }
}, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
} }
// Mmmmmm... more memory! // Mmmmmm... more memory!
VMRuntime.getRuntime().clearGrowthLimit(); VMRuntime.getRuntime().clearGrowthLimit();
// The system server has to run all of the time, so it needs to be // The system server has to run all of the time, so it needs to be
// as efficient as possible with its memory usage. // as efficient as possible with its memory usage.
VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
// Some devices rely on runtime fingerprint generation, so make sure // Some devices rely on runtime fingerprint generation, so make sure
// we've defined it before booting further. // we've defined it before booting further.
Build.ensureFingerprintProperty(); Build.ensureFingerprintProperty();
// Within the system server, it is an error to access Environment paths without // Within the system server, it is an error to access Environment paths without
// explicitly specifying a user. // explicitly specifying a user.
Environment.setUserRequired(true); Environment.setUserRequired(true);
// Ensure binder calls into the system always run at foreground priority. // Ensure binder calls into the system always run at foreground priority.
BinderInternal.disableBackgroundScheduling(true); BinderInternal.disableBackgroundScheduling(true);
// Prepare the main looper thread (this thread). // Prepare the main looper thread (this thread).
android.os.Process.setThreadPriority( android.os.Process.setThreadPriority(
android.os.Process.THREAD_PRIORITY_FOREGROUND); android.os.Process.THREAD_PRIORITY_FOREGROUND);
android.os.Process.setCanSelfBackground(false); android.os.Process.setCanSelfBackground(false);
Looper.prepareMainLooper(); Looper.prepareMainLooper();
// Initialize native services. // Initialize native services.
System.loadLibrary("android_servers"); System.loadLibrary("android_servers");
nativeInit(); nativeInit();
// Check whether we failed to shut down last time we tried. // Check whether we failed to shut down last time we tried.
// This call may not return. // This call may not return.
performPendingShutdown(); performPendingShutdown();
// Initialize the system context. // Initialize the system context.
createSystemContext(); createSystemContext();
// Create the system service manager. // Create the system service manager.
mSystemServiceManager = new SystemServiceManager(mSystemContext); mSystemServiceManager = new SystemServiceManager(mSystemContext);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager); LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
// Start services. // Start services.
try { try {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartServices");
startBootstrapServices(); startBootstrapServices();
startCoreServices(); startCoreServices();
startOtherServices(); startOtherServices();
@@ -258,6 +265,8 @@ public final class SystemServer {
Slog.e("System", "******************************************"); Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex); Slog.e("System", "************ Failure starting system services", ex);
throw ex; throw ex;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
// For debug builds, log event loop stalls to dropbox for analysis. // For debug builds, log event loop stalls to dropbox for analysis.
@@ -325,7 +334,9 @@ public final class SystemServer {
// Now that the power manager has been started, let the activity manager // Now that the power manager has been started, let the activity manager
// initialize power management features. // initialize power management features.
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "InitPowerManagement");
mActivityManagerService.initPowerManagement(); mActivityManagerService.initPowerManagement();
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
// Display manager is needed to provide display metrics before package manager // Display manager is needed to provide display metrics before package manager
// starts up. // starts up.
@@ -345,14 +356,16 @@ public final class SystemServer {
} }
// Start the package manager. // Start the package manager.
Slog.i(TAG, "Package Manager"); traceBeginAndSlog("StartPackageManagerService");
mPackageManagerService = PackageManagerService.main(mSystemContext, installer, mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore); mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
mFirstBoot = mPackageManagerService.isFirstBoot(); mFirstBoot = mPackageManagerService.isFirstBoot();
mPackageManager = mSystemContext.getPackageManager(); mPackageManager = mSystemContext.getPackageManager();
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "User Service"); traceBeginAndSlog("StartUserManagerService");
ServiceManager.addService(Context.USER_SERVICE, UserManagerService.getInstance()); ServiceManager.addService(Context.USER_SERVICE, UserManagerService.getInstance());
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
// Initialize attribute cache used to cache resources from packages. // Initialize attribute cache used to cache resources from packages.
AttributeCache.init(mSystemContext); AttributeCache.init(mSystemContext);
@@ -427,62 +440,73 @@ public final class SystemServer {
Slog.i(TAG, "Reading configuration..."); Slog.i(TAG, "Reading configuration...");
SystemConfig.getInstance(); SystemConfig.getInstance();
Slog.i(TAG, "Scheduling Policy"); traceBeginAndSlog("StartSchedulingPolicyService");
ServiceManager.addService("scheduling_policy", new SchedulingPolicyService()); ServiceManager.addService("scheduling_policy", new SchedulingPolicyService());
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(TelecomLoaderService.class); mSystemServiceManager.startService(TelecomLoaderService.class);
Slog.i(TAG, "Telephony Registry"); traceBeginAndSlog("StartTelephonyRegistry");
telephonyRegistry = new TelephonyRegistry(context); telephonyRegistry = new TelephonyRegistry(context);
ServiceManager.addService("telephony.registry", telephonyRegistry); ServiceManager.addService("telephony.registry", telephonyRegistry);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Entropy Mixer"); traceBeginAndSlog("StartEntropyMixer");
entropyMixer = new EntropyMixer(context); entropyMixer = new EntropyMixer(context);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
// The AccountManager must come before the ContentService // The AccountManager must come before the ContentService
traceBeginAndSlog("StartAccountManagerService");
try { try {
// TODO: seems like this should be disable-able, but req'd by ContentService // TODO: seems like this should be disable-able, but req'd by ContentService
Slog.i(TAG, "Account Manager");
accountManager = new AccountManagerService(context); accountManager = new AccountManagerService(context);
ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager); ServiceManager.addService(Context.ACCOUNT_SERVICE, accountManager);
} catch (Throwable e) { } catch (Throwable e) {
Slog.e(TAG, "Failure starting Account Manager", e); Slog.e(TAG, "Failure starting Account Manager", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Content Manager"); traceBeginAndSlog("StartContentService");
contentService = ContentService.main(context, contentService = ContentService.main(context,
mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL); mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "System Content Providers"); traceBeginAndSlog("InstallSystemProviders");
mActivityManagerService.installSystemProviders(); mActivityManagerService.installSystemProviders();
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Vibrator Service"); traceBeginAndSlog("StartVibratorService");
vibrator = new VibratorService(context); vibrator = new VibratorService(context);
ServiceManager.addService("vibrator", vibrator); ServiceManager.addService("vibrator", vibrator);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Consumer IR Service"); traceBeginAndSlog("StartConsumerIrService");
consumerIr = new ConsumerIrService(context); consumerIr = new ConsumerIrService(context);
ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr); ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(AlarmManagerService.class); mSystemServiceManager.startService(AlarmManagerService.class);
alarm = IAlarmManager.Stub.asInterface( alarm = IAlarmManager.Stub.asInterface(
ServiceManager.getService(Context.ALARM_SERVICE)); ServiceManager.getService(Context.ALARM_SERVICE));
Slog.i(TAG, "Init Watchdog"); traceBeginAndSlog("InitWatchdog");
final Watchdog watchdog = Watchdog.getInstance(); final Watchdog watchdog = Watchdog.getInstance();
watchdog.init(context, mActivityManagerService); watchdog.init(context, mActivityManagerService);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Input Manager"); traceBeginAndSlog("StartInputManagerService");
inputManager = new InputManagerService(context); inputManager = new InputManagerService(context);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "Window Manager"); traceBeginAndSlog("StartWindowManagerService");
wm = WindowManagerService.main(context, inputManager, wm = WindowManagerService.main(context, inputManager,
mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL, mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL,
!mFirstBoot, mOnlyCore); !mFirstBoot, mOnlyCore);
ServiceManager.addService(Context.WINDOW_SERVICE, wm); ServiceManager.addService(Context.WINDOW_SERVICE, wm);
ServiceManager.addService(Context.INPUT_SERVICE, inputManager); ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mActivityManagerService.setWindowManager(wm); mActivityManagerService.setWindowManager(wm);
@@ -505,9 +529,10 @@ public final class SystemServer {
} else if (disableBluetooth) { } else if (disableBluetooth) {
Slog.i(TAG, "Bluetooth Service disabled by config"); Slog.i(TAG, "Bluetooth Service disabled by config");
} else { } else {
Slog.i(TAG, "Bluetooth Manager Service"); traceBeginAndSlog("StartBluetoothManagerService");
bluetooth = new BluetoothManagerService(context); bluetooth = new BluetoothManagerService(context);
ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, bluetooth);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
Slog.e("System", "******************************************"); Slog.e("System", "******************************************");
@@ -529,21 +554,23 @@ public final class SystemServer {
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
//if (!disableNonCoreServices) { // TODO: View depends on these; mock them? //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
if (true) { if (true) {
traceBeginAndSlog("StartInputMethodManagerService");
try { try {
Slog.i(TAG, "Input Method Service");
imm = new InputMethodManagerService(context, wm); imm = new InputMethodManagerService(context, wm);
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Input Manager Service", e); reportWtf("starting Input Manager Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartAccessibilityManagerService");
try { try {
Slog.i(TAG, "Accessibility Manager");
ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
new AccessibilityManagerService(context)); new AccessibilityManagerService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Accessibility Manager", e); reportWtf("starting Accessibility Manager", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
} }
@@ -556,25 +583,28 @@ public final class SystemServer {
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
if (!disableStorage && if (!disableStorage &&
!"0".equals(SystemProperties.get("system_init.startmountservice"))) { !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
traceBeginAndSlog("StartMountService");
try { try {
/* /*
* NotificationManagerService is dependant on MountService, * NotificationManagerService is dependant on MountService,
* (for media / usb notifications) so we must start MountService first. * (for media / usb notifications) so we must start MountService first.
*/ */
Slog.i(TAG, "Mount Service");
mountService = new MountService(context); mountService = new MountService(context);
ServiceManager.addService("mount", mountService); ServiceManager.addService("mount", mountService);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Mount Service", e); reportWtf("starting Mount Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
} }
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PerformBootDexOpt");
try { try {
mPackageManagerService.performBootDexOpt(); mPackageManagerService.performBootDexOpt();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("performing boot dexopt", e); reportWtf("performing boot dexopt", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
try { try {
ActivityManagerNative.getDefault().showBootMessage( ActivityManagerNative.getDefault().showBootMessage(
@@ -586,13 +616,14 @@ public final class SystemServer {
if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) { if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartLockSettingsService");
try { try {
Slog.i(TAG, "LockSettingsService");
lockSettings = new LockSettingsService(context); lockSettings = new LockSettingsService(context);
ServiceManager.addService("lock_settings", lockSettings); ServiceManager.addService("lock_settings", lockSettings);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting LockSettingsService service", e); reportWtf("starting LockSettingsService service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) { if (!SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
mSystemServiceManager.startService(PersistentDataBlockService.class); mSystemServiceManager.startService(PersistentDataBlockService.class);
@@ -604,64 +635,70 @@ public final class SystemServer {
} }
if (!disableSystemUI) { if (!disableSystemUI) {
traceBeginAndSlog("StartStatusBarManagerService");
try { try {
Slog.i(TAG, "Status Bar");
statusBar = new StatusBarManagerService(context, wm); statusBar = new StatusBarManagerService(context, wm);
ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting StatusBarManagerService", e); reportWtf("starting StatusBarManagerService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartClipboardService");
try { try {
Slog.i(TAG, "Clipboard Service");
ServiceManager.addService(Context.CLIPBOARD_SERVICE, ServiceManager.addService(Context.CLIPBOARD_SERVICE,
new ClipboardService(context)); new ClipboardService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Clipboard Service", e); reportWtf("starting Clipboard Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNetwork) { if (!disableNetwork) {
traceBeginAndSlog("StartNetworkManagementService");
try { try {
Slog.i(TAG, "NetworkManagement Service");
networkManagement = NetworkManagementService.create(context); networkManagement = NetworkManagementService.create(context);
ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement); ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting NetworkManagement Service", e); reportWtf("starting NetworkManagement Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartTextServicesManagerService");
try { try {
Slog.i(TAG, "Text Service Manager Service");
tsms = new TextServicesManagerService(context); tsms = new TextServicesManagerService(context);
ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms); ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Text Service Manager Service", e); reportWtf("starting Text Service Manager Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNetwork) { if (!disableNetwork) {
traceBeginAndSlog("StartNetworkScoreService");
try { try {
Slog.i(TAG, "Network Score Service");
networkScore = new NetworkScoreService(context); networkScore = new NetworkScoreService(context);
ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore); ServiceManager.addService(Context.NETWORK_SCORE_SERVICE, networkScore);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Network Score Service", e); reportWtf("starting Network Score Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartNetworkStatsService");
try { try {
Slog.i(TAG, "NetworkStats Service");
networkStats = new NetworkStatsService(context, networkManagement, alarm); networkStats = new NetworkStatsService(context, networkManagement, alarm);
ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats); ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting NetworkStats Service", e); reportWtf("starting NetworkStats Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartNetworkPolicyManagerService");
try { try {
Slog.i(TAG, "NetworkPolicy Service");
networkPolicy = new NetworkPolicyManagerService( networkPolicy = new NetworkPolicyManagerService(
context, mActivityManagerService, context, mActivityManagerService,
(IPowerManager)ServiceManager.getService(Context.POWER_SERVICE), (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE),
@@ -670,6 +707,7 @@ public final class SystemServer {
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting NetworkPolicy Service", e); reportWtf("starting NetworkPolicy Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS); mSystemServiceManager.startService(WIFI_P2P_SERVICE_CLASS);
mSystemServiceManager.startService(WIFI_SERVICE_CLASS); mSystemServiceManager.startService(WIFI_SERVICE_CLASS);
@@ -682,8 +720,8 @@ public final class SystemServer {
mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS); mSystemServiceManager.startService(ETHERNET_SERVICE_CLASS);
} }
traceBeginAndSlog("StartConnectivityService");
try { try {
Slog.i(TAG, "Connectivity Service");
connectivity = new ConnectivityService( connectivity = new ConnectivityService(
context, networkManagement, networkStats, networkPolicy); context, networkManagement, networkStats, networkPolicy);
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
@@ -692,25 +730,28 @@ public final class SystemServer {
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Connectivity Service", e); reportWtf("starting Connectivity Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartNsdService");
try { try {
Slog.i(TAG, "Network Service Discovery Service");
serviceDiscovery = NsdService.create(context); serviceDiscovery = NsdService.create(context);
ServiceManager.addService( ServiceManager.addService(
Context.NSD_SERVICE, serviceDiscovery); Context.NSD_SERVICE, serviceDiscovery);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Service Discovery Service", e); reportWtf("starting Service Discovery Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartUpdateLockService");
try { try {
Slog.i(TAG, "UpdateLock Service");
ServiceManager.addService(Context.UPDATE_LOCK_SERVICE, ServiceManager.addService(Context.UPDATE_LOCK_SERVICE,
new UpdateLockService(context)); new UpdateLockService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting UpdateLockService", e); reportWtf("starting UpdateLockService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
/* /*
@@ -719,22 +760,28 @@ public final class SystemServer {
* first before continuing. * first before continuing.
*/ */
if (mountService != null && !mOnlyCore) { if (mountService != null && !mOnlyCore) {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WaitForAsecScan");
mountService.waitForAsecScan(); mountService.waitForAsecScan();
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeAccountManagerServiceReady");
try { try {
if (accountManager != null) if (accountManager != null)
accountManager.systemReady(); accountManager.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Account Manager Service ready", e); reportWtf("making Account Manager Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeContentServiceReady");
try { try {
if (contentService != null) if (contentService != null)
contentService.systemReady(); contentService.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Content Service ready", e); reportWtf("making Content Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(NotificationManagerService.class); mSystemServiceManager.startService(NotificationManagerService.class);
notification = INotificationManager.Stub.asInterface( notification = INotificationManager.Stub.asInterface(
@@ -744,60 +791,66 @@ public final class SystemServer {
mSystemServiceManager.startService(DeviceStorageMonitorService.class); mSystemServiceManager.startService(DeviceStorageMonitorService.class);
if (!disableLocation) { if (!disableLocation) {
traceBeginAndSlog("StartLocationManagerService");
try { try {
Slog.i(TAG, "Location Manager");
location = new LocationManagerService(context); location = new LocationManagerService(context);
ServiceManager.addService(Context.LOCATION_SERVICE, location); ServiceManager.addService(Context.LOCATION_SERVICE, location);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Location Manager", e); reportWtf("starting Location Manager", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartCountryDetectorService");
try { try {
Slog.i(TAG, "Country Detector");
countryDetector = new CountryDetectorService(context); countryDetector = new CountryDetectorService(context);
ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector); ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Country Detector", e); reportWtf("starting Country Detector", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartSearchManagerService");
try { try {
Slog.i(TAG, "Search Service");
ServiceManager.addService(Context.SEARCH_SERVICE, ServiceManager.addService(Context.SEARCH_SERVICE,
new SearchManagerService(context)); new SearchManagerService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Search Service", e); reportWtf("starting Search Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
traceBeginAndSlog("StartDropBoxManagerService");
try { try {
Slog.i(TAG, "DropBox Service");
ServiceManager.addService(Context.DROPBOX_SERVICE, ServiceManager.addService(Context.DROPBOX_SERVICE,
new DropBoxManagerService(context, new File("/data/system/dropbox"))); new DropBoxManagerService(context, new File("/data/system/dropbox")));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting DropBoxManagerService", e); reportWtf("starting DropBoxManagerService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
if (!disableNonCoreServices && context.getResources().getBoolean( if (!disableNonCoreServices && context.getResources().getBoolean(
R.bool.config_enableWallpaperService)) { R.bool.config_enableWallpaperService)) {
traceBeginAndSlog("StartWallpaperManagerService");
try { try {
Slog.i(TAG, "Wallpaper Service");
wallpaper = new WallpaperManagerService(context); wallpaper = new WallpaperManagerService(context);
ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper); ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Wallpaper Service", e); reportWtf("starting Wallpaper Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) { if (!disableMedia && !"0".equals(SystemProperties.get("system_init.startaudioservice"))) {
traceBeginAndSlog("StartAudioService");
try { try {
Slog.i(TAG, "Audio Service");
audioService = new AudioService(context); audioService = new AudioService(context);
ServiceManager.addService(Context.AUDIO_SERVICE, audioService); ServiceManager.addService(Context.AUDIO_SERVICE, audioService);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting Audio Service", e); reportWtf("starting Audio Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
@@ -805,14 +858,15 @@ public final class SystemServer {
} }
if (!disableMedia) { if (!disableMedia) {
traceBeginAndSlog("StartWiredAccessoryManager");
try { try {
Slog.i(TAG, "Wired Accessory Manager");
// Listen for wired headset changes // Listen for wired headset changes
inputManager.setWiredAccessoryCallbacks( inputManager.setWiredAccessoryCallbacks(
new WiredAccessoryManager(context, inputManager)); new WiredAccessoryManager(context, inputManager));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting WiredAccessoryManager", e); reportWtf("starting WiredAccessoryManager", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
@@ -820,17 +874,20 @@ public final class SystemServer {
|| mPackageManager.hasSystemFeature( || mPackageManager.hasSystemFeature(
PackageManager.FEATURE_USB_ACCESSORY)) { PackageManager.FEATURE_USB_ACCESSORY)) {
// Manage USB host and device support // Manage USB host and device support
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartUsbService");
mSystemServiceManager.startService(USB_SERVICE_CLASS); mSystemServiceManager.startService(USB_SERVICE_CLASS);
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
traceBeginAndSlog("StartSerialService");
try { try {
Slog.i(TAG, "Serial Service");
// Serial port support // Serial port support
serial = new SerialService(context); serial = new SerialService(context);
ServiceManager.addService(Context.SERIAL_SERVICE, serial); ServiceManager.addService(Context.SERIAL_SERVICE, serial);
} catch (Throwable e) { } catch (Throwable e) {
Slog.e(TAG, "Failure starting SerialService", e); Slog.e(TAG, "Failure starting SerialService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
mSystemServiceManager.startService(TwilightService.class); mSystemServiceManager.startService(TwilightService.class);
@@ -853,51 +910,56 @@ public final class SystemServer {
} }
} }
traceBeginAndSlog("StartDiskStatsService");
try { try {
Slog.i(TAG, "DiskStats Service");
ServiceManager.addService("diskstats", new DiskStatsService(context)); ServiceManager.addService("diskstats", new DiskStatsService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting DiskStats Service", e); reportWtf("starting DiskStats Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
traceBeginAndSlog("StartSamplingProfilerService");
try { try {
// need to add this service even if SamplingProfilerIntegration.isEnabled() // need to add this service even if SamplingProfilerIntegration.isEnabled()
// is false, because it is this service that detects system property change and // is false, because it is this service that detects system property change and
// turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work, // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
// there is little overhead for running this service. // there is little overhead for running this service.
Slog.i(TAG, "SamplingProfiler Service");
ServiceManager.addService("samplingprofiler", ServiceManager.addService("samplingprofiler",
new SamplingProfilerService(context)); new SamplingProfilerService(context));
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting SamplingProfiler Service", e); reportWtf("starting SamplingProfiler Service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
if (!disableNetwork && !disableNetworkTime) { if (!disableNetwork && !disableNetworkTime) {
traceBeginAndSlog("StartNetworkTimeUpdateService");
try { try {
Slog.i(TAG, "NetworkTimeUpdateService");
networkTimeUpdater = new NetworkTimeUpdateService(context); networkTimeUpdater = new NetworkTimeUpdateService(context);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting NetworkTimeUpdate service", e); reportWtf("starting NetworkTimeUpdate service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableMedia) { if (!disableMedia) {
traceBeginAndSlog("StartCommonTimeManagementService");
try { try {
Slog.i(TAG, "CommonTimeManagementService");
commonTimeMgmtService = new CommonTimeManagementService(context); commonTimeMgmtService = new CommonTimeManagementService(context);
ServiceManager.addService("commontime_management", commonTimeMgmtService); ServiceManager.addService("commontime_management", commonTimeMgmtService);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting CommonTimeManagementService service", e); reportWtf("starting CommonTimeManagementService service", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNetwork) { if (!disableNetwork) {
traceBeginAndSlog("CertBlacklister");
try { try {
Slog.i(TAG, "CertBlacklister");
CertBlacklister blacklister = new CertBlacklister(context); CertBlacklister blacklister = new CertBlacklister(context);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting CertBlacklister", e); reportWtf("starting CertBlacklister", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
@@ -906,13 +968,14 @@ public final class SystemServer {
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartAssetAtlasService");
try { try {
Slog.i(TAG, "Assets Atlas Service");
atlas = new AssetAtlasService(context); atlas = new AssetAtlasService(context);
ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas); ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting AssetAtlasService", e); reportWtf("starting AssetAtlasService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) { if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
@@ -932,24 +995,26 @@ public final class SystemServer {
} }
if (!disableNonCoreServices) { if (!disableNonCoreServices) {
traceBeginAndSlog("StartMediaRouterService");
try { try {
Slog.i(TAG, "Media Router Service");
mediaRouter = new MediaRouterService(context); mediaRouter = new MediaRouterService(context);
ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter); ServiceManager.addService(Context.MEDIA_ROUTER_SERVICE, mediaRouter);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting MediaRouterService", e); reportWtf("starting MediaRouterService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
mSystemServiceManager.startService(TrustManagerService.class); mSystemServiceManager.startService(TrustManagerService.class);
mSystemServiceManager.startService(FingerprintService.class); mSystemServiceManager.startService(FingerprintService.class);
traceBeginAndSlog("StartBackgroundDexOptService");
try { try {
Slog.i(TAG, "BackgroundDexOptService");
BackgroundDexOptService.schedule(context); BackgroundDexOptService.schedule(context);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting BackgroundDexOptService", e); reportWtf("starting BackgroundDexOptService", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
@@ -977,12 +1042,15 @@ public final class SystemServer {
// It is now time to start up the app processes... // It is now time to start up the app processes...
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeVibratorServiceReady");
try { try {
vibrator.systemReady(); vibrator.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Vibrator Service ready", e); reportWtf("making Vibrator Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeLockSettingsServiceReady");
if (lockSettings != null) { if (lockSettings != null) {
try { try {
lockSettings.systemReady(); lockSettings.systemReady();
@@ -990,17 +1058,20 @@ public final class SystemServer {
reportWtf("making Lock Settings Service ready", e); reportWtf("making Lock Settings Service ready", e);
} }
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
// Needed by DevicePolicyManager for initialization // Needed by DevicePolicyManager for initialization
mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY); mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeWindowManagerServiceReady");
try { try {
wm.systemReady(); wm.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Window Manager Service ready", e); reportWtf("making Window Manager Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
if (safeMode) { if (safeMode) {
mActivityManagerService.showSafeModeOverlay(); mActivityManagerService.showSafeModeOverlay();
@@ -1015,25 +1086,32 @@ public final class SystemServer {
w.getDefaultDisplay().getMetrics(metrics); w.getDefaultDisplay().getMetrics(metrics);
context.getResources().updateConfiguration(config, metrics); context.getResources().updateConfiguration(config, metrics);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePowerManagerServiceReady");
try { try {
// TODO: use boot phase // TODO: use boot phase
mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService()); mPowerManagerService.systemReady(mActivityManagerService.getAppOpsService());
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Power Manager Service ready", e); reportWtf("making Power Manager Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakePackageManagerServiceReady");
try { try {
mPackageManagerService.systemReady(); mPackageManagerService.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Package Manager Service ready", e); reportWtf("making Package Manager Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeDisplayManagerServiceReady");
try { try {
// TODO: use boot phase and communicate these flags some other way // TODO: use boot phase and communicate these flags some other way
mDisplayManagerService.systemReady(safeMode, mOnlyCore); mDisplayManagerService.systemReady(safeMode, mOnlyCore);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Display Manager Service ready", e); reportWtf("making Display Manager Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
// These are needed to propagate to the runnable below. // These are needed to propagate to the runnable below.
final MountService mountServiceF = mountService; final MountService mountServiceF = mountService;
@@ -1068,60 +1146,83 @@ public final class SystemServer {
Slog.i(TAG, "Making services ready"); Slog.i(TAG, "Making services ready");
mSystemServiceManager.startBootPhase( mSystemServiceManager.startBootPhase(
SystemService.PHASE_ACTIVITY_MANAGER_READY); SystemService.PHASE_ACTIVITY_MANAGER_READY);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseActivityManagerReady");
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartObservingNativeCrashes");
try { try {
mActivityManagerService.startObservingNativeCrashes(); mActivityManagerService.startObservingNativeCrashes();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("observing native crashes", e); reportWtf("observing native crashes", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Slog.i(TAG, "WebViewFactory preparation"); Slog.i(TAG, "WebViewFactory preparation");
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "WebViewFactoryPreparation");
WebViewFactory.prepareWebViewInSystemServer(); WebViewFactory.prepareWebViewInSystemServer();
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartSystemUI");
try { try {
startSystemUi(context); startSystemUi(context);
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("starting System UI", e); reportWtf("starting System UI", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeMountServiceReady");
try { try {
if (mountServiceF != null) mountServiceF.systemReady(); if (mountServiceF != null) mountServiceF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Mount Service ready", e); reportWtf("making Mount Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkScoreServiceReady");
try { try {
if (networkScoreF != null) networkScoreF.systemReady(); if (networkScoreF != null) networkScoreF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Score Service ready", e); reportWtf("making Network Score Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkManagementServiceReady");
try { try {
if (networkManagementF != null) networkManagementF.systemReady(); if (networkManagementF != null) networkManagementF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Managment Service ready", e); reportWtf("making Network Managment Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkStatsServiceReady");
try { try {
if (networkStatsF != null) networkStatsF.systemReady(); if (networkStatsF != null) networkStatsF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Stats Service ready", e); reportWtf("making Network Stats Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeNetworkPolicyServiceReady");
try { try {
if (networkPolicyF != null) networkPolicyF.systemReady(); if (networkPolicyF != null) networkPolicyF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Network Policy Service ready", e); reportWtf("making Network Policy Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeConnectivityServiceReady");
try { try {
if (connectivityF != null) connectivityF.systemReady(); if (connectivityF != null) connectivityF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("making Connectivity Service ready", e); reportWtf("making Connectivity Service ready", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "MakeAudioServiceReady");
try { try {
if (audioServiceF != null) audioServiceF.systemReady(); if (audioServiceF != null) audioServiceF.systemReady();
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying AudioService running", e); reportWtf("Notifying AudioService running", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Watchdog.getInstance().start(); Watchdog.getInstance().start();
// It is now okay to let the various system services start their // It is now okay to let the various system services start their
// third party code... // third party code...
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "PhaseThirdPartyAppsCanStart");
mSystemServiceManager.startBootPhase( mSystemServiceManager.startBootPhase(
SystemService.PHASE_THIRD_PARTY_APPS_CAN_START); SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
@@ -1190,6 +1291,7 @@ public final class SystemServer {
} catch (Throwable e) { } catch (Throwable e) {
reportWtf("Notifying MmsService running", e); reportWtf("Notifying MmsService running", e);
} }
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
} }
}); });
} }
@@ -1201,4 +1303,9 @@ public final class SystemServer {
//Slog.d(TAG, "Starting service: " + intent); //Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.OWNER); context.startServiceAsUser(intent, UserHandle.OWNER);
} }
private static void traceBeginAndSlog(String name) {
Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, name);
Slog.i(TAG, name);
}
} }