編輯:關於Android編程
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部分代碼都不需要增加也都正常。
1:Toolbar跟隨滾動顯示與隱藏 看下Layout代碼"1.0" encoding="utf-8"?&
RatingBar簡單介紹RatingBar是基於SeekBar(拖動條)和ProgressBar(狀態條)的擴展,用星形來顯示等級評定,在使用默認RatingBar時,
我手機的關於手機界面:說明:其中手機型號、Android版本、軟件版本通過系統Build類得到,處理器信息、內核版本通過讀取系統文件得到,基帶版本信息通過反射得到。&nb
先看一看我的代碼運行結果。代碼運行起來初始化狀態: 點擊開始按鈕,唱片機的機械臂勻速接近唱片磁盤,同時唱片磁盤也開始勻速順時針旋轉: &n