SystemServer.java revision d2a458750e5a3d490af09cecb5c28370baf0a913
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import android.accounts.AccountManagerService;
20import android.app.ActivityManagerNative;
21import android.bluetooth.BluetoothAdapter;
22import android.content.ComponentName;
23import android.content.ContentResolver;
24import android.content.ContentService;
25import android.content.Context;
26import android.content.Intent;
27import android.content.pm.IPackageManager;
28import android.content.res.Configuration;
29import android.database.ContentObserver;
30import android.media.AudioService;
31import android.os.Looper;
32import android.os.RemoteException;
33import android.os.ServiceManager;
34import android.os.StrictMode;
35import android.os.SystemClock;
36import android.os.SystemProperties;
37import android.provider.Settings;
38import android.server.BluetoothA2dpService;
39import android.server.BluetoothService;
40import android.server.search.SearchManagerService;
41import android.util.DisplayMetrics;
42import android.util.EventLog;
43import android.util.Slog;
44import android.view.WindowManager;
45
46import com.android.internal.app.ShutdownThread;
47import com.android.internal.os.BinderInternal;
48import com.android.internal.os.SamplingProfilerIntegration;
49import com.android.server.accessibility.AccessibilityManagerService;
50import com.android.server.am.ActivityManagerService;
51import com.android.server.net.NetworkPolicyManagerService;
52import com.android.server.net.NetworkStatsService;
53import com.android.server.pm.PackageManagerService;
54import com.android.server.usb.UsbService;
55import com.android.server.wm.WindowManagerService;
56
57import dalvik.system.VMRuntime;
58import dalvik.system.Zygote;
59
60import java.io.File;
61import java.util.Timer;
62import java.util.TimerTask;
63
64class ServerThread extends Thread {
65    private static final String TAG = "SystemServer";
66
67    ContentResolver mContentResolver;
68
69    private class AdbSettingsObserver extends ContentObserver {
70        public AdbSettingsObserver() {
71            super(null);
72        }
73        @Override
74        public void onChange(boolean selfChange) {
75            boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
76                Settings.Secure.ADB_ENABLED, 0) > 0);
77            // setting this secure property will start or stop adbd
78           SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
79        }
80    }
81
82    @Override
83    public void run() {
84        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
85            SystemClock.uptimeMillis());
86
87        Looper.prepare();
88
89        android.os.Process.setThreadPriority(
90                android.os.Process.THREAD_PRIORITY_FOREGROUND);
91
92        BinderInternal.disableBackgroundScheduling(true);
93        android.os.Process.setCanSelfBackground(false);
94
95        // Check whether we failed to shut down last time we tried.
96        {
97            final String shutdownAction = SystemProperties.get(
98                    ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
99            if (shutdownAction != null && shutdownAction.length() > 0) {
100                boolean reboot = (shutdownAction.charAt(0) == '1');
101
102                final String reason;
103                if (shutdownAction.length() > 1) {
104                    reason = shutdownAction.substring(1, shutdownAction.length());
105                } else {
106                    reason = null;
107                }
108
109                ShutdownThread.rebootOrShutdown(reboot, reason);
110            }
111        }
112
113        String factoryTestStr = SystemProperties.get("ro.factorytest");
114        int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
115                : Integer.parseInt(factoryTestStr);
116
117        LightsService lights = null;
118        PowerManagerService power = null;
119        BatteryService battery = null;
120        AlarmManagerService alarm = null;
121        NetworkManagementService networkManagement = null;
122        NetworkStatsService networkStats = null;
123        NetworkPolicyManagerService networkPolicy = null;
124        ConnectivityService connectivity = null;
125        IPackageManager pm = null;
126        Context context = null;
127        WindowManagerService wm = null;
128        BluetoothService bluetooth = null;
129        BluetoothA2dpService bluetoothA2dp = null;
130        WiredAccessoryObserver wiredAccessory = null;
131        DockObserver dock = null;
132        UsbService usb = null;
133        UiModeManagerService uiMode = null;
134        RecognitionManagerService recognition = null;
135        ThrottleService throttle = null;
136        NetworkTimeUpdateService networkTimeUpdater = null;
137
138        // Critical services...
139        try {
140            Slog.i(TAG, "Entropy Service");
141            ServiceManager.addService("entropy", new EntropyService());
142
143            Slog.i(TAG, "Power Manager");
144            power = new PowerManagerService();
145            ServiceManager.addService(Context.POWER_SERVICE, power);
146
147            Slog.i(TAG, "Activity Manager");
148            context = ActivityManagerService.main(factoryTest);
149
150            Slog.i(TAG, "Telephony Registry");
151            ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
152
153            AttributeCache.init(context);
154
155            Slog.i(TAG, "Package Manager");
156            pm = PackageManagerService.main(context,
157                    factoryTest != SystemServer.FACTORY_TEST_OFF);
158
159            ActivityManagerService.setSystemProcess();
160
161            mContentResolver = context.getContentResolver();
162
163            // The AccountManager must come before the ContentService
164            try {
165                Slog.i(TAG, "Account Manager");
166                ServiceManager.addService(Context.ACCOUNT_SERVICE,
167                        new AccountManagerService(context));
168            } catch (Throwable e) {
169                Slog.e(TAG, "Failure starting Account Manager", e);
170            }
171
172            Slog.i(TAG, "Content Manager");
173            ContentService.main(context,
174                    factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
175
176            Slog.i(TAG, "System Content Providers");
177            ActivityManagerService.installSystemProviders();
178
179            Slog.i(TAG, "Lights Service");
180            lights = new LightsService(context);
181
182            Slog.i(TAG, "Battery Service");
183            battery = new BatteryService(context, lights);
184            ServiceManager.addService("battery", battery);
185
186            Slog.i(TAG, "Vibrator Service");
187            ServiceManager.addService("vibrator", new VibratorService(context));
188
189            // only initialize the power service after we have started the
190            // lights service, content providers and the battery service.
191            power.init(context, lights, ActivityManagerService.getDefault(), battery);
192
193            Slog.i(TAG, "Alarm Manager");
194            alarm = new AlarmManagerService(context);
195            ServiceManager.addService(Context.ALARM_SERVICE, alarm);
196
197            Slog.i(TAG, "Init Watchdog");
198            Watchdog.getInstance().init(context, battery, power, alarm,
199                    ActivityManagerService.self());
200
201            Slog.i(TAG, "Window Manager");
202            wm = WindowManagerService.main(context, power,
203                    factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
204            ServiceManager.addService(Context.WINDOW_SERVICE, wm);
205
206            ((ActivityManagerService)ServiceManager.getService("activity"))
207                    .setWindowManager(wm);
208
209            // Skip Bluetooth if we have an emulator kernel
210            // TODO: Use a more reliable check to see if this product should
211            // support Bluetooth - see bug 988521
212            if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
213                Slog.i(TAG, "No Bluetooh Service (emulator)");
214            } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
215                Slog.i(TAG, "No Bluetooth Service (factory test)");
216            } else {
217                Slog.i(TAG, "Bluetooth Service");
218                bluetooth = new BluetoothService(context);
219                ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
220                bluetooth.initAfterRegistration();
221                bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
222                ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
223                                          bluetoothA2dp);
224                bluetooth.initAfterA2dpRegistration();
225
226                int bluetoothOn = Settings.Secure.getInt(mContentResolver,
227                    Settings.Secure.BLUETOOTH_ON, 0);
228                if (bluetoothOn > 0) {
229                    bluetooth.enable();
230                }
231            }
232
233        } catch (RuntimeException e) {
234            Slog.e("System", "Failure starting core service", e);
235        }
236
237        DevicePolicyManagerService devicePolicy = null;
238        StatusBarManagerService statusBar = null;
239        InputMethodManagerService imm = null;
240        AppWidgetService appWidget = null;
241        NotificationManagerService notification = null;
242        WallpaperManagerService wallpaper = null;
243        LocationManagerService location = null;
244        CountryDetectorService countryDetector = null;
245
246        if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
247            try {
248                Slog.i(TAG, "Device Policy");
249                devicePolicy = new DevicePolicyManagerService(context);
250                ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
251            } catch (Throwable e) {
252                Slog.e(TAG, "Failure starting DevicePolicyService", e);
253            }
254
255            try {
256                Slog.i(TAG, "Status Bar");
257                statusBar = new StatusBarManagerService(context, wm);
258                ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
259            } catch (Throwable e) {
260                Slog.e(TAG, "Failure starting StatusBarManagerService", e);
261            }
262
263            try {
264                Slog.i(TAG, "Clipboard Service");
265                ServiceManager.addService(Context.CLIPBOARD_SERVICE,
266                        new ClipboardService(context));
267            } catch (Throwable e) {
268                Slog.e(TAG, "Failure starting Clipboard Service", e);
269            }
270
271            try {
272                Slog.i(TAG, "Input Method Service");
273                imm = new InputMethodManagerService(context, statusBar);
274                ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
275            } catch (Throwable e) {
276                Slog.e(TAG, "Failure starting Input Manager Service", e);
277            }
278
279            try {
280                Slog.i(TAG, "NetworkManagement Service");
281                networkManagement = NetworkManagementService.create(context);
282                ServiceManager.addService(Context.NETWORKMANAGEMENT_SERVICE, networkManagement);
283            } catch (Throwable e) {
284                Slog.e(TAG, "Failure starting NetworkManagement Service", e);
285            }
286
287            try {
288                Slog.i(TAG, "NetworkStats Service");
289                networkStats = new NetworkStatsService(context, networkManagement, alarm);
290                ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
291            } catch (Throwable e) {
292                Slog.e(TAG, "Failure starting NetworkStats Service", e);
293            }
294
295            try {
296                Slog.i(TAG, "NetworkPolicy Service");
297                networkPolicy = new NetworkPolicyManagerService(
298                        context, ActivityManagerService.self(), power, networkStats);
299                ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
300            } catch (Throwable e) {
301                Slog.e(TAG, "Failure starting NetworkPolicy Service", e);
302            }
303
304            try {
305                Slog.i(TAG, "Connectivity Service");
306                connectivity = new ConnectivityService(context, networkManagement, networkPolicy);
307                ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
308                networkStats.bindConnectivityManager(connectivity);
309            } catch (Throwable e) {
310                Slog.e(TAG, "Failure starting Connectivity Service", e);
311            }
312
313            try {
314                Slog.i(TAG, "Throttle Service");
315                throttle = new ThrottleService(context);
316                ServiceManager.addService(
317                        Context.THROTTLE_SERVICE, throttle);
318            } catch (Throwable e) {
319                Slog.e(TAG, "Failure starting ThrottleService", e);
320            }
321
322            try {
323              Slog.i(TAG, "Accessibility Manager");
324              ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
325                      new AccessibilityManagerService(context));
326            } catch (Throwable e) {
327              Slog.e(TAG, "Failure starting Accessibility Manager", e);
328            }
329
330            try {
331                /*
332                 * NotificationManagerService is dependant on MountService,
333                 * (for media / usb notifications) so we must start MountService first.
334                 */
335                Slog.i(TAG, "Mount Service");
336                ServiceManager.addService("mount", new MountService(context));
337            } catch (Throwable e) {
338                Slog.e(TAG, "Failure starting Mount Service", e);
339            }
340
341            try {
342                Slog.i(TAG, "Notification Manager");
343                notification = new NotificationManagerService(context, statusBar, lights);
344                ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
345            } catch (Throwable e) {
346                Slog.e(TAG, "Failure starting Notification Manager", e);
347            }
348
349            try {
350                Slog.i(TAG, "Device Storage Monitor");
351                ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
352                        new DeviceStorageMonitorService(context));
353            } catch (Throwable e) {
354                Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
355            }
356
357            try {
358                Slog.i(TAG, "Location Manager");
359                location = new LocationManagerService(context);
360                ServiceManager.addService(Context.LOCATION_SERVICE, location);
361            } catch (Throwable e) {
362                Slog.e(TAG, "Failure starting Location Manager", e);
363            }
364
365            try {
366                Slog.i(TAG, "Country Detector");
367                countryDetector = new CountryDetectorService(context);
368                ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
369            } catch (Throwable e) {
370                Slog.e(TAG, "Failure starting Country Detector", e);
371            }
372
373            try {
374                Slog.i(TAG, "Search Service");
375                ServiceManager.addService(Context.SEARCH_SERVICE,
376                        new SearchManagerService(context));
377            } catch (Throwable e) {
378                Slog.e(TAG, "Failure starting Search Service", e);
379            }
380
381            try {
382                Slog.i(TAG, "DropBox Service");
383                ServiceManager.addService(Context.DROPBOX_SERVICE,
384                        new DropBoxManagerService(context, new File("/data/system/dropbox")));
385            } catch (Throwable e) {
386                Slog.e(TAG, "Failure starting DropBoxManagerService", e);
387            }
388
389            try {
390                Slog.i(TAG, "Wallpaper Service");
391                wallpaper = new WallpaperManagerService(context);
392                ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
393            } catch (Throwable e) {
394                Slog.e(TAG, "Failure starting Wallpaper Service", e);
395            }
396
397            try {
398                Slog.i(TAG, "Audio Service");
399                ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
400            } catch (Throwable e) {
401                Slog.e(TAG, "Failure starting Audio Service", e);
402            }
403
404            try {
405                Slog.i(TAG, "Dock Observer");
406                // Listen for dock station changes
407                dock = new DockObserver(context, power);
408            } catch (Throwable e) {
409                Slog.e(TAG, "Failure starting DockObserver", e);
410            }
411
412            try {
413                Slog.i(TAG, "Wired Accessory Observer");
414                // Listen for wired headset changes
415                wiredAccessory = new WiredAccessoryObserver(context);
416            } catch (Throwable e) {
417                Slog.e(TAG, "Failure starting WiredAccessoryObserver", e);
418            }
419
420            try {
421                Slog.i(TAG, "USB Observer");
422                // Listen for USB changes
423                usb = new UsbService(context);
424                ServiceManager.addService(Context.USB_SERVICE, usb);
425            } catch (Throwable e) {
426                Slog.e(TAG, "Failure starting UsbService", e);
427            }
428
429            try {
430                Slog.i(TAG, "UI Mode Manager Service");
431                // Listen for UI mode changes
432                uiMode = new UiModeManagerService(context);
433            } catch (Throwable e) {
434                Slog.e(TAG, "Failure starting UiModeManagerService", e);
435            }
436
437            try {
438                Slog.i(TAG, "Backup Service");
439                ServiceManager.addService(Context.BACKUP_SERVICE,
440                        new BackupManagerService(context));
441            } catch (Throwable e) {
442                Slog.e(TAG, "Failure starting Backup Service", e);
443            }
444
445            try {
446                Slog.i(TAG, "AppWidget Service");
447                appWidget = new AppWidgetService(context);
448                ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
449            } catch (Throwable e) {
450                Slog.e(TAG, "Failure starting AppWidget Service", e);
451            }
452
453            try {
454                Slog.i(TAG, "Recognition Service");
455                recognition = new RecognitionManagerService(context);
456            } catch (Throwable e) {
457                Slog.e(TAG, "Failure starting Recognition Service", e);
458            }
459
460            try {
461                Slog.i(TAG, "DiskStats Service");
462                ServiceManager.addService("diskstats", new DiskStatsService(context));
463            } catch (Throwable e) {
464                Slog.e(TAG, "Failure starting DiskStats Service", e);
465            }
466
467            try {
468                // need to add this service even if SamplingProfilerIntegration.isEnabled()
469                // is false, because it is this service that detects system property change and
470                // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
471                // there is little overhead for running this service.
472                Slog.i(TAG, "SamplingProfiler Service");
473                ServiceManager.addService("samplingprofiler",
474                            new SamplingProfilerService(context));
475            } catch (Throwable e) {
476                Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
477            }
478
479            try {
480                Slog.i(TAG, "NetworkTimeUpdateService");
481                networkTimeUpdater = new NetworkTimeUpdateService(context);
482            } catch (Throwable e) {
483                Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
484            }
485        }
486
487        // make sure the ADB_ENABLED setting value matches the secure property value
488        Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
489                "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
490
491        // register observer to listen for settings changes
492        mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
493                false, new AdbSettingsObserver());
494
495        // Before things start rolling, be sure we have decided whether
496        // we are in safe mode.
497        final boolean safeMode = wm.detectSafeMode();
498        if (safeMode) {
499            ActivityManagerService.self().enterSafeMode();
500            // Post the safe mode state in the Zygote class
501            Zygote.systemInSafeMode = true;
502            // Disable the JIT for the system_server process
503            VMRuntime.getRuntime().disableJitCompilation();
504        } else {
505            // Enable the JIT for the system_server process
506            VMRuntime.getRuntime().startJitCompilation();
507        }
508
509        // It is now time to start up the app processes...
510
511        if (devicePolicy != null) {
512            devicePolicy.systemReady();
513        }
514
515        if (notification != null) {
516            notification.systemReady();
517        }
518
519        wm.systemReady();
520
521        if (safeMode) {
522            ActivityManagerService.self().showSafeModeOverlay();
523        }
524
525        // Update the configuration for this context by hand, because we're going
526        // to start using it before the config change done in wm.systemReady() will
527        // propagate to it.
528        Configuration config = wm.computeNewConfiguration();
529        DisplayMetrics metrics = new DisplayMetrics();
530        WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
531        w.getDefaultDisplay().getMetrics(metrics);
532        context.getResources().updateConfiguration(config, metrics);
533
534        power.systemReady();
535        try {
536            pm.systemReady();
537        } catch (RemoteException e) {
538        }
539
540        // These are needed to propagate to the runnable below.
541        final Context contextF = context;
542        final BatteryService batteryF = battery;
543        final NetworkStatsService networkStatsF = networkStats;
544        final NetworkPolicyManagerService networkPolicyF = networkPolicy;
545        final ConnectivityService connectivityF = connectivity;
546        final DockObserver dockF = dock;
547        final UsbService usbF = usb;
548        final ThrottleService throttleF = throttle;
549        final UiModeManagerService uiModeF = uiMode;
550        final AppWidgetService appWidgetF = appWidget;
551        final WallpaperManagerService wallpaperF = wallpaper;
552        final InputMethodManagerService immF = imm;
553        final RecognitionManagerService recognitionF = recognition;
554        final LocationManagerService locationF = location;
555        final CountryDetectorService countryDetectorF = countryDetector;
556        final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
557
558        // We now tell the activity manager it is okay to run third party
559        // code.  It will call back into us once it has gotten to the state
560        // where third party code can really run (but before it has actually
561        // started launching the initial applications), for us to complete our
562        // initialization.
563        ((ActivityManagerService)ActivityManagerNative.getDefault())
564                .systemReady(new Runnable() {
565            public void run() {
566                Slog.i(TAG, "Making services ready");
567
568                startSystemUi(contextF);
569                if (batteryF != null) batteryF.systemReady();
570                if (networkStatsF != null) networkStatsF.systemReady();
571                if (networkPolicyF != null) networkPolicyF.systemReady();
572                if (connectivityF != null) connectivityF.systemReady();
573                if (dockF != null) dockF.systemReady();
574                if (usbF != null) usbF.systemReady();
575                if (uiModeF != null) uiModeF.systemReady();
576                if (recognitionF != null) recognitionF.systemReady();
577                Watchdog.getInstance().start();
578
579                // It is now okay to let the various system services start their
580                // third party code...
581
582                if (appWidgetF != null) appWidgetF.systemReady(safeMode);
583                if (wallpaperF != null) wallpaperF.systemReady();
584                if (immF != null) immF.systemReady();
585                if (locationF != null) locationF.systemReady();
586                if (countryDetectorF != null) countryDetectorF.systemReady();
587                if (throttleF != null) throttleF.systemReady();
588                if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
589            }
590        });
591
592        // For debug builds, log event loop stalls to dropbox for analysis.
593        if (StrictMode.conditionallyEnableDebugLogging()) {
594            Slog.i(TAG, "Enabled StrictMode for system server main thread.");
595        }
596
597        Looper.loop();
598        Slog.d(TAG, "System ServerThread is exiting!");
599    }
600
601    static final void startSystemUi(Context context) {
602        Intent intent = new Intent();
603        intent.setComponent(new ComponentName("com.android.systemui",
604                    "com.android.systemui.SystemUIService"));
605        Slog.d(TAG, "Starting service: " + intent);
606        context.startService(intent);
607    }
608}
609
610public class SystemServer {
611    private static final String TAG = "SystemServer";
612
613    public static final int FACTORY_TEST_OFF = 0;
614    public static final int FACTORY_TEST_LOW_LEVEL = 1;
615    public static final int FACTORY_TEST_HIGH_LEVEL = 2;
616
617    static Timer timer;
618    static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
619
620    // The earliest supported time.  We pick one day into 1970, to
621    // give any timezone code room without going into negative time.
622    private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
623
624    /**
625     * This method is called from Zygote to initialize the system. This will cause the native
626     * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
627     * up into init2() to start the Android services.
628     */
629    native public static void init1(String[] args);
630
631    public static void main(String[] args) {
632        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
633            // If a device's clock is before 1970 (before 0), a lot of
634            // APIs crash dealing with negative numbers, notably
635            // java.io.File#setLastModified, so instead we fake it and
636            // hope that time from cell towers or NTP fixes it
637            // shortly.
638            Slog.w(TAG, "System clock is before 1970; setting to 1970.");
639            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
640        }
641
642        if (SamplingProfilerIntegration.isEnabled()) {
643            SamplingProfilerIntegration.start();
644            timer = new Timer();
645            timer.schedule(new TimerTask() {
646                @Override
647                public void run() {
648                    SamplingProfilerIntegration.writeSnapshot("system_server", null);
649                }
650            }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
651        }
652
653        // Mmmmmm... more memory!
654        dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
655
656        // The system server has to run all of the time, so it needs to be
657        // as efficient as possible with its memory usage.
658        VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
659
660        System.loadLibrary("android_servers");
661        init1(args);
662    }
663
664    public static final void init2() {
665        Slog.i(TAG, "Entered the Android system server!");
666        Thread thr = new ServerThread();
667        thr.setName("android.server.ServerThread");
668        thr.start();
669    }
670}
671