| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.app.ActivityManagerNative; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentService; |
| 22 | import android.content.Context; |
| 23 | import android.content.pm.IPackageManager; |
| 24 | import android.database.ContentObserver; |
| 25 | import android.database.Cursor; |
| 26 | import android.media.AudioService; |
| 27 | import android.os.Looper; |
| 28 | import android.os.RemoteException; |
| 29 | import android.os.ServiceManager; |
| 30 | import android.os.SystemClock; |
| 31 | import android.os.SystemProperties; |
| 32 | import android.os.IBinder; |
| 33 | import android.provider.Settings; |
| 34 | import android.provider.Contacts.People; |
| 35 | import android.server.BluetoothDeviceService; |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 36 | import android.server.BluetoothA2dpService; |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | import android.server.checkin.FallbackCheckinService; |
| 38 | import android.server.search.SearchManagerService; |
| 39 | import android.util.EventLog; |
| 40 | import android.util.Log; |
| 41 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 42 | import dalvik.system.TouchDex; |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 43 | import dalvik.system.VMRuntime; |
| 44 | |
| 45 | import com.android.server.am.ActivityManagerService; |
| 46 | import com.android.server.status.StatusBarService; |
| 47 | |
| 48 | import java.lang.reflect.Constructor; |
| 49 | import java.lang.reflect.InvocationTargetException; |
| 50 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | class ServerThread extends Thread { |
| 52 | private static final String TAG = "SystemServer"; |
| 53 | private final static boolean INCLUDE_DEMO = false; |
| 54 | |
| 55 | private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010; |
| 56 | |
| 57 | private ContentResolver mContentResolver; |
| 58 | |
| 59 | private class AdbSettingsObserver extends ContentObserver { |
| 60 | public AdbSettingsObserver() { |
| 61 | super(null); |
| 62 | } |
| 63 | @Override |
| 64 | public void onChange(boolean selfChange) { |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 65 | boolean enableAdb = (Settings.Secure.getInt(mContentResolver, |
| 66 | Settings.Secure.ADB_ENABLED, 0) > 0); |
| 67 | // setting this secure property will start or stop adbd |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 68 | SystemProperties.set("persist.service.adb.enable", enableAdb ? "1" : "0"); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void run() { |
| 74 | EventLog.writeEvent(LOG_BOOT_PROGRESS_SYSTEM_RUN, |
| 75 | SystemClock.uptimeMillis()); |
| 76 | |
| 77 | ActivityManagerService.prepareTraceFile(false); // create dir |
| 78 | |
| 79 | Looper.prepare(); |
| 80 | |
| 81 | android.os.Process.setThreadPriority( |
| 82 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| 83 | |
| 84 | String factoryTestStr = SystemProperties.get("ro.factorytest"); |
| 85 | int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF |
| 86 | : Integer.parseInt(factoryTestStr); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 87 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 88 | PowerManagerService power = null; |
| 89 | IPackageManager pm = null; |
| 90 | Context context = null; |
| 91 | WindowManagerService wm = null; |
| 92 | BluetoothDeviceService bluetooth = null; |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 93 | BluetoothA2dpService bluetoothA2dp = null; |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 94 | HeadsetObserver headset = null; |
| 95 | |
| 96 | // Critical services... |
| 97 | try { |
| 98 | Log.i(TAG, "Starting Power Manager."); |
| 99 | power = new PowerManagerService(); |
| 100 | ServiceManager.addService(Context.POWER_SERVICE, power); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 101 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | Log.i(TAG, "Starting Activity Manager."); |
| 103 | context = ActivityManagerService.main(factoryTest); |
| 104 | |
| 105 | Log.i(TAG, "Starting telephony registry"); |
| 106 | ServiceManager.addService("telephony.registry", new TelephonyRegistry(context)); |
| 107 | |
| 108 | AttributeCache.init(context); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 109 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 110 | Log.i(TAG, "Starting Package Manager."); |
| 111 | pm = PackageManagerService.main(context, |
| 112 | factoryTest != SystemServer.FACTORY_TEST_OFF); |
| 113 | |
| 114 | ActivityManagerService.setSystemProcess(); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 115 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 116 | mContentResolver = context.getContentResolver(); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 117 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | Log.i(TAG, "Starting Content Manager."); |
| 119 | ContentService.main(context, |
| 120 | factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 121 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | Log.i(TAG, "Starting System Content Providers."); |
| 123 | ActivityManagerService.installSystemProviders(); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 124 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 125 | Log.i(TAG, "Starting Battery Service."); |
| 126 | BatteryService battery = new BatteryService(context); |
| 127 | ServiceManager.addService("battery", battery); |
| 128 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 129 | // only initialize the power service after we have started the |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 130 | // content providers and the batter service. |
| 131 | power.init(context, ActivityManagerService.getDefault(), battery); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 132 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 133 | Log.i(TAG, "Starting Alarm Manager."); |
| 134 | AlarmManagerService alarm = new AlarmManagerService(context); |
| 135 | ServiceManager.addService(Context.ALARM_SERVICE, alarm); |
| 136 | |
| 137 | Watchdog.getInstance().init(context, battery, power, alarm, |
| 138 | ActivityManagerService.self()); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 139 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 140 | // Sensor Service is needed by Window Manager, so this goes first |
| 141 | Log.i(TAG, "Starting Sensor Service."); |
| 142 | ServiceManager.addService(Context.SENSOR_SERVICE, new SensorService(context)); |
| 143 | |
| 144 | Log.i(TAG, "Starting Window Manager."); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 145 | wm = WindowManagerService.main(context, power, |
| 146 | factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 147 | ServiceManager.addService(Context.WINDOW_SERVICE, wm); |
| 148 | |
| 149 | ((ActivityManagerService)ServiceManager.getService("activity")) |
| 150 | .setWindowManager(wm); |
| 151 | |
| 152 | // Skip Bluetooth if we have an emulator kernel |
| 153 | // TODO: Use a more reliable check to see if this product should |
| 154 | // support Bluetooth - see bug 988521 |
| 155 | if (SystemProperties.get("ro.kernel.qemu").equals("1")) { |
| 156 | Log.i(TAG, "Registering null Bluetooth Service (emulator)"); |
| 157 | ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); |
| 158 | } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { |
| 159 | Log.i(TAG, "Registering null Bluetooth Service (factory test)"); |
| 160 | ServiceManager.addService(Context.BLUETOOTH_SERVICE, null); |
| 161 | } else { |
| 162 | Log.i(TAG, "Starting Bluetooth Service."); |
| 163 | bluetooth = new BluetoothDeviceService(context); |
| 164 | bluetooth.init(); |
| 165 | ServiceManager.addService(Context.BLUETOOTH_SERVICE, bluetooth); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 166 | bluetoothA2dp = new BluetoothA2dpService(context); |
| 167 | ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE, |
| 168 | bluetoothA2dp); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 169 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 170 | int bluetoothOn = Settings.Secure.getInt(mContentResolver, |
| 171 | Settings.Secure.BLUETOOTH_ON, 0); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 172 | if (bluetoothOn > 0) { |
| 173 | bluetooth.enable(null); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | } catch (RuntimeException e) { |
| 178 | Log.e("System", "Failure starting core service", e); |
| 179 | } |
| 180 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 181 | StatusBarService statusBar = null; |
| 182 | InputMethodManagerService imm = null; |
| 183 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 184 | if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 185 | try { |
| 186 | Log.i(TAG, "Starting Status Bar Service."); |
| 187 | statusBar = new StatusBarService(context); |
| 188 | ServiceManager.addService("statusbar", statusBar); |
| 189 | com.android.server.status.StatusBarPolicy.installIcons(context, statusBar); |
| 190 | } catch (Throwable e) { |
| 191 | Log.e(TAG, "Failure starting StatusBarService", e); |
| 192 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 193 | |
| 194 | try { |
| 195 | Log.i(TAG, "Starting Clipboard Service."); |
| 196 | ServiceManager.addService("clipboard", new ClipboardService(context)); |
| 197 | } catch (Throwable e) { |
| 198 | Log.e(TAG, "Failure starting Clipboard Service", e); |
| 199 | } |
| 200 | |
| 201 | try { |
| 202 | Log.i(TAG, "Starting Input Method Service."); |
| 203 | imm = new InputMethodManagerService(context, statusBar); |
| 204 | ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); |
| 205 | } catch (Throwable e) { |
| 206 | Log.e(TAG, "Failure starting Input Manager Service", e); |
| 207 | } |
| 208 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 209 | try { |
| 210 | Log.i(TAG, "Starting Hardware Service."); |
| 211 | ServiceManager.addService("hardware", new HardwareService(context)); |
| 212 | } catch (Throwable e) { |
| 213 | Log.e(TAG, "Failure starting Hardware Service", e); |
| 214 | } |
| 215 | |
| 216 | try { |
| 217 | Log.i(TAG, "Starting NetStat Service."); |
| 218 | ServiceManager.addService("netstat", new NetStatService(context)); |
| 219 | } catch (Throwable e) { |
| 220 | Log.e(TAG, "Failure starting NetStat Service", e); |
| 221 | } |
| 222 | |
| 223 | try { |
| 224 | Log.i(TAG, "Starting Connectivity Service."); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 225 | ServiceManager.addService(Context.CONNECTIVITY_SERVICE, |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 226 | ConnectivityService.getInstance(context)); |
| 227 | } catch (Throwable e) { |
| 228 | Log.e(TAG, "Failure starting Connectivity Service", e); |
| 229 | } |
| 230 | |
| 231 | try { |
| 232 | Log.i(TAG, "Starting Notification Manager."); |
| 233 | ServiceManager.addService(Context.NOTIFICATION_SERVICE, |
| 234 | new NotificationManagerService(context, statusBar)); |
| 235 | } catch (Throwable e) { |
| 236 | Log.e(TAG, "Failure starting Notification Manager", e); |
| 237 | } |
| 238 | |
| 239 | try { |
| 240 | // MountService must start after NotificationManagerService |
| 241 | Log.i(TAG, "Starting Mount Service."); |
| 242 | ServiceManager.addService("mount", new MountService(context)); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 243 | } catch (Throwable e) { |
| 244 | Log.e(TAG, "Failure starting Mount Service", e); |
| 245 | } |
| 246 | |
| 247 | try { |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 248 | Log.i(TAG, "Starting DeviceStorageMonitor service"); |
| 249 | ServiceManager.addService(DeviceStorageMonitorService.SERVICE, |
| 250 | new DeviceStorageMonitorService(context)); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 251 | } catch (Throwable e) { |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 252 | Log.e(TAG, "Failure starting DeviceStorageMonitor service", e); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 253 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 254 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 255 | try { |
| 256 | Log.i(TAG, "Starting Location Manager."); |
| 257 | ServiceManager.addService(Context.LOCATION_SERVICE, new LocationManagerService(context)); |
| 258 | } catch (Throwable e) { |
| 259 | Log.e(TAG, "Failure starting Location Manager", e); |
| 260 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 261 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 262 | try { |
| 263 | Log.i(TAG, "Starting Search Service."); |
| 264 | ServiceManager.addService( Context.SEARCH_SERVICE, new SearchManagerService(context) ); |
| 265 | } catch (Throwable e) { |
| 266 | Log.e(TAG, "Failure starting Search Service", e); |
| 267 | } |
| 268 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 269 | if (INCLUDE_DEMO) { |
| 270 | Log.i(TAG, "Installing demo data..."); |
| 271 | (new DemoThread(context)).start(); |
| 272 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 273 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 274 | try { |
| 275 | Log.i(TAG, "Starting Checkin Service"); |
| 276 | addService(context, "checkin", "com.google.android.server.checkin.CheckinService", |
| 277 | FallbackCheckinService.class); |
| 278 | } catch (Throwable e) { |
| 279 | Log.e(TAG, "Failure starting Checkin Service", e); |
| 280 | } |
| 281 | |
| 282 | try { |
| 283 | Log.i(TAG, "Starting Wallpaper Service"); |
| 284 | ServiceManager.addService(Context.WALLPAPER_SERVICE, new WallpaperService(context)); |
| 285 | } catch (Throwable e) { |
| 286 | Log.e(TAG, "Failure starting Wallpaper Service", e); |
| 287 | } |
| 288 | |
| 289 | try { |
| 290 | Log.i(TAG, "Starting Audio Service"); |
| 291 | ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context)); |
| 292 | } catch (Throwable e) { |
| The Android Open Source Project | 22f7dfd | 2009-01-20 14:03:58 -0800 | [diff] [blame] | 293 | Log.e(TAG, "Failure starting Audio Service", e); |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 294 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 295 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 296 | try { |
| 297 | Log.i(TAG, "Starting HeadsetObserver"); |
| 298 | // Listen for wired headset changes |
| 299 | headset = new HeadsetObserver(context); |
| 300 | } catch (Throwable e) { |
| 301 | Log.e(TAG, "Failure starting HeadsetObserver", e); |
| 302 | } |
| The Android Open Source Project | 22f7dfd | 2009-01-20 14:03:58 -0800 | [diff] [blame] | 303 | |
| 304 | try { |
| 305 | Log.i(TAG, "Starting Gadget Service"); |
| 306 | ServiceManager.addService(Context.GADGET_SERVICE, new GadgetService(context)); |
| 307 | } catch (Throwable e) { |
| 308 | Log.e(TAG, "Failure starting Gadget Service", e); |
| 309 | } |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 312 | // make sure the ADB_ENABLED setting value matches the secure property value |
| 313 | Settings.Secure.putInt(mContentResolver, Settings.Secure.ADB_ENABLED, |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | "1".equals(SystemProperties.get("persist.service.adb.enable")) ? 1 : 0); |
| 315 | |
| 316 | // register observer to listen for settings changes |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 317 | mContentResolver.registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.ADB_ENABLED), |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 318 | false, new AdbSettingsObserver()); |
| 319 | |
| 320 | // It is now time to start up the app processes... |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 321 | if (statusBar != null) { |
| 322 | statusBar.systemReady(); |
| 323 | } |
| 324 | if (imm != null) { |
| 325 | imm.systemReady(); |
| 326 | } |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 327 | wm.systemReady(); |
| 328 | power.systemReady(); |
| 329 | try { |
| 330 | pm.systemReady(); |
| 331 | } catch (RemoteException e) { |
| 332 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 333 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | // After making the following code, third party code may be running... |
| 335 | try { |
| 336 | ActivityManagerNative.getDefault().systemReady(); |
| 337 | } catch (RemoteException e) { |
| 338 | } |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 339 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 340 | Watchdog.getInstance().start(); |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 341 | |
| The Android Open Source Project | 54b6cfa | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | Looper.loop(); |
| 343 | Log.d(TAG, "System ServerThread is exiting!"); |
| 344 | } |
| 345 | |
| 346 | private void addService(Context context, String name, String serviceClass, |
| 347 | Class<? extends IBinder> fallback) { |
| 348 | |
| 349 | final IBinder service = findService(context, serviceClass, fallback); |
| 350 | if (service != null) { |
| 351 | ServiceManager.addService(name, service); |
| 352 | } else { |
| 353 | Log.e(TAG, "Failure starting service '" + name + "' with class " + serviceClass); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | private IBinder findService(Context context, String serviceClass, |
| 358 | Class<? extends IBinder> fallback) { |
| 359 | |
| 360 | IBinder service = null; |
| 361 | try { |
| 362 | Class<?> klass = Class.forName(serviceClass); |
| 363 | Constructor<?> c = klass.getConstructor(Context.class); |
| 364 | service = (IBinder) c.newInstance(context); |
| 365 | } catch (ClassNotFoundException e) { |
| 366 | // Ignore |
| 367 | } catch (IllegalAccessException e) { |
| 368 | // Ignore |
| 369 | } catch (NoSuchMethodException e) { |
| 370 | // Ignore |
| 371 | } catch (InvocationTargetException e) { |
| 372 | // Ignore |
| 373 | } catch (InstantiationException e) { |
| 374 | // Ignore |
| 375 | } |
| 376 | |
| 377 | if (service == null && fallback != null) { |
| 378 | Log.w(TAG, "Could not find " + serviceClass + ", trying fallback"); |
| 379 | try { |
| 380 | service = fallback.newInstance(); |
| 381 | } catch (IllegalAccessException e) { |
| 382 | // Ignore |
| 383 | } catch (InstantiationException e) { |
| 384 | // Ignore |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | return service; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | class DemoThread extends Thread |
| 393 | { |
| 394 | DemoThread(Context context) |
| 395 | { |
| 396 | mContext = context; |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public void run() |
| 401 | { |
| 402 | try { |
| 403 | Cursor c = mContext.getContentResolver().query(People.CONTENT_URI, null, null, null, null); |
| 404 | boolean hasData = c != null && c.moveToFirst(); |
| 405 | if (c != null) { |
| 406 | c.deactivate(); |
| 407 | } |
| 408 | if (!hasData) { |
| 409 | DemoDataSet dataset = new DemoDataSet(); |
| 410 | dataset.add(mContext); |
| 411 | } |
| 412 | } catch (Throwable e) { |
| 413 | Log.e("SystemServer", "Failure installing demo data", e); |
| 414 | } |
| 415 | |
| 416 | } |
| 417 | |
| 418 | Context mContext; |
| 419 | } |
| 420 | |
| 421 | public class SystemServer |
| 422 | { |
| 423 | private static final String TAG = "SystemServer"; |
| 424 | |
| 425 | public static final int FACTORY_TEST_OFF = 0; |
| 426 | public static final int FACTORY_TEST_LOW_LEVEL = 1; |
| 427 | public static final int FACTORY_TEST_HIGH_LEVEL = 2; |
| 428 | |
| 429 | /** |
| 430 | * This method is called from Zygote to initialize the system. This will cause the native |
| 431 | * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back |
| 432 | * up into init2() to start the Android services. |
| 433 | */ |
| 434 | native public static void init1(String[] args); |
| 435 | |
| 436 | public static void main(String[] args) { |
| 437 | // The system server has to run all of the time, so it needs to be |
| 438 | // as efficient as possible with its memory usage. |
| 439 | VMRuntime.getRuntime().setTargetHeapUtilization(0.8f); |
| 440 | |
| 441 | System.loadLibrary("android_servers"); |
| 442 | init1(args); |
| 443 | } |
| 444 | |
| 445 | public static final void init2() { |
| 446 | Log.i(TAG, "Entered the Android system server!"); |
| 447 | Thread thr = new ServerThread(); |
| 448 | thr.setName("android.server.ServerThread"); |
| 449 | thr.start(); |
| 450 | } |
| 451 | } |