SystemServer.java revision 75279904202357565cf5a1cb11148d01f42b4569
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            } catch (Throwable e) {
309                Slog.e(TAG, "Failure starting Connectivity Service", e);
310            }
311
312            try {
313                Slog.i(TAG, "Throttle Service");
314                throttle = new ThrottleService(context);
315                ServiceManager.addService(
316                        Context.THROTTLE_SERVICE, throttle);
317            } catch (Throwable e) {
318                Slog.e(TAG, "Failure starting ThrottleService", e);
319            }
320
321            try {
322              Slog.i(TAG, "Accessibility Manager");
323              ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
324                      new AccessibilityManagerService(context));
325            } catch (Throwable e) {
326              Slog.e(TAG, "Failure starting Accessibility Manager", e);
327            }
328
329            try {
330                /*
331                 * NotificationManagerService is dependant on MountService,
332                 * (for media / usb notifications) so we must start MountService first.
333                 */
334                Slog.i(TAG, "Mount Service");
335                ServiceManager.addService("mount", new MountService(context));
336            } catch (Throwable e) {
337                Slog.e(TAG, "Failure starting Mount Service", e);
338            }
339
340            try {
341                Slog.i(TAG, "Notification Manager");
342                notification = new NotificationManagerService(context, statusBar, lights);
343                ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
344            } catch (Throwable e) {
345                Slog.e(TAG, "Failure starting Notification Manager", e);
346            }
347
348            try {
349                Slog.i(TAG, "Device Storage Monitor");
350                ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
351                        new DeviceStorageMonitorService(context));
352            } catch (Throwable e) {
353                Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
354            }
355
356            try {
357                Slog.i(TAG, "Location Manager");
358                location = new LocationManagerService(context);
359                ServiceManager.addService(Context.LOCATION_SERVICE, location);
360            } catch (Throwable e) {
361                Slog.e(TAG, "Failure starting Location Manager", e);
362            }
363
364            try {
365                Slog.i(TAG, "Country Detector");
366                countryDetector = new CountryDetectorService(context);
367                ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
368            } catch (Throwable e) {
369                Slog.e(TAG, "Failure starting Country Detector", e);
370            }
371
372            try {
373                Slog.i(TAG, "Search Service");
374                ServiceManager.addService(Context.SEARCH_SERVICE,
375                        new SearchManagerService(context));
376            } catch (Throwable e) {
377                Slog.e(TAG, "Failure starting Search Service", e);
378            }
379
380            try {
381                Slog.i(TAG, "DropBox Service");
382                ServiceManager.addService(Context.DROPBOX_SERVICE,
383                        new DropBoxManagerService(context, new File("/data/system/dropbox")));
384            } catch (Throwable e) {
385                Slog.e(TAG, "Failure starting DropBoxManagerService", e);
386            }
387
388            try {
389                Slog.i(TAG, "Wallpaper Service");
390                wallpaper = new WallpaperManagerService(context);
391                ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
392            } catch (Throwable e) {
393                Slog.e(TAG, "Failure starting Wallpaper Service", e);
394            }
395
396            try {
397                Slog.i(TAG, "Audio Service");
398                ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
399            } catch (Throwable e) {
400                Slog.e(TAG, "Failure starting Audio Service", e);
401            }
402
403            try {
404                Slog.i(TAG, "Dock Observer");
405                // Listen for dock station changes
406                dock = new DockObserver(context, power);
407            } catch (Throwable e) {
408                Slog.e(TAG, "Failure starting DockObserver", e);
409            }
410
411            try {
412                Slog.i(TAG, "Wired Accessory Observer");
413                // Listen for wired headset changes
414                wiredAccessory = new WiredAccessoryObserver(context);
415            } catch (Throwable e) {
416                Slog.e(TAG, "Failure starting WiredAccessoryObserver", e);
417            }
418
419            try {
420                Slog.i(TAG, "USB Observer");
421                // Listen for USB changes
422                usb = new UsbService(context);
423                ServiceManager.addService(Context.USB_SERVICE, usb);
424            } catch (Throwable e) {
425                Slog.e(TAG, "Failure starting UsbService", e);
426            }
427
428            try {
429                Slog.i(TAG, "UI Mode Manager Service");
430                // Listen for UI mode changes
431                uiMode = new UiModeManagerService(context);
432            } catch (Throwable e) {
433                Slog.e(TAG, "Failure starting UiModeManagerService", e);
434            }
435
436            try {
437                Slog.i(TAG, "Backup Service");
438                ServiceManager.addService(Context.BACKUP_SERVICE,
439                        new BackupManagerService(context));
440            } catch (Throwable e) {
441                Slog.e(TAG, "Failure starting Backup Service", e);
442            }
443
444            try {
445                Slog.i(TAG, "AppWidget Service");
446                appWidget = new AppWidgetService(context);
447                ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
448            } catch (Throwable e) {
449                Slog.e(TAG, "Failure starting AppWidget Service", e);
450            }
451
452            try {
453                Slog.i(TAG, "Recognition Service");
454                recognition = new RecognitionManagerService(context);
455            } catch (Throwable e) {
456                Slog.e(TAG, "Failure starting Recognition Service", e);
457            }
458
459            try {
460                Slog.i(TAG, "DiskStats Service");
461                ServiceManager.addService("diskstats", new DiskStatsService(context));
462            } catch (Throwable e) {
463                Slog.e(TAG, "Failure starting DiskStats Service", e);
464            }
465
466            try {
467                // need to add this service even if SamplingProfilerIntegration.isEnabled()
468                // is false, because it is this service that detects system property change and
469                // turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
470                // there is little overhead for running this service.
471                Slog.i(TAG, "SamplingProfiler Service");
472                ServiceManager.addService("samplingprofiler",
473                            new SamplingProfilerService(context));
474            } catch (Throwable e) {
475                Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
476            }
477
478            try {
479                Slog.i(TAG, "NetworkTimeUpdateService");
480                networkTimeUpdater = new NetworkTimeUpdateService(context);
481            } catch (Throwable e) {
482                Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
483            }
484        }
485
486        // make sure the ADB_ENABLED setting value matches the secure property value
487        Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
488                "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
489
490        // register observer to listen for settings changes
491        mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
492                false, new AdbSettingsObserver());
493
494        // Before things start rolling, be sure we have decided whether
495        // we are in safe mode.
496        final boolean safeMode = wm.detectSafeMode();
497        if (safeMode) {
498            ActivityManagerService.self().enterSafeMode();
499            // Post the safe mode state in the Zygote class
500            Zygote.systemInSafeMode = true;
501            // Disable the JIT for the system_server process
502            VMRuntime.getRuntime().disableJitCompilation();
503        } else {
504            // Enable the JIT for the system_server process
505            VMRuntime.getRuntime().startJitCompilation();
506        }
507
508        // It is now time to start up the app processes...
509
510        if (devicePolicy != null) {
511            devicePolicy.systemReady();
512        }
513
514        if (notification != null) {
515            notification.systemReady();
516        }
517
518        wm.systemReady();
519
520        if (safeMode) {
521            ActivityManagerService.self().showSafeModeOverlay();
522        }
523
524        // Update the configuration for this context by hand, because we're going
525        // to start using it before the config change done in wm.systemReady() will
526        // propagate to it.
527        Configuration config = wm.computeNewConfiguration();
528        DisplayMetrics metrics = new DisplayMetrics();
529        WindowManager w = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
530        w.getDefaultDisplay().getMetrics(metrics);
531        context.getResources().updateConfiguration(config, metrics);
532
533        power.systemReady();
534        try {
535            pm.systemReady();
536        } catch (RemoteException e) {
537        }
538
539        // These are needed to propagate to the runnable below.
540        final Context contextF = context;
541        final BatteryService batteryF = battery;
542        final NetworkStatsService networkStatsF = networkStats;
543        final NetworkPolicyManagerService networkPolicyF = networkPolicy;
544        final ConnectivityService connectivityF = connectivity;
545        final DockObserver dockF = dock;
546        final UsbService usbF = usb;
547        final ThrottleService throttleF = throttle;
548        final UiModeManagerService uiModeF = uiMode;
549        final AppWidgetService appWidgetF = appWidget;
550        final WallpaperManagerService wallpaperF = wallpaper;
551        final InputMethodManagerService immF = imm;
552        final RecognitionManagerService recognitionF = recognition;
553        final LocationManagerService locationF = location;
554        final CountryDetectorService countryDetectorF = countryDetector;
555        final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
556
557        // We now tell the activity manager it is okay to run third party
558        // code.  It will call back into us once it has gotten to the state
559        // where third party code can really run (but before it has actually
560        // started launching the initial applications), for us to complete our
561        // initialization.
562        ((ActivityManagerService)ActivityManagerNative.getDefault())
563                .systemReady(new Runnable() {
564            public void run() {
565                Slog.i(TAG, "Making services ready");
566
567                startSystemUi(contextF);
568                if (batteryF != null) batteryF.systemReady();
569                if (networkStatsF != null) networkStatsF.systemReady();
570                if (networkPolicyF != null) networkPolicyF.systemReady();
571                if (connectivityF != null) connectivityF.systemReady();
572                if (dockF != null) dockF.systemReady();
573                if (usbF != null) usbF.systemReady();
574                if (uiModeF != null) uiModeF.systemReady();
575                if (recognitionF != null) recognitionF.systemReady();
576                Watchdog.getInstance().start();
577
578                // It is now okay to let the various system services start their
579                // third party code...
580
581                if (appWidgetF != null) appWidgetF.systemReady(safeMode);
582                if (wallpaperF != null) wallpaperF.systemReady();
583                if (immF != null) immF.systemReady();
584                if (locationF != null) locationF.systemReady();
585                if (countryDetectorF != null) countryDetectorF.systemReady();
586                if (throttleF != null) throttleF.systemReady();
587                if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
588            }
589        });
590
591        // For debug builds, log event loop stalls to dropbox for analysis.
592        if (StrictMode.conditionallyEnableDebugLogging()) {
593            Slog.i(TAG, "Enabled StrictMode for system server main thread.");
594        }
595
596        Looper.loop();
597        Slog.d(TAG, "System ServerThread is exiting!");
598    }
599
600    static final void startSystemUi(Context context) {
601        Intent intent = new Intent();
602        intent.setComponent(new ComponentName("com.android.systemui",
603                    "com.android.systemui.SystemUIService"));
604        Slog.d(TAG, "Starting service: " + intent);
605        context.startService(intent);
606    }
607}
608
609public class SystemServer {
610    private static final String TAG = "SystemServer";
611
612    public static final int FACTORY_TEST_OFF = 0;
613    public static final int FACTORY_TEST_LOW_LEVEL = 1;
614    public static final int FACTORY_TEST_HIGH_LEVEL = 2;
615
616    static Timer timer;
617    static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
618
619    // The earliest supported time.  We pick one day into 1970, to
620    // give any timezone code room without going into negative time.
621    private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
622
623    /**
624     * This method is called from Zygote to initialize the system. This will cause the native
625     * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
626     * up into init2() to start the Android services.
627     */
628    native public static void init1(String[] args);
629
630    public static void main(String[] args) {
631        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
632            // If a device's clock is before 1970 (before 0), a lot of
633            // APIs crash dealing with negative numbers, notably
634            // java.io.File#setLastModified, so instead we fake it and
635            // hope that time from cell towers or NTP fixes it
636            // shortly.
637            Slog.w(TAG, "System clock is before 1970; setting to 1970.");
638            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
639        }
640
641        if (SamplingProfilerIntegration.isEnabled()) {
642            SamplingProfilerIntegration.start();
643            timer = new Timer();
644            timer.schedule(new TimerTask() {
645                @Override
646                public void run() {
647                    SamplingProfilerIntegration.writeSnapshot("system_server", null);
648                }
649            }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
650        }
651
652        // Mmmmmm... more memory!
653        dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
654
655        // The system server has to run all of the time, so it needs to be
656        // as efficient as possible with its memory usage.
657        VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
658
659        System.loadLibrary("android_servers");
660        init1(args);
661    }
662
663    public static final void init2() {
664        Slog.i(TAG, "Entered the Android system server!");
665        Thread thr = new ServerThread();
666        thr.setName("android.server.ServerThread");
667        thr.start();
668    }
669}
670