Android電池管理體系 二

2021-08-15 22:08:52 字數 3846 閱讀 9871

在前面的文章中我們提到了android電池模組中的驅動層,該層主要通過充電晶元驅動去讀取電池電量,電池狀態等資訊。在我們在驅動中拿到電池電量資訊的時候是怎麼一步步傳到android層的,在這裡就需要提到health模組。health模組是android4.4以後推出的,主要用於向下讀取電池驅動中的電量資訊,然後向上傳遞給framwork中的

batteryservice.

該篇文章主要就android health模組進行分析(下面關鍵**會有注釋):

health模組的**位置位於/system/core/healthd/,其入口在healthd.cpp中的main函式中,

int main(int argc, char **argv)  else }}

ret = healthd_init(); //主要做初始化的工作

if (ret)

healthd_mainloop();

klog_error("main loop terminated, exiting\n");

return 3;

}

healthd_mode_ops是乙個充電狀態的結構體,

正常開機情況下會 將android_ops結構體賦值給healthd_mode_ops ,如果在關機情況下會將 charget_ops結構體賦值給healthd_mode_opos,就是關機充電的使用。

然後在healthd_init中,主要做一些初始化工作:

static int healthd_init() 

healthd_board_init(&healthd_config);

healthd_mode_ops->init(&healthd_config);

wakealarm_init();

uevent_init();

gbatterymonitor = new batterymonitor();

gbatterymonitor->init(&healthd_config);

return 0;

}

在上面的**中首先建立了乙個epoll,主要用於將檔案指標掛在工作佇列中,用於輪詢檢視驅動層是否發來資訊,然後呼叫uevent_init()對uevent進行註冊,應為從上篇文章我們明白,電池驅動是通過uevent與health進行通訊的,uevent通訊本質上就是socket通訊,這裡不詳細說了。

然後呼叫完healthd_init(),接下來比較重要的就是執行healthd_mainloop()了

static void healthd_mainloop(void) 

for (int n = 0; n < nevents; ++n)

if (!nevents)

periodic_chores();

healthd_mode_ops->heartbeat();

}return;

}

可以看到,在這裡直接開啟了乙個無線迴圈,監聽是否有uevent事件到來,如果在for迴圈中檢測到uevent事件到來的時候,會直接呼叫 uevent_event函式

static void uevent_event(uint32_t /*epevents*/) 

/* advance to after the next \0 */

while (*cp++);}

}

在uevent_event函式中,會判斷ssubsystem是否等於power_supply_subsystem,如果是的話,說明是電池驅動傳過來的資訊,會執行 healthd_battery_update()函式

void healthd_battery_update(void)

在該函式中會直接呼叫batterymonitor中的update()函式,對電池的各個屬性進行更新,並在最後呼叫在前面註冊的監聽進行上報

bool batterymonitor::update(void) 

const int size = 128;

char buf[size];

string8 btech;

if (readfromfile(mhealthdconfig->batterystatuspath, buf, size) > 0)

props.batterystatus = getbatterystatus(buf);

if (readfromfile(mhealthdconfig->batteryhealthpath, buf, size) > 0)

props.batteryhealth = getbatteryhealth(buf);

if (readfromfile(mhealthdconfig->batterytechnologypath, buf, size) > 0)

props.batterytechnology = string8(buf);

unsigned int i;

for (i = 0; i < mchargernames.size(); i++)

path.clear();

mchargernames[i].string());

if (access(path.string(), r_ok) == 0) }}

}}

//讀取電池節點資訊

logthis = !healthd_board_battery_update(&props);

if (logthis)

} else

size_t len = strlen(dmesgline);

//儲存當前電池狀態

snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s",

props.chargeraconline ? "a" : "",

props.chargerusbonline ? "u" : "",

props.chargerwirelessonline ? "w" : "");

log_time realtime(clock_realtime);

time_t t = realtime.tv_sec;

struct tm *tmp = gmtime(&t);

if (tmp) }}

klog_warning(log_tag, "%s\n", dmesgline);

}healthd_mode_ops->battery_update(&props); //向上更新電池狀態

return props.chargeraconline | props.chargerusbonline |

props.chargerwirelessonline; //當前為電源充電或者usb充電或者無線充電

}

在該函式中呼叫 healthd_mode_ops->battery_update(&props) 進行,其中battery_update(&props)為在health.cpp中初始化的結構體,最後返回當前的充電狀態。

battery_update()呼叫的函式如下,呼叫註冊的監聽進行上報:

void healthd_mode_android_battery_update(

struct android::batteryproperties *props)

安全管理體系

安全管理體系是指基於安全管理的一整套體系,體系包括硬體軟體方面。意義基於安全管理的一整套體系 分類軟體硬體 目的實現安全管理運營 目錄1基本定義 2關鍵要素 3最佳實踐 摺疊編輯本段基本定義 軟體方面涉及到思想,制度,教育,組織,管理 硬體包括安全投入,裝置,裝置技術,執行維護等等。構建安全管理體系...

ISO檔案管理體系

質量體系檔案包括 一階檔案 質量手冊 二階檔案 程式檔案 檔案控制程式 記錄控制程式 不合格品控制程式 內部審核控制程式 糾正錯控制程式 預防措施控制程式 三階檔案 作業指導書 規範 外來檔案等 四階檔案 表單 記錄等。iso9000有幾個主要的特性,概括起來就是 1個精髓和1個中心 2個基本點 3...

比較論之 好的管理體系與壞的管理體系

好的管理體系,會把矛盾置於人與體系之間,壞的管理體系則會把矛盾置於人與人之間。這裡牽涉到管理體系的寬容程度。是不簡單一句話。如果想把矛盾置於人與體系之間,就好比法制的社會,與人治社會之對比。對於公司來說,中國的大部分公司還是人治的。從集團論角度,人治公司,只能有乙個集團,只能有乙個強權。這樣的體系,...