欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 开机充电图标和充电动画效果

程序员文章站 2022-09-02 07:57:30
首先驱动需要先获取到2个power supply kernel\msm-3.18\drivers\usb\phy\phy-msm-usb.c motg->usb_ps...

首先驱动需要先获取到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 battery
current 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 开机充电图标和充电动画效果,希望对大家有所帮助