• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

修訂e0cf1cfb2ff03a995e9be86007f87326e71fcc88 (tree)
時間2011-08-05 17:26:22
作者Yi Sun <beyounn@gmai...>
CommiterChih-Wei Huang

Log Message

Add battery status support for PC and VMs

Change Summary

差異

Binary files /dev/null and b/core/res/res/drawable/gpm_ac_adapter.png differ
--- a/services/java/com/android/server/BatteryService.java
+++ b/services/java/com/android/server/BatteryService.java
@@ -445,7 +445,9 @@ class BatteryService extends Binder {
445445 mBatteryStatus == BatteryManager.BATTERY_STATUS_FULL) {
446446 return com.android.internal.R.drawable.stat_sys_battery;
447447 } else {
448- return com.android.internal.R.drawable.stat_sys_battery_unknown;
448+ return mBatteryPresent ?
449+ com.android.internal.R.drawable.stat_sys_battery_unknown :
450+ com.android.internal.R.drawable.gpm_ac_adapter;
449451 }
450452 }
451453
--- a/services/jni/com_android_server_BatteryService.cpp
+++ b/services/jni/com_android_server_BatteryService.cpp
@@ -77,6 +77,8 @@ struct PowerSupplyPaths {
7777 char* batteryHealthPath;
7878 char* batteryPresentPath;
7979 char* batteryCapacityPath;
80+ char* batteryChargeNowPath;
81+ char* batteryChargeFullPath;
8082 char* batteryVoltagePath;
8183 char* batteryTemperaturePath;
8284 char* batteryTechnologyPath;
@@ -194,14 +196,44 @@ static void setVoltageField(JNIEnv* env, jobject obj, const char* path, jfieldID
194196 env->SetIntField(obj, fieldID, value);
195197 }
196198
199+static void setChargeLevel(JNIEnv* env, jobject obj, jfieldID fieldID) {
200+ float now,full;
201+ int value = 0;
202+ char buf[128];
203+
204+ if (readFromFile(gPaths.batteryChargeNowPath, buf, 128) > 0 ) {
205+ now = atoi(buf);
206+ if (readFromFile(gPaths.batteryChargeFullPath, buf, 128) > 0 ) {
207+ full = atoi(buf);
208+ value = (int)((now/full) * 100);
209+ } else {
210+ value = now;
211+ }
212+ }
213+ env->SetIntField(obj, fieldID, value);
214+}
197215
198216 static void android_server_BatteryService_update(JNIEnv* env, jobject obj)
199217 {
200218 setBooleanField(env, obj, gPaths.acOnlinePath, gFieldIds.mAcOnline);
201219 setBooleanField(env, obj, gPaths.usbOnlinePath, gFieldIds.mUsbOnline);
202220 setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent);
221+ if ( !gPaths.acOnlinePath && !gPaths.usbOnlinePath && !gPaths.batteryPresentPath) {
222+ /* most likely, we have a PC here */
223+ env->SetBooleanField(obj, gFieldIds.mAcOnline, true);
224+ }
203225
204- setIntField(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel);
226+ if (gPaths.batteryPresentPath) {
227+ if (gPaths.batteryCapacityPath) {
228+ setIntField(env, obj, gPaths.batteryCapacityPath,
229+ gFieldIds.mBatteryLevel);
230+ } else {
231+ setChargeLevel(env,obj, gFieldIds.mBatteryLevel);
232+ }
233+ } else {
234+ /*This is a PC or VM, faking the level to full, we are on AC anyway */
235+ env->SetIntField(obj, gFieldIds.mBatteryLevel, 100);
236+ }
205237 setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage);
206238 setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature);
207239
@@ -226,6 +258,7 @@ static JNINativeMethod sMethods[] = {
226258 {"native_update", "()V", (void*)android_server_BatteryService_update},
227259 };
228260
261+
229262 int register_android_server_BatteryService(JNIEnv* env)
230263 {
231264 char path[PATH_MAX];
@@ -273,8 +306,31 @@ int register_android_server_BatteryService(JNIEnv* env)
273306 if (access(path, R_OK) == 0)
274307 gPaths.batteryPresentPath = strdup(path);
275308 snprintf(path, sizeof(path), "%s/%s/capacity", POWER_SUPPLY_PATH, name);
276- if (access(path, R_OK) == 0)
309+ if (access(path, R_OK) == 0) {
277310 gPaths.batteryCapacityPath = strdup(path);
311+ } else {
312+ snprintf(path, sizeof(path), "%s/%s/charge_now",
313+ POWER_SUPPLY_PATH, name);
314+ if (access(path, R_OK) == 0) {
315+ gPaths.batteryChargeNowPath = strdup(path);
316+ snprintf(path, sizeof(path), "%s/%s/charge_full",
317+ POWER_SUPPLY_PATH, name);
318+ if (access(path, R_OK) == 0) {
319+ gPaths.batteryChargeFullPath = strdup(path);
320+ }
321+ } else {
322+ snprintf(path, sizeof(path), "%s/%s/energy_now",
323+ POWER_SUPPLY_PATH, name);
324+ if (access(path, R_OK) == 0) {
325+ gPaths.batteryChargeNowPath = strdup(path);
326+ snprintf(path, sizeof(path), "%s/%s/energy_full",
327+ POWER_SUPPLY_PATH, name);
328+ if (access(path, R_OK) == 0) {
329+ gPaths.batteryChargeFullPath = strdup(path);
330+ }
331+ }
332+ }
333+ }
278334
279335 snprintf(path, sizeof(path), "%s/%s/voltage_now", POWER_SUPPLY_PATH, name);
280336 if (access(path, R_OK) == 0) {
@@ -314,7 +370,8 @@ int register_android_server_BatteryService(JNIEnv* env)
314370 LOGE("batteryHealthPath not found");
315371 if (!gPaths.batteryPresentPath)
316372 LOGE("batteryPresentPath not found");
317- if (!gPaths.batteryCapacityPath)
373+ if (!gPaths.batteryCapacityPath && (!gPaths.batteryChargeNowPath ||
374+ !gPaths.batteryChargeFullPath))
318375 LOGE("batteryCapacityPath not found");
319376 if (!gPaths.batteryVoltagePath)
320377 LOGE("batteryVoltagePath not found");