2009-03-03 19:31:44 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.server;
|
|
|
|
|
|
|
|
import com.android.server.am.ActivityManagerService;
|
2009-12-07 17:59:37 -08:00
|
|
|
import com.android.internal.os.BinderInternal;
|
2009-09-04 18:31:17 -07:00
|
|
|
import com.android.internal.os.SamplingProfilerIntegration;
|
2010-09-23 16:12:11 -07:00
|
|
|
import com.trustedlogic.trustednfc.android.server.NfcService;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
import dalvik.system.VMRuntime;
|
2010-02-14 16:18:56 -08:00
|
|
|
import dalvik.system.Zygote;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2010-06-09 15:45:18 -05:00
|
|
|
import android.accounts.AccountManagerService;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.app.ActivityManagerNative;
|
2009-10-08 00:12:45 +02:00
|
|
|
import android.bluetooth.BluetoothAdapter;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentService;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.pm.IPackageManager;
|
|
|
|
import android.database.ContentObserver;
|
|
|
|
import android.media.AudioService;
|
2010-09-10 16:03:29 -07:00
|
|
|
import android.os.Build;
|
2010-06-09 15:45:18 -05:00
|
|
|
import android.os.Looper;
|
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.ServiceManager;
|
2010-09-10 16:03:29 -07:00
|
|
|
import android.os.StrictMode;
|
2010-06-09 15:45:18 -05:00
|
|
|
import android.os.SystemClock;
|
|
|
|
import android.os.SystemProperties;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.provider.Settings;
|
|
|
|
import android.server.BluetoothA2dpService;
|
2009-08-14 18:33:38 -07:00
|
|
|
import android.server.BluetoothService;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.server.search.SearchManagerService;
|
|
|
|
import android.util.EventLog;
|
2010-09-23 16:12:11 -07:00
|
|
|
import android.util.Log;
|
2010-02-26 18:56:32 -08:00
|
|
|
import android.util.Slog;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2009-09-11 16:40:01 -07:00
|
|
|
import java.io.File;
|
2009-09-04 18:31:17 -07:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
class ServerThread extends Thread {
|
|
|
|
private static final String TAG = "SystemServer";
|
|
|
|
|
2010-06-09 15:45:18 -05:00
|
|
|
ContentResolver mContentResolver;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
private class AdbSettingsObserver extends ContentObserver {
|
|
|
|
public AdbSettingsObserver() {
|
|
|
|
super(null);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onChange(boolean selfChange) {
|
|
|
|
boolean enableAdb = (Settings.Secure.getInt(mContentResolver,
|
|
|
|
Settings.Secure.ADB_ENABLED, 0) > 0);
|
|
|
|
// setting this secure property will start or stop adbd
|
|
|
|
SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2009-12-04 10:31:43 -08:00
|
|
|
EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
|
2009-03-03 19:31:44 -08:00
|
|
|
SystemClock.uptimeMillis());
|
|
|
|
|
|
|
|
Looper.prepare();
|
|
|
|
|
|
|
|
android.os.Process.setThreadPriority(
|
|
|
|
android.os.Process.THREAD_PRIORITY_FOREGROUND);
|
|
|
|
|
2009-12-07 17:59:37 -08:00
|
|
|
BinderInternal.disableBackgroundScheduling(true);
|
2010-06-30 17:46:30 -07:00
|
|
|
android.os.Process.setCanSelfBackground(false);
|
2010-05-28 01:54:03 -07:00
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
String factoryTestStr = SystemProperties.get("ro.factorytest");
|
|
|
|
int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
|
|
|
|
: Integer.parseInt(factoryTestStr);
|
|
|
|
|
2009-11-24 00:30:52 -05:00
|
|
|
LightsService lights = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
PowerManagerService power = null;
|
2009-08-12 09:56:44 -04:00
|
|
|
BatteryService battery = null;
|
2009-08-14 14:18:49 -04:00
|
|
|
ConnectivityService connectivity = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
IPackageManager pm = null;
|
|
|
|
Context context = null;
|
|
|
|
WindowManagerService wm = null;
|
2009-08-14 18:33:38 -07:00
|
|
|
BluetoothService bluetooth = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
BluetoothA2dpService bluetoothA2dp = null;
|
|
|
|
HeadsetObserver headset = null;
|
2009-08-12 15:15:43 -05:00
|
|
|
DockObserver dock = null;
|
2010-06-23 17:36:36 -04:00
|
|
|
UsbObserver usb = null;
|
2010-03-04 18:41:49 -08:00
|
|
|
UiModeManagerService uiMode = null;
|
2010-02-19 17:02:21 -08:00
|
|
|
RecognitionManagerService recognition = null;
|
2010-04-01 14:45:18 -07:00
|
|
|
ThrottleService throttle = null;
|
2010-09-13 16:24:08 -07:00
|
|
|
NetworkTimeUpdateService networkTimeUpdater = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
// Critical services...
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Entropy Service");
|
2009-06-17 16:03:22 -07:00
|
|
|
ServiceManager.addService("entropy", new EntropyService());
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Power Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
power = new PowerManagerService();
|
|
|
|
ServiceManager.addService(Context.POWER_SERVICE, power);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Activity Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
context = ActivityManagerService.main(factoryTest);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Telephony Registry");
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService("telephony.registry", new TelephonyRegistry(context));
|
|
|
|
|
|
|
|
AttributeCache.init(context);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Package Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
pm = PackageManagerService.main(context,
|
|
|
|
factoryTest != SystemServer.FACTORY_TEST_OFF);
|
|
|
|
|
|
|
|
ActivityManagerService.setSystemProcess();
|
|
|
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
2009-09-29 20:44:30 -07:00
|
|
|
// The AccountManager must come before the ContentService
|
2009-03-24 22:48:12 -07:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Account Manager");
|
2009-03-24 22:48:12 -07:00
|
|
|
ServiceManager.addService(Context.ACCOUNT_SERVICE,
|
|
|
|
new AccountManagerService(context));
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Account Manager", e);
|
2009-03-24 22:48:12 -07:00
|
|
|
}
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Content Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
ContentService.main(context,
|
|
|
|
factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "System Content Providers");
|
2009-03-03 19:31:44 -08:00
|
|
|
ActivityManagerService.installSystemProviders();
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Battery Service");
|
2009-08-12 09:56:44 -04:00
|
|
|
battery = new BatteryService(context);
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService("battery", battery);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Lights Service");
|
2009-11-24 00:30:52 -05:00
|
|
|
lights = new LightsService(context);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Vibrator Service");
|
2009-11-24 00:30:52 -05:00
|
|
|
ServiceManager.addService("vibrator", new VibratorService(context));
|
2009-03-18 17:39:46 -07:00
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
// only initialize the power service after we have started the
|
2009-11-24 00:30:52 -05:00
|
|
|
// lights service, content providers and the battery service.
|
|
|
|
power.init(context, lights, ActivityManagerService.getDefault(), battery);
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Alarm Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
AlarmManagerService alarm = new AlarmManagerService(context);
|
|
|
|
ServiceManager.addService(Context.ALARM_SERVICE, alarm);
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Init Watchdog");
|
2009-03-03 19:31:44 -08:00
|
|
|
Watchdog.getInstance().init(context, battery, power, alarm,
|
|
|
|
ActivityManagerService.self());
|
|
|
|
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Window Manager");
|
2009-03-03 19:31:44 -08:00
|
|
|
wm = WindowManagerService.main(context, power,
|
|
|
|
factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL);
|
|
|
|
ServiceManager.addService(Context.WINDOW_SERVICE, wm);
|
|
|
|
|
|
|
|
((ActivityManagerService)ServiceManager.getService("activity"))
|
|
|
|
.setWindowManager(wm);
|
|
|
|
|
|
|
|
// Skip Bluetooth if we have an emulator kernel
|
|
|
|
// TODO: Use a more reliable check to see if this product should
|
|
|
|
// support Bluetooth - see bug 988521
|
|
|
|
if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Registering null Bluetooth Service (emulator)");
|
2009-10-08 00:12:45 +02:00
|
|
|
ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
|
2009-03-03 19:31:44 -08:00
|
|
|
} else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Registering null Bluetooth Service (factory test)");
|
2009-10-08 00:12:45 +02:00
|
|
|
ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null);
|
2009-03-03 19:31:44 -08:00
|
|
|
} else {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Bluetooth Service");
|
2009-08-14 18:33:38 -07:00
|
|
|
bluetooth = new BluetoothService(context);
|
2009-10-08 00:12:45 +02:00
|
|
|
ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth);
|
2009-08-14 18:33:38 -07:00
|
|
|
bluetooth.initAfterRegistration();
|
2009-05-05 22:26:12 -07:00
|
|
|
bluetoothA2dp = new BluetoothA2dpService(context, bluetooth);
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE,
|
|
|
|
bluetoothA2dp);
|
|
|
|
|
|
|
|
int bluetoothOn = Settings.Secure.getInt(mContentResolver,
|
|
|
|
Settings.Secure.BLUETOOTH_ON, 0);
|
|
|
|
if (bluetoothOn > 0) {
|
2009-03-18 17:39:46 -07:00
|
|
|
bluetooth.enable();
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (RuntimeException e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e("System", "Failure starting core service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 18:14:19 -08:00
|
|
|
DevicePolicyManagerService devicePolicy = null;
|
2010-04-12 08:18:45 -07:00
|
|
|
StatusBarManagerService statusBar = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
InputMethodManagerService imm = null;
|
2009-03-11 12:11:56 -07:00
|
|
|
AppWidgetService appWidget = null;
|
2009-07-08 17:09:14 -07:00
|
|
|
NotificationManagerService notification = null;
|
2009-08-13 10:20:21 -07:00
|
|
|
WallpaperManagerService wallpaper = null;
|
2010-02-22 16:36:44 -05:00
|
|
|
LocationManagerService location = null;
|
2010-07-13 15:32:16 +08:00
|
|
|
CountryDetectorService countryDetector = null;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
|
2010-01-12 18:14:19 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Device Policy");
|
2010-01-12 18:14:19 -08:00
|
|
|
devicePolicy = new DevicePolicyManagerService(context);
|
|
|
|
ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting DevicePolicyService", e);
|
2010-01-12 18:14:19 -08:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Status Bar");
|
2010-04-12 08:18:45 -07:00
|
|
|
statusBar = new StatusBarManagerService(context);
|
2010-01-12 18:14:19 -08:00
|
|
|
ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-04-12 08:18:45 -07:00
|
|
|
Slog.e(TAG, "Failure starting StatusBarManagerService", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Clipboard Service");
|
2010-01-12 18:14:19 -08:00
|
|
|
ServiceManager.addService(Context.CLIPBOARD_SERVICE,
|
|
|
|
new ClipboardService(context));
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Clipboard Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Input Method Service");
|
2009-03-03 19:31:44 -08:00
|
|
|
imm = new InputMethodManagerService(context, statusBar);
|
|
|
|
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Input Manager Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "NetStat Service");
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService("netstat", new NetStatService(context));
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting NetStat Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:17:26 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "NetworkManagement Service");
|
2010-01-26 06:17:26 -08:00
|
|
|
ServiceManager.addService(
|
2010-09-22 14:32:35 -07:00
|
|
|
Context.NETWORKMANAGEMENT_SERVICE,
|
|
|
|
NetworkManagementService.create(context));
|
2010-01-26 06:17:26 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting NetworkManagement Service", e);
|
2010-01-26 06:17:26 -08:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Connectivity Service");
|
2009-08-14 14:18:49 -04:00
|
|
|
connectivity = ConnectivityService.getInstance(context);
|
|
|
|
ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Connectivity Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2010-04-01 14:45:18 -07:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "Throttle Service");
|
|
|
|
throttle = new ThrottleService(context);
|
|
|
|
ServiceManager.addService(
|
|
|
|
Context.THROTTLE_SERVICE, throttle);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting ThrottleService", e);
|
|
|
|
}
|
|
|
|
|
2009-05-14 22:28:01 -07:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Accessibility Manager");
|
2009-05-14 22:28:01 -07:00
|
|
|
ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
|
|
|
|
new AccessibilityManagerService(context));
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Accessibility Manager", e);
|
2009-05-14 22:28:01 -07:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-03 14:43:09 -08:00
|
|
|
/*
|
|
|
|
* NotificationManagerService is dependant on MountService,
|
|
|
|
* (for media / usb notifications) so we must start MountService first.
|
|
|
|
*/
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Mount Service");
|
2010-02-03 14:43:09 -08:00
|
|
|
ServiceManager.addService("mount", new MountService(context));
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Mount Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Notification Manager");
|
2010-02-03 14:43:09 -08:00
|
|
|
notification = new NotificationManagerService(context, statusBar, lights);
|
|
|
|
ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Notification Manager", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Device Storage Monitor");
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
|
|
|
|
new DeviceStorageMonitorService(context));
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Location Manager");
|
2010-02-22 16:36:44 -05:00
|
|
|
location = new LocationManagerService(context);
|
|
|
|
ServiceManager.addService(Context.LOCATION_SERVICE, location);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Location Manager", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2010-07-13 15:32:16 +08:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "Country Detector");
|
|
|
|
countryDetector = new CountryDetectorService(context);
|
|
|
|
ServiceManager.addService(Context.COUNTRY_DETECTOR, countryDetector);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting Country Detector", e);
|
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Search Service");
|
2010-01-12 18:14:19 -08:00
|
|
|
ServiceManager.addService(Context.SEARCH_SERVICE,
|
|
|
|
new SearchManagerService(context));
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Search Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2009-09-11 16:40:01 -07:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "DropBox Service");
|
2009-10-27 18:23:39 -07:00
|
|
|
ServiceManager.addService(Context.DROPBOX_SERVICE,
|
2009-11-12 11:32:50 -08:00
|
|
|
new DropBoxManagerService(context, new File("/data/system/dropbox")));
|
2009-09-11 16:40:01 -07:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting DropBoxManagerService", e);
|
2009-09-11 16:40:01 -07:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Wallpaper Service");
|
2009-08-13 10:20:21 -07:00
|
|
|
wallpaper = new WallpaperManagerService(context);
|
|
|
|
ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Wallpaper Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Audio Service");
|
2009-03-03 19:31:44 -08:00
|
|
|
ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context));
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Audio Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Headset Observer");
|
2009-03-03 19:31:44 -08:00
|
|
|
// Listen for wired headset changes
|
|
|
|
headset = new HeadsetObserver(context);
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting HeadsetObserver", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2009-08-12 15:15:43 -05:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Dock Observer");
|
2009-08-12 15:15:43 -05:00
|
|
|
// Listen for dock station changes
|
2009-09-10 18:37:37 -05:00
|
|
|
dock = new DockObserver(context, power);
|
2009-08-12 15:15:43 -05:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting DockObserver", e);
|
2009-08-12 15:15:43 -05:00
|
|
|
}
|
|
|
|
|
2010-06-23 17:36:36 -04:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "USB Observer");
|
|
|
|
// Listen for USB changes
|
|
|
|
usb = new UsbObserver(context);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting UsbObserver", e);
|
|
|
|
}
|
|
|
|
|
2010-03-04 18:41:49 -08:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "UI Mode Manager Service");
|
2010-06-23 17:36:36 -04:00
|
|
|
// Listen for UI mode changes
|
2010-03-04 18:41:49 -08:00
|
|
|
uiMode = new UiModeManagerService(context);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting UiModeManagerService", e);
|
|
|
|
}
|
|
|
|
|
2009-04-29 14:03:25 -07:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Backup Service");
|
2010-01-12 18:14:19 -08:00
|
|
|
ServiceManager.addService(Context.BACKUP_SERVICE,
|
|
|
|
new BackupManagerService(context));
|
2009-04-29 14:03:25 -07:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Backup Service", e);
|
2009-04-29 14:03:25 -07:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "AppWidget Service");
|
2009-03-11 12:11:56 -07:00
|
|
|
appWidget = new AppWidgetService(context);
|
|
|
|
ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
|
2009-03-03 19:31:44 -08:00
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting AppWidget Service", e);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2010-02-19 17:02:21 -08:00
|
|
|
try {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Recognition Service");
|
2010-02-19 17:02:21 -08:00
|
|
|
recognition = new RecognitionManagerService(context);
|
|
|
|
} catch (Throwable e) {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.e(TAG, "Failure starting Recognition Service", e);
|
2010-02-19 17:02:21 -08:00
|
|
|
}
|
2010-09-23 16:12:11 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
Slog.i(TAG, "Nfc Service");
|
|
|
|
NfcService nfc;
|
|
|
|
try {
|
|
|
|
nfc = new NfcService(context);
|
|
|
|
} catch (UnsatisfiedLinkError e) { // gross hack to detect NFC
|
|
|
|
nfc = null;
|
|
|
|
Slog.w(TAG, "No NFC support");
|
|
|
|
}
|
|
|
|
ServiceManager.addService(Context.NFC_SERVICE, nfc);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting NFC Service", e);
|
|
|
|
}
|
2010-02-19 17:02:21 -08:00
|
|
|
|
2010-03-25 16:20:14 -07:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "DiskStats Service");
|
|
|
|
ServiceManager.addService("diskstats", new DiskStatsService(context));
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting DiskStats Service", e);
|
|
|
|
}
|
2010-05-28 01:54:03 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
// need to add this service even if SamplingProfilerIntegration.isEnabled()
|
|
|
|
// is false, because it is this service that detects system property change and
|
|
|
|
// turns on SamplingProfilerIntegration. Plus, when sampling profiler doesn't work,
|
|
|
|
// there is little overhead for running this service.
|
|
|
|
Slog.i(TAG, "SamplingProfiler Service");
|
|
|
|
ServiceManager.addService("samplingprofiler",
|
|
|
|
new SamplingProfilerService(context));
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting SamplingProfiler Service", e);
|
|
|
|
}
|
2010-08-06 12:06:04 +08:00
|
|
|
|
2010-09-13 16:24:08 -07:00
|
|
|
try {
|
|
|
|
Slog.i(TAG, "NetworkTimeUpdateService");
|
|
|
|
networkTimeUpdater = new NetworkTimeUpdateService(context);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Slog.e(TAG, "Failure starting NetworkTimeUpdate service");
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the ADB_ENABLED setting value matches the secure property value
|
|
|
|
Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED,
|
|
|
|
"1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0);
|
|
|
|
|
|
|
|
// register observer to listen for settings changes
|
|
|
|
mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED),
|
|
|
|
false, new AdbSettingsObserver());
|
|
|
|
|
2009-09-28 13:25:46 -07:00
|
|
|
// Before things start rolling, be sure we have decided whether
|
|
|
|
// we are in safe mode.
|
2009-09-02 13:26:28 -07:00
|
|
|
final boolean safeMode = wm.detectSafeMode();
|
2009-09-28 13:25:46 -07:00
|
|
|
if (safeMode) {
|
|
|
|
try {
|
|
|
|
ActivityManagerNative.getDefault().enterSafeMode();
|
2010-02-14 16:18:56 -08:00
|
|
|
// Post the safe mode state in the Zygote class
|
|
|
|
Zygote.systemInSafeMode = true;
|
|
|
|
// Disable the JIT for the system_server process
|
|
|
|
VMRuntime.getRuntime().disableJitCompilation();
|
2009-09-28 13:25:46 -07:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
2010-02-14 16:18:56 -08:00
|
|
|
} else {
|
|
|
|
// Enable the JIT for the system_server process
|
|
|
|
VMRuntime.getRuntime().startJitCompilation();
|
2009-09-28 13:25:46 -07:00
|
|
|
}
|
2009-12-04 10:31:43 -08:00
|
|
|
|
2009-09-28 13:25:46 -07:00
|
|
|
// It is now time to start up the app processes...
|
2009-07-08 17:09:14 -07:00
|
|
|
|
2010-01-12 18:14:19 -08:00
|
|
|
if (devicePolicy != null) {
|
|
|
|
devicePolicy.systemReady();
|
|
|
|
}
|
|
|
|
|
2009-07-08 17:09:14 -07:00
|
|
|
if (notification != null) {
|
|
|
|
notification.systemReady();
|
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
if (statusBar != null) {
|
|
|
|
statusBar.systemReady();
|
|
|
|
}
|
|
|
|
wm.systemReady();
|
|
|
|
power.systemReady();
|
|
|
|
try {
|
|
|
|
pm.systemReady();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:26:28 -07:00
|
|
|
// These are needed to propagate to the runnable below.
|
2010-04-12 08:18:45 -07:00
|
|
|
final StatusBarManagerService statusBarF = statusBar;
|
2009-09-02 13:26:28 -07:00
|
|
|
final BatteryService batteryF = battery;
|
|
|
|
final ConnectivityService connectivityF = connectivity;
|
|
|
|
final DockObserver dockF = dock;
|
2010-06-23 17:36:36 -04:00
|
|
|
final UsbObserver usbF = usb;
|
2010-04-01 14:45:18 -07:00
|
|
|
final ThrottleService throttleF = throttle;
|
2010-03-04 18:41:49 -08:00
|
|
|
final UiModeManagerService uiModeF = uiMode;
|
2009-09-02 13:26:28 -07:00
|
|
|
final AppWidgetService appWidgetF = appWidget;
|
|
|
|
final WallpaperManagerService wallpaperF = wallpaper;
|
|
|
|
final InputMethodManagerService immF = imm;
|
2010-02-19 17:02:21 -08:00
|
|
|
final RecognitionManagerService recognitionF = recognition;
|
2010-02-22 16:36:44 -05:00
|
|
|
final LocationManagerService locationF = location;
|
2010-07-13 15:32:16 +08:00
|
|
|
final CountryDetectorService countryDetectorF = countryDetector;
|
2010-09-13 16:24:08 -07:00
|
|
|
final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
|
2009-12-04 10:31:43 -08:00
|
|
|
|
2009-09-02 13:26:28 -07:00
|
|
|
// We now tell the activity manager it is okay to run third party
|
|
|
|
// code. It will call back into us once it has gotten to the state
|
|
|
|
// where third party code can really run (but before it has actually
|
|
|
|
// started launching the initial applications), for us to complete our
|
|
|
|
// initialization.
|
|
|
|
((ActivityManagerService)ActivityManagerNative.getDefault())
|
|
|
|
.systemReady(new Runnable() {
|
|
|
|
public void run() {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Making services ready");
|
2009-12-04 10:31:43 -08:00
|
|
|
|
2010-04-08 16:41:23 -05:00
|
|
|
if (statusBarF != null) statusBarF.systemReady2();
|
2009-09-02 13:26:28 -07:00
|
|
|
if (batteryF != null) batteryF.systemReady();
|
|
|
|
if (connectivityF != null) connectivityF.systemReady();
|
|
|
|
if (dockF != null) dockF.systemReady();
|
2010-06-23 17:36:36 -04:00
|
|
|
if (usbF != null) usbF.systemReady();
|
2010-03-04 18:41:49 -08:00
|
|
|
if (uiModeF != null) uiModeF.systemReady();
|
2010-02-19 17:02:21 -08:00
|
|
|
if (recognitionF != null) recognitionF.systemReady();
|
2009-09-02 13:26:28 -07:00
|
|
|
Watchdog.getInstance().start();
|
|
|
|
|
|
|
|
// It is now okay to let the various system services start their
|
|
|
|
// third party code...
|
2009-12-04 10:31:43 -08:00
|
|
|
|
2009-09-02 13:26:28 -07:00
|
|
|
if (appWidgetF != null) appWidgetF.systemReady(safeMode);
|
|
|
|
if (wallpaperF != null) wallpaperF.systemReady();
|
|
|
|
if (immF != null) immF.systemReady();
|
2010-02-22 16:36:44 -05:00
|
|
|
if (locationF != null) locationF.systemReady();
|
2010-07-13 15:32:16 +08:00
|
|
|
if (countryDetectorF != null) countryDetectorF.systemReady();
|
2010-04-01 14:45:18 -07:00
|
|
|
if (throttleF != null) throttleF.systemReady();
|
2010-09-13 16:24:08 -07:00
|
|
|
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
|
2009-09-02 13:26:28 -07:00
|
|
|
}
|
|
|
|
});
|
2009-12-04 10:31:43 -08:00
|
|
|
|
2010-09-10 09:19:50 -07:00
|
|
|
// For debug builds, log event loop stalls to dropbox for analysis.
|
2010-09-13 21:29:05 -07:00
|
|
|
if (StrictMode.conditionallyEnableDebugLogging()) {
|
|
|
|
Slog.i(TAG, "Enabled StrictMode for system server main thread.");
|
2010-09-10 09:19:50 -07:00
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
Looper.loop();
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.d(TAG, "System ServerThread is exiting!");
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 15:45:18 -05:00
|
|
|
public class SystemServer {
|
2009-03-03 19:31:44 -08:00
|
|
|
private static final String TAG = "SystemServer";
|
|
|
|
|
|
|
|
public static final int FACTORY_TEST_OFF = 0;
|
|
|
|
public static final int FACTORY_TEST_LOW_LEVEL = 1;
|
|
|
|
public static final int FACTORY_TEST_HIGH_LEVEL = 2;
|
2009-05-05 22:26:12 -07:00
|
|
|
|
2009-09-04 18:31:17 -07:00
|
|
|
static Timer timer;
|
|
|
|
static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
|
|
|
|
|
2009-05-05 22:26:12 -07:00
|
|
|
/**
|
|
|
|
* This method is called from Zygote to initialize the system. This will cause the native
|
2009-03-03 19:31:44 -08:00
|
|
|
* services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back
|
|
|
|
* up into init2() to start the Android services.
|
2009-05-05 22:26:12 -07:00
|
|
|
*/
|
2009-03-03 19:31:44 -08:00
|
|
|
native public static void init1(String[] args);
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2009-09-04 18:31:17 -07:00
|
|
|
if (SamplingProfilerIntegration.isEnabled()) {
|
|
|
|
SamplingProfilerIntegration.start();
|
|
|
|
timer = new Timer();
|
|
|
|
timer.schedule(new TimerTask() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2010-05-28 01:54:03 -07:00
|
|
|
SamplingProfilerIntegration.writeSnapshot("system_server", null);
|
2009-09-04 18:31:17 -07:00
|
|
|
}
|
|
|
|
}, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
|
|
|
|
}
|
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
// The system server has to run all of the time, so it needs to be
|
|
|
|
// as efficient as possible with its memory usage.
|
|
|
|
VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
|
2010-05-28 01:54:03 -07:00
|
|
|
|
2009-03-03 19:31:44 -08:00
|
|
|
System.loadLibrary("android_servers");
|
|
|
|
init1(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final void init2() {
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "Entered the Android system server!");
|
2009-03-03 19:31:44 -08:00
|
|
|
Thread thr = new ServerThread();
|
|
|
|
thr.setName("android.server.ServerThread");
|
|
|
|
thr.start();
|
|
|
|
}
|
|
|
|
}
|