您好,登錄后才能下訂單哦!
小編給大家分享一下如何使用Android實現開機充電圖標和充電動畫效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
首先驅動需要先獲取到2個power supply
kernel\msm-3.18\drivers\usb\phy\phy-msm-usb.c
motg->usb_psy.name = "usb";motg->usb_psy.type = POWER_SUPPLY_TYPE_USB;motg->usb_psy.supplied_to = otg_pm_power_supplied_to;motg->usb_psy.num_supplicants = ARRAY_SIZE(otg_pm_power_supplied_to);motg->usb_psy.properties = otg_pm_power_props_usb;motg->usb_psy.num_properties = ARRAY_SIZE(otg_pm_power_props_usb);motg->usb_psy.get_property = otg_power_get_property_usb;motg->usb_psy.set_property = otg_power_set_property_usb;motg->usb_psy.property_is_writeable = otg_power_property_is_writeable_usb;if (!msm_otg_register_power_supply(pdev, motg)) psy = &motg->usb_psy;
kernel\msm-3.18\drivers\power\bq2570x\bq2570x_charger.c
usb_psy = power_supply_get_by_name("usb");static int bq2570x_psy_register(struct bq2570x *bq){ int ret; bq->batt_psy.name = "dc_o2"; bq->batt_psy.type = POWER_SUPPLY_TYPE_BATTERY; bq->batt_psy.properties = bq2570x_charger_props; bq->batt_psy.num_properties = ARRAY_SIZE(bq2570x_charger_props); bq->batt_psy.get_property = bq2570x_charger_get_property; bq->batt_psy.set_property = bq2570x_charger_set_property; bq->batt_psy.external_power_changed = bq2570x_external_power_changed; bq->batt_psy.property_is_writeable = bq2570x_charger_is_writeable; ret = power_supply_register(bq->dev, &bq->batt_psy); if (ret < 0) { pr_err("failed to register batt_psy:%d\n", ret); return ret; } return 0;}
充電的閃電圖標和充電動畫啟動邏輯
閃電圖標啟動邏輯:POWER_SUPPLY_TYPE_USB的power supply上報USB類型(CDP,DCP,USB)
power_supply_set_supply_type(bq->usb_psy, POWER_SUPPLY_TYPE_USB);ret = power_supply_set_online(bq->usb_psy, true);power_supply_changed(bq->usb_psy);
充電動畫的啟動邏輯:POWER_SUPPLY_TYPE_BATTERY的power supply上報充電狀態
(CHARGE_STATE_NOT_CHARGING,CHARGE_STATE_FASTCHARGE)bq->charge_state = CHARGE_STATE_FASTCHARGE;power_supply_changed(&bq->batt_psy);
利用dumpsys分析當前battery 狀態
V2_PRO:/ # dumpsys batteryCurrent Battery Service state: AC powered: false USB powered: true Wireless powered: false Max charging current: 0 Max charging voltage: 0 Charge counter: 0 status: 2 health: 2 present: true level: 46 scale: 100 voltage: 7 temperature: 270 technology: Li-ion
如上主要關注2個字段:
USB powered : true
那么閃電圖標應該會出現
status: 2
那么充電動畫應該啟動了
同時我們還可以通過shell指令的方式啟動充電圖標和充電動畫
dumpsys battery set usb 1
閃電圖標應該會出現
dumpsys battery set status 2
充電動畫應該啟動了
dumpsys battery set usb 0
閃電圖標消失
dumpsys battery set status 4
充電動畫消失
以上是“如何使用Android實現開機充電圖標和充電動畫效果”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。