DC充电器:只有5V和GND两根线,也就是说接入DC,USB检测的D+和D-是悬空的。
1. 接入DC充电器显示充电图标,但没有闪电标识问题
/frameworks/base/services/core/java/com/android/server/BatteryService.java下sendIntentLocked()函数//intent.putExtra(BatteryManager.EXTRA_PLUGGED,mPlugType);//kandi mark//kandi add if( mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_CHARGING || mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_FULL ){ intent.putExtra(BatteryManager.EXTRA_PLUGGED, mPlugType |BatteryManager.BATTERY_PLUGGED_AC |BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS); }else { intent.putExtra(BatteryManager.EXTRA_PLUGGED, BATTERY_PLUGGED_NONE); }
此函数是发ACTION_BATTERY_CHANGED广播的。上面解决版本是我们核心板厂家给出来的,但存在几个问题:
(1) 不管是AC、USB、WIRELESS还是DC,设备Battery status显示的都是Charging
因为mPlugType或AC或USB或WIRELESS,以至于APP层判断为unknown类型,见\packages\apps\Settings\src\com\android\setting\Utils.java的onReceive()相关代码
public static String getBatteryStatus(Resources res, IntentbatteryChangedIntent) { final Intent intent = batteryChangedIntent; int plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN); String statusString; if (status == BatteryManager.BATTERY_STATUS_CHARGING) { int resId; if (plugType == BatteryManager.BATTERY_PLUGGED_AC) { resId =R.string.battery_info_status_charging_ac; } else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) { resId =R.string.battery_info_status_charging_usb; } else if (plugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) { resId =R.string.battery_info_status_charging_wireless; } else { resId =R.string.battery_info_status_charging;//Charging } statusString = res.getString(resId); } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) { statusString = res.getString(R.string.battery_info_status_discharging); } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) { statusString =res.getString(R.string.battery_info_status_not_charging); } else if (status == BatteryManager.BATTERY_STATUS_FULL) { statusString = res.getString(R.string.battery_info_status_full); } else { statusString = res.getString(R.string.battery_info_status_unknown); } return statusString; }
(2) 充满的情况下,还显示闪电标识,见if里面的条件。
2. DC无法充电问题
虽然显示充电,但是实际不能充电,厂家给出的解决方案是在kernel\drivers\power\qpnp-linear-charger.c下的
qpnp_batt_external_power_changed函数增加下面的代码
if (qpnp_lbc_is_usb_chg_plugged_in(chip)) { chip->usb_psy->get_property(chip->usb_psy, POWER_SUPPLY_PROP_CURRENT_MAX,&ret); current_ma= ret.intval / 1000; pr_debug("simcomcurent ma =%d \n",current_ma); //kandiadd start chip->usb_psy->get_property(chip->usb_psy, POWER_SUPPLY_PROP_TYPE,&ret); pr_debug("simcomusb type =%d \n",ret.intval); if(USB_SDP_CHARGER== ret.intval ){ // already checked asusb current_ma=500; }elseif (USB_DCP_CHARGER == ret.intval || USB_CDP_CHARGER == ret.intval){ // checked as AC current_ma=1500; }else{ current_ma=1500; //charging and can't be reginazed, type as DC, } //kandiadd end
3. 休眠状态接入DC无法唤醒系统问题
\kernel\drivers\usb\phy\ phy-msm-usb.c把floated_charger_enable赋值为1就可以解决此问题,也就是:
static bool floated_charger_enable =1;
相关的代码见msm_chg_detect_work()的USB_CHG_STATE_DCD_DONE这个case下的:
if (line_state) /* DP > VLGC or/and DM> VLGC */ motg->chg_type= USB_PROPRIETARY_CHARGER; elseif (!dcd && floated_charger_enable) motg->chg_type= USB_FLOATED_CHARGER; else motg->chg_type= USB_SDP_CHARGER; motg->chg_state= USB_CHG_STATE_DETECTED; delay= 0;
使能floated charger,对应的chg_type为USB_FLOATED_CHARGER,如果是此类型,通过msm_otg_notify_chg_type()重新映射为POWER_SUPPLY_TYPE_USB_DCP,/* Dedicated Charging Port */,然后再发给用户层。
解决了此问题后,上面第1和第2部分代码都不需要增加也都正常。