偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Android系統(tǒng)的心臟,SystemServer進程及各系統(tǒng)服務(wù)之間的關(guān)系

移動開發(fā) Android
SystemService是framework的一些對應(yīng)功能的服務(wù),供其他模塊和APP來調(diào)用。這些服務(wù)通常與特定的功能或模塊相關(guān),例如BatteryService(用于獲取電池屬性、充電狀態(tài)、百分比等)、PowerManagerService(控制休眠、喚醒等)以及TvInputManagerService(用于創(chuàng)建和釋放會話等)。

SystemServer

SystemServer是Android系統(tǒng)中的一個重要進程,是zygote fork的第一個進程,負責啟動和管理系統(tǒng)中的各種服務(wù)。在Android系統(tǒng)中,SystemServer進程的名稱為"system_server"。

SystemServer進程啟動后,會加載SystemServer類并執(zhí)行其main函數(shù),main函數(shù)是SystemServer的入口點,負責啟動和初始化各種系統(tǒng)服務(wù)。在這個過程中,SystemServer會創(chuàng)建一個Looper和一個Handler,用于在主線程中處理消息和運行任務(wù)。Looper是Android事件循環(huán)的一部分,負責在主線程中接收和分發(fā)消息,Handler則用于發(fā)送和處理消息。

SystemServer創(chuàng)建并初始化的系統(tǒng)服務(wù)包括ActivityManagerService(AMS)、PackageManagerService(PMS)、WindowManagerService(WMS)等。這些服務(wù)在Android系統(tǒng)中扮演著重要的角色,例如AMS負責管理應(yīng)用程序的生命周期和活動狀態(tài),PMS負責管理應(yīng)用程序包的安裝和卸載,WMS則負責管理窗口的創(chuàng)建、顯示和更新等。

在SystemServer的main函數(shù)中,還會啟動其他各種系統(tǒng)服務(wù),這些服務(wù)通過SystemServiceManager進行管理和控制。SystemServer進程會一直運行,處理來自各種系統(tǒng)服務(wù)的消息,確保系統(tǒng)的正常運行和穩(wěn)定性。

ServiceManager

ServiceManager是Android系統(tǒng)中的一個重要守護進程,負責管理系統(tǒng)服務(wù)的注冊、查找和啟動。

  1. 「作用」:

提供服務(wù)注冊和查找:ServiceManager充當了一個中央注冊表的角色,允許應(yīng)用程序和系統(tǒng)組件將自己注冊為服務(wù),并提供一個唯一的服務(wù)名稱。其他應(yīng)用程序可以通過ServiceManager查找并獲取已注冊的服務(wù),從而實現(xiàn)進程間通信。

啟動和管理系統(tǒng)進程:ServiceManager還負責啟動和管理一些重要的系統(tǒng)進程,例如系統(tǒng)服務(wù)(如Telephony服務(wù)、Media服務(wù)等),以及其他一些重要的系統(tǒng)組件。

實現(xiàn)Binder機制:Android系統(tǒng)采用Binder作為進程間通信(IPC)的機制,ServiceManager是Binder通信的關(guān)鍵組件之一。

  1. 「權(quán)限」:

ServiceManager的訪問權(quán)限較高,一般只有系統(tǒng)級應(yīng)用或者具有系統(tǒng)權(quán)限的應(yīng)用程序才能夠使用ServiceManager進行服務(wù)的注冊和查詢。

  1. 「與Binder的關(guān)系」:

ServiceManager是Binder的守護進程,在Android上如果ServiceManager掛掉,所有采用Binder通信的進程服務(wù)都會受到影響。ServiceManager本身也是一個Binder服務(wù),其handle固定為0。應(yīng)用程序相要通過Binder向一個service發(fā)送數(shù)據(jù),必須先通過ServiceManager獲取該service的handle,然后才能通過binder驅(qū)動與service通信。

  1. 「啟動流程」:

在Android系統(tǒng)的啟動過程中,SystemServer進程在啟動時會啟動ServiceManager,并將各種系統(tǒng)服務(wù)注冊到ServiceManager中。

protected final void publishBinderService(String name, IBinder service, boolean allowIsolated) {
    ServiceManager.addService(name, service, allowIsolated);
}

SystemServiceManager

SystemServiceManager是Android系統(tǒng)中用于管理系統(tǒng)服務(wù)的一個類。負責管理所有注冊的系統(tǒng)級別服務(wù),并在需要時啟動和停止它們。例如,當SystemServer進程啟動時,SystemServiceManager會注冊PackageManagerService、WindowManagerService、ActivityManagerService等服務(wù),并在需要時啟動。

@SuppressWarnings("unchecked")
public <T extends SystemService> T startService(Class<T> serviceClass) {
    final String name = serviceClass.getName();
    Slog.i(TAG, "Starting " + name);
 
    // Create the service.
    if (!SystemService.class.isAssignableFrom(serviceClass)) {
        throw new RuntimeException("Failed to create " + name
                + ": service must extend " + SystemService.class.getName());
    }
    final T service;
    try {
        Constructor<T> constructor = serviceClass.getConstructor(Context.class);
        service = constructor.newInstance(mContext);
    } catch (InstantiationException ex) {
        throw new RuntimeException("Failed to create service " + name
                + ": service could not be instantiated", ex);
    } catch (IllegalAccessException ex) {
        throw new RuntimeException("Failed to create service " + name
                + ": service must have a public constructor with a Context argument", ex);
    } catch (NoSuchMethodException ex) {
        throw new RuntimeException("Failed to create service " + name
                + ": service must have a public constructor with a Context argument", ex);
    } catch (InvocationTargetException ex) {
        throw new RuntimeException("Failed to create service " + name
                + ": service constructor threw an exception", ex);
    }

    // Register it.
    mServices.add(service);
 
    // Start it.
    try {
        service.onStart();
    } catch (RuntimeException ex) {
        throw new RuntimeException("Failed to start service " + name
                + ": onStart threw an exception", ex);
    }
    return service;
}

SystemServiceManager通過調(diào)用registerService函數(shù)來注冊系統(tǒng)服務(wù),并可以通過startService、stopService函數(shù)來啟動或停止這些服務(wù)。當系統(tǒng)不再需要某個服務(wù)時,SystemServiceManager也會負責將其停止并卸載。

SystemServiceManager是Android系統(tǒng)內(nèi)部使用的組件,通常不需要開發(fā)者直接與其交互。

SystemService

SystemService是framework的一些對應(yīng)功能的服務(wù),供其他模塊和APP來調(diào)用。這些服務(wù)通常與特定的功能或模塊相關(guān),例如BatteryService(用于獲取電池屬性、充電狀態(tài)、百分比等)、PowerManagerService(控制休眠、喚醒等)以及TvInputManagerService(用于創(chuàng)建和釋放會話等)。

SystemService的使用相對簡單,通過context.getSystemService(@NonNull Class<T> serviceClass)或Object getSystemService(@ServiceName @NonNull String name)方法獲取一個manager對象,然后調(diào)用SystemService里面的方法。

SystemService是Android系統(tǒng)內(nèi)部使用的組件,開發(fā)者在開發(fā)Android應(yīng)用程序時,通常是通過系統(tǒng)提供的API來與系統(tǒng)服務(wù)進行交互的,而不是直接操作SystemService。

val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager

責任編輯:武曉燕 來源: 沐雨花飛蝶
相關(guān)推薦

2021-01-08 08:21:02

Android

2010-05-10 19:03:00

Unix文件

2010-02-07 10:46:50

Android系統(tǒng)

2016-10-28 21:30:00

AndroidJava進程

2018-07-06 14:00:55

Linux進程線程

2018-05-31 10:57:31

Linux系統(tǒng)進程線程

2010-03-04 16:08:21

Android系統(tǒng)平臺

2010-04-12 10:01:43

Windows 7運行速度

2023-11-03 08:22:09

Android系統(tǒng)算法

2011-08-19 09:33:31

windowsxp系統(tǒng)進程系統(tǒng)服務(wù)

2009-06-25 14:46:50

JDKJREJVM

2012-07-03 10:22:42

服務(wù)器虛擬化

2018-07-31 09:38:34

服務(wù)器工作站關(guān)系

2017-09-11 15:35:43

AndroidInput系統(tǒng)框架

2017-08-06 00:05:18

進程通信開發(fā)

2020-04-26 17:18:11

物聯(lián)網(wǎng)醫(yī)療技術(shù)

2018-06-29 09:20:13

2014-09-11 17:02:41

綜合布線

2010-05-06 16:15:04

Unix系統(tǒng)進程

2010-05-11 19:16:03

Unix系統(tǒng)
點贊
收藏

51CTO技術(shù)棧公眾號