- 浏览: 110209 次
- 性别:
- 来自: 北京
最新评论
-
ocean1999:
有代码没 想学习哈 邮箱65614435@qq.com ,非常 ...
使用Google app做了个文件上传网站 http://avatar-share.appspot.com -
mywayscut:
很不错。详细介绍下吧,上传到blob的实现的怎么样的
使用Google app做了个文件上传网站 http://avatar-share.appspot.com
System Server是Android系统的核心,他在Dalvik虚拟机启动后立即开始初始化和运行。其它的系统服务在System Server进程的环境中运行。/base/services/java/com/android/server/SystemServer.java
/** * This method is called from Zygote to initialize the system. This will cause the native * services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back * up into init2() to start the Android services. */ native public static void init1(String[] args); public static void main(String[] args) { if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) { // If a device's clock is before 1970 (before 0), a lot of // APIs crash dealing with negative numbers, notably // java.io.File#setLastModified, so instead we fake it and // hope that time from cell towers or NTP fixes it // shortly. Slog.w(TAG, "System clock is before 1970; setting to 1970."); SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME); } if (SamplingProfilerIntegration.isEnabled()) { SamplingProfilerIntegration.start(); timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { SamplingProfilerIntegration.writeSnapshot("system_server"); } }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL); } // 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); System.loadLibrary("android_servers"); init1(args); } public static final void init2() { Slog.i(TAG, "Entered the Android system server!"); Thread thr = new ServerThread(); thr.setName("android.server.ServerThread"); thr.start(); }
在main函数中,首先检查系统时间设置和SamplingProfiler。然后加载一个叫android_servers的本地库,他提供本地方法的接口(源程序在framework/base/services/jni/目录中)。然后调用本地方法设置服务。具体执行设置的代码在frameworks/base/cmds/system_server/library/system_init.cpp中。
extern "C" status_t system_init() { LOGI("Entered system_init()"); sp<ProcessState> proc(ProcessState::self()); sp<IServiceManager> sm = defaultServiceManager(); LOGI("ServiceManager: %p\n", sm.get()); sp<GrimReaper> grim = new GrimReaper(); sm->asBinder()->linkToDeath(grim, grim.get(), 0); char propBuf[PROPERTY_VALUE_MAX]; property_get("system_init.startsurfaceflinger", propBuf, "1"); if (strcmp(propBuf, "1") == 0) { // Start the SurfaceFlinger SurfaceFlinger::instantiate(); } // Start the sensor service SensorService::instantiate(); // On the simulator, audioflinger et al don't get started the // same way as on the device, and we need to start them here if (!proc->supportsProcesses()) { // Start the AudioFlinger AudioFlinger::instantiate(); // Start the media playback service MediaPlayerService::instantiate(); // Start the camera service CameraService::instantiate(); // Start the audio policy service AudioPolicyService::instantiate(); } // And now start the Android runtime. We have to do this bit // of nastiness because the Android runtime initialization requires // some of the core system services to already be started. // All other servers should just start the Android runtime at // the beginning of their processes's main(), before calling // the init function. LOGI("System server: starting Android runtime.\n"); AndroidRuntime* runtime = AndroidRuntime::getRuntime(); LOGI("System server: starting Android services.\n"); runtime->callStatic("com/android/server/SystemServer", "init2"); // If running in our own process, just go into the thread // pool. Otherwise, call the initialization finished // func to let this process continue its initilization. if (proc->supportsProcesses()) { LOGI("System server: entering thread pool.\n"); ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); LOGI("System server: exiting thread pool.\n"); } return NO_ERROR; }
等初始化传感器,视频,音频等服务后,调用一个回调方法init2 (在SystemServer.java中)。在上面的代码可以看到,这个方法开启了ServerThread来初始化其它的服务。
public void run() { EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); Looper.prepare(); android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_FOREGROUND); BinderInternal.disableBackgroundScheduling(true); android.os.Process.setCanSelfBackground(false); // Check whether we failed to shut down last time we tried. { final String shutdownAction = SystemProperties.get( ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); if (shutdownAction != null && shutdownAction.length() > 0) { boolean reboot = (shutdownAction.charAt(0) == '1'); final String reason; if (shutdownAction.length() > 1) { reason = shutdownAction.substring(1, shutdownAction.length()); } else { reason = null; } ShutdownThread.rebootOrShutdown(reboot, reason); } } String factoryTestStr = SystemProperties.get("ro.factorytest"); int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF : Integer.parseInt(factoryTestStr); LightsService lights = null; PowerManagerService power = null; BatteryService battery = null; ConnectivityService connectivity = null; IPackageManager pm = null; Context context = null; WindowManagerService wm = null; BluetoothService bluetooth = null; BluetoothA2dpService bluetoothA2dp = null; HeadsetObserver headset = null; DockObserver dock = null; UsbService usb = null; UiModeManagerService uiMode = null; RecognitionManagerService recognition = null; ThrottleService throttle = null; // Critical services... try { Slog.i(TAG, "Entropy Service"); ServiceManager.addService("entropy", new EntropyService()); Slog.i(TAG, "Power Manager"); power = new PowerManagerService(); ServiceManager.addService(Context.POWER_SERVICE, power); Slog.i(TAG, "Activity Manager"); context = ActivityManagerService.main(factoryTest); Slog.i(TAG, "Telephony Registry"); ServiceManager.addService("telephony.registry", new TelephonyRegistry(context)); AttributeCache.init(context); Slog.i(TAG, "Package Manager"); pm = PackageManagerService.main(context, factoryTest != SystemServer.FACTORY_TEST_OFF); ActivityManagerService.setSystemProcess(); mContentResolver = context.getContentResolver(); // The AccountManager must come before the ContentService try { Slog.i(TAG, "Account Manager"); ServiceManager.addService(Context.ACCOUNT_SERVICE, new AccountManagerService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Account Manager", e); } Slog.i(TAG, "Content Manager"); ContentService.main(context, factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL); Slog.i(TAG, "System Content Providers"); ActivityManagerService.installSystemProviders(); Slog.i(TAG, "Battery Service"); battery = new BatteryService(context); ServiceManager.addService("battery", battery); Slog.i(TAG, "Lights Service"); lights = new LightsService(context); Slog.i(TAG, "Vibrator Service"); ServiceManager.addService("vibrator", new VibratorService(context)); // only initialize the power service after we have started the // lights service, content providers and the battery service. power.init(context, lights, ActivityManagerService.getDefault(), battery); Slog.i(TAG, "Alarm Manager"); AlarmManagerService alarm = new AlarmManagerService(context); ServiceManager.addService(Context.ALARM_SERVICE, alarm); Slog.i(TAG, "Init Watchdog"); Watchdog.getInstance().init(context, battery, power, alarm, ActivityManagerService.self()); Slog.i(TAG, "Window Manager"); 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")) { Slog.i(TAG, "Registering null Bluetooth Service (emulator)"); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null); } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) { Slog.i(TAG, "Registering null Bluetooth Service (factory test)"); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, null); } else { Slog.i(TAG, "Bluetooth Service"); bluetooth = new BluetoothService(context); ServiceManager.addService(BluetoothAdapter.BLUETOOTH_SERVICE, bluetooth); bluetooth.initAfterRegistration(); bluetoothA2dp = new BluetoothA2dpService(context, bluetooth); ServiceManager.addService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE, bluetoothA2dp); int bluetoothOn = Settings.Secure.getInt(mContentResolver, Settings.Secure.BLUETOOTH_ON, 0); if (bluetoothOn > 0) { bluetooth.enable(); } } } catch (RuntimeException e) { Slog.e("System", "Failure starting core service", e); } DevicePolicyManagerService devicePolicy = null; StatusBarManagerService statusBar = null; InputMethodManagerService imm = null; AppWidgetService appWidget = null; NotificationManagerService notification = null; WallpaperManagerService wallpaper = null; LocationManagerService location = null; if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { try { Slog.i(TAG, "Device Policy"); devicePolicy = new DevicePolicyManagerService(context); ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy); } catch (Throwable e) { Slog.e(TAG, "Failure starting DevicePolicyService", e); } try { Slog.i(TAG, "Status Bar"); statusBar = new StatusBarManagerService(context); ServiceManager.addService(Context.STATUS_BAR_SERVICE, statusBar); } catch (Throwable e) { Slog.e(TAG, "Failure starting StatusBarManagerService", e); } try { Slog.i(TAG, "Clipboard Service"); ServiceManager.addService(Context.CLIPBOARD_SERVICE, new ClipboardService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Clipboard Service", e); } try { Slog.i(TAG, "Input Method Service"); imm = new InputMethodManagerService(context, statusBar); ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm); } catch (Throwable e) { Slog.e(TAG, "Failure starting Input Manager Service", e); } try { Slog.i(TAG, "NetStat Service"); ServiceManager.addService("netstat", new NetStatService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting NetStat Service", e); } try { Slog.i(TAG, "NetworkManagement Service"); ServiceManager.addService( Context.NETWORKMANAGEMENT_SERVICE, NetworkManagementService.create(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting NetworkManagement Service", e); } try { Slog.i(TAG, "Connectivity Service"); connectivity = ConnectivityService.getInstance(context); ServiceManager.addService(Context.CONNECTIVITY_SERVICE, connectivity); } catch (Throwable e) { Slog.e(TAG, "Failure starting Connectivity Service", e); } 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); } try { Slog.i(TAG, "Accessibility Manager"); ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, new AccessibilityManagerService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Accessibility Manager", e); } try { /* * NotificationManagerService is dependant on MountService, * (for media / usb notifications) so we must start MountService first. */ Slog.i(TAG, "Mount Service"); ServiceManager.addService("mount", new MountService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Mount Service", e); } try { Slog.i(TAG, "Notification Manager"); notification = new NotificationManagerService(context, statusBar, lights); ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification); } catch (Throwable e) { Slog.e(TAG, "Failure starting Notification Manager", e); } try { Slog.i(TAG, "Device Storage Monitor"); ServiceManager.addService(DeviceStorageMonitorService.SERVICE, new DeviceStorageMonitorService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting DeviceStorageMonitor service", e); } try { Slog.i(TAG, "Location Manager"); location = new LocationManagerService(context); ServiceManager.addService(Context.LOCATION_SERVICE, location); } catch (Throwable e) { Slog.e(TAG, "Failure starting Location Manager", e); } try { Slog.i(TAG, "Search Service"); ServiceManager.addService(Context.SEARCH_SERVICE, new SearchManagerService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Search Service", e); } if (INCLUDE_DEMO) { Slog.i(TAG, "Installing demo data..."); (new DemoThread(context)).start(); } try { Slog.i(TAG, "DropBox Service"); ServiceManager.addService(Context.DROPBOX_SERVICE, new DropBoxManagerService(context, new File("/data/system/dropbox"))); } catch (Throwable e) { Slog.e(TAG, "Failure starting DropBoxManagerService", e); } try { Slog.i(TAG, "Wallpaper Service"); wallpaper = new WallpaperManagerService(context); ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper); } catch (Throwable e) { Slog.e(TAG, "Failure starting Wallpaper Service", e); } try { Slog.i(TAG, "Audio Service"); ServiceManager.addService(Context.AUDIO_SERVICE, new AudioService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Audio Service", e); } try { Slog.i(TAG, "Headset Observer"); // Listen for wired headset changes headset = new HeadsetObserver(context); } catch (Throwable e) { Slog.e(TAG, "Failure starting HeadsetObserver", e); } try { Slog.i(TAG, "Dock Observer"); // Listen for dock station changes dock = new DockObserver(context, power); } catch (Throwable e) { Slog.e(TAG, "Failure starting DockObserver", e); } try { Slog.i(TAG, "USB Service"); // Listen for USB changes usb = new UsbService(context); ServiceManager.addService(Context.USB_SERVICE, usb); } catch (Throwable e) { Slog.e(TAG, "Failure starting UsbService", e); } try { Slog.i(TAG, "UI Mode Manager Service"); // Listen for UI mode changes uiMode = new UiModeManagerService(context); } catch (Throwable e) { Slog.e(TAG, "Failure starting UiModeManagerService", e); } try { Slog.i(TAG, "Backup Service"); ServiceManager.addService(Context.BACKUP_SERVICE, new BackupManagerService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting Backup Service", e); } try { Slog.i(TAG, "AppWidget Service"); appWidget = new AppWidgetService(context); ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget); } catch (Throwable e) { Slog.e(TAG, "Failure starting AppWidget Service", e); } try { Slog.i(TAG, "Recognition Service"); recognition = new RecognitionManagerService(context); } catch (Throwable e) { Slog.e(TAG, "Failure starting Recognition Service", e); } try { Slog.i(TAG, "DiskStats Service"); ServiceManager.addService("diskstats", new DiskStatsService(context)); } catch (Throwable e) { Slog.e(TAG, "Failure starting DiskStats Service", e); } } // 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()); // Before things start rolling, be sure we have decided whether // we are in safe mode. final boolean safeMode = wm.detectSafeMode(); if (safeMode) { try { ActivityManagerNative.getDefault().enterSafeMode(); // Post the safe mode state in the Zygote class Zygote.systemInSafeMode = true; // Disable the JIT for the system_server process VMRuntime.getRuntime().disableJitCompilation(); } catch (RemoteException e) { } } else { // Enable the JIT for the system_server process VMRuntime.getRuntime().startJitCompilation(); } // It is now time to start up the app processes... if (devicePolicy != null) { devicePolicy.systemReady(); } if (notification != null) { notification.systemReady(); } if (statusBar != null) { statusBar.systemReady(); } wm.systemReady(); power.systemReady(); try { pm.systemReady(); } catch (RemoteException e) { } // These are needed to propagate to the runnable below. final StatusBarManagerService statusBarF = statusBar; final BatteryService batteryF = battery; final ConnectivityService connectivityF = connectivity; final DockObserver dockF = dock; final UsbService usbF = usb; final ThrottleService throttleF = throttle; final UiModeManagerService uiModeF = uiMode; final AppWidgetService appWidgetF = appWidget; final WallpaperManagerService wallpaperF = wallpaper; final InputMethodManagerService immF = imm; final RecognitionManagerService recognitionF = recognition; final LocationManagerService locationF = location; // 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() { Slog.i(TAG, "Making services ready"); if (statusBarF != null) statusBarF.systemReady2(); if (batteryF != null) batteryF.systemReady(); if (connectivityF != null) connectivityF.systemReady(); if (dockF != null) dockF.systemReady(); if (usbF != null) usbF.systemReady(); if (uiModeF != null) uiModeF.systemReady(); if (recognitionF != null) recognitionF.systemReady(); Watchdog.getInstance().start(); // It is now okay to let the various system services start their // third party code... if (appWidgetF != null) appWidgetF.systemReady(safeMode); if (wallpaperF != null) wallpaperF.systemReady(); if (immF != null) immF.systemReady(); if (locationF != null) locationF.systemReady(); if (throttleF != null) throttleF.systemReady(); } }); // For debug builds, log event loop stalls to dropbox for analysis. if (StrictMode.conditionallyEnableDebugLogging()) { Slog.i(TAG, "Enabled StrictMode for system server main thread."); } Looper.loop(); Slog.d(TAG, "System ServerThread is exiting!"); }
这里启动的没一个进程都作为一个Dalvik线程而存在于SystemServer进程里面。
发表评论
-
Android Power Manager分析[转载]
2011-07-20 03:06 2575一、Android的电源管理部分文件路径如下: ... -
How BatteryService works in android.
2011-07-14 05:04 2039BatteryService monitors the cha ... -
Android 编译C模块
2011-06-14 03:57 3402Android 编译环境 本身比较复杂,且不像普通的编 ... -
Activity的启动流程【zhuanzai】
2011-06-12 11:08 2903Activity启动分为很多种情况,这里说的是打开新的应用程序 ... -
Android源码目录结构
2011-05-05 03:24 1607GNU的内核在体积和运行效率上不适合移动设备,系统核心组件都是 ... -
编译Android源码和Linux内核源码时候遇到的一些错误
2011-05-02 02:52 109961. Ubuntu下执行命令 "adb reb ... -
Building Android and Linux Kernel for Nexus One[转载]
2011-05-01 11:44 2289原文地址: http://randomizedso ...
相关推荐
在manifest文件中添加`android:sharedUserId="android.uid.system"`属性到`<application>`标签,这将使应用与系统共享用户ID。 2. **添加权限声明**:在同一个`<application>`标签下,声明`android.permission....
Android启动,第三阶段,SystemServer创建。 紧接上两篇《 Android启动-init介绍》和《Android启动-Zygote启动介绍》Linux内核启动之后,执行第一个进程 Init-->init创建Zygote-->fork出SystemServer。 这里...
2. **获取二进制文件**:`android_server_nonpie`通常位于系统镜像的`system_server`进程中,需要通过ADB(Android Debug Bridge)将其导出到本地进行分析。 3. **加载二进制**:在IDA中打开`android_server_nonpie...
- 内核启动后,Android System Server进程开始运行,这是Android系统的心脏,负责管理所有其他服务和进程。 - 在System Server启动的同时,会加载各种系统服务,包括Display服务,此时开机动画开始播放。 2. **...
- Android System Server是Android系统的主进程,负责用户界面、权限管理等。 - Zygote进程是System Server的父进程,它是所有Java应用的起点,预先加载Dalvik或ART运行时环境。 7. **设备初始化和服务启动**: ...
4. Android System Server:在EMUELEC中,init会启动Android的System Server,这是Android框架的核心服务进程。 5. 用户界面启动:Android System Server接着启动SurfaceFlinger服务,构建图形界面,并启动关键的...
6. **系统启动流程**: 在Android启动过程中,system_server进程是核心组件,它负责初始化系统服务和执行各种设置。这个过程涉及到大量的C++接口调用,如Zygote进程的创建,用于孵化新的应用程序进程。 7. **Android...
在Android源码中,`com.android.server.SystemSettingsService`是SystemSetting的主要实现类,它继承自`android.app.settings.ISystemSettingsService$Stub`,实现了远程服务接口,使得其他进程可以通过Binder机制...
Android下通过root实现对system_server中binder的ioctl调用拦截
标题中的"frida-server-16.0.13-android-arm64"指的是Frida Server的一个特定版本,这是用于Android设备的动态代码插桩工具。Frida是由 Ole André Vadla Rønning 开发的一款强大的开源软件,它允许开发者在运行时...
在Android平台上连接并操作SQL Server 2008是一项技术性较强的任务,涉及到多个关键知识点。首先,我们需要了解Android系统如何与远程服务器交互,以及如何处理SQL Server的数据库操作。以下是一些核心概念和步骤: ...
在Android系统中,"Android Native"指的是使用C/C++等原生代码开发的组件,而"Android Server"则指的是在Android设备上运行的服务程序。"android-native-server.rar"这个压缩包提供了一个实例,展示了如何在Android ...
Slog.i(TAG, "Entered the Android system server!"); Thread thr = new ServerThread(); thr.setName("android.server.ServerThread"); thr.start(); } class ServerThread extends Thread { private ...
接下来我们就要实现我们的终极目标了:system_server(JAVA端)与服务端相互通信; 预处理 首先先解释下一个“玄学”的情况:在前两章的操作完成后,我们不需要添加任何JAVA类,即可直接使用; 究其原因,是因为在我们...
ADB(Android Debug Bridge)...总之,对`android / platform / system / core`目录下的ADB源码进行深入研究,将有助于开发者提升对Android系统的整体理解和定制能力,对于从事Android开发的人员来说是一项宝贵的资源。
本文档对 Android 11.0 平台开机启动流程进行了详细的介绍,涵盖了 Android 架构图、系统启动流程、init 启动流程、Zygote 启动流程、System Server 启动流程等关键部分。 Android 架构图 Android 系统架构图主要...
system_server_1471堆栈
frida-server-14.0.8-android-arm64 ,frida 14.0.8 对应的安卓server内容,下载之后push到手机即可开始使用
7. **System Server**:这是Android系统的另一核心组件,负责处理系统级别的服务、窗口管理和应用管理等。 8. **HAL(Hardware Abstraction Layer)**:硬件抽象层提供了对硬件设备的操作接口,使得上层软件可以...
frida-server-14.2.18-android-arm64