diff options
-rw-r--r-- | services/java/com/android/server/BatteryService.java | 3 | ||||
-rw-r--r-- | services/jni/com_android_server_BatteryService.cpp | 127 |
2 files changed, 70 insertions, 60 deletions
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index ab9ae69b9945..84f2a95add4e 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -324,6 +324,9 @@ class BatteryService extends Binder { && mBatteryLevel <= mLowBatteryWarningLevel && (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel); + if (mBatteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) + mBatteryLevel = BATTERY_SCALE; + sendIntent(); // Separate broadcast is sent for power connected / not connected diff --git a/services/jni/com_android_server_BatteryService.cpp b/services/jni/com_android_server_BatteryService.cpp index 2ceb5356e624..166d6b489540 100644 --- a/services/jni/com_android_server_BatteryService.cpp +++ b/services/jni/com_android_server_BatteryService.cpp @@ -232,76 +232,83 @@ int register_android_server_BatteryService(JNIEnv* env) DIR* dir = opendir(POWER_SUPPLY_PATH); if (dir == NULL) { - LOGE("Could not open %s\n", POWER_SUPPLY_PATH); - return -1; - } - while ((entry = readdir(dir))) { - const char* name = entry->d_name; - - // ignore "." and ".." - if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) { - continue; - } + // This indicates the kernel is built with + // CONFIG_POWER_SUPPLY disabled. + // This should be treated the same as a kernel with + // CONFIG_POWER_SUPPLY enabled, but not finding a + // power supply -- simply make sure all paths in + // gPaths are NULL + // jniRegisterNativeMethods etc. still should be run. + memset(&gPaths, 0, sizeof(gPaths)); + } else { + while ((entry = readdir(dir))) { + const char* name = entry->d_name; - char buf[20]; - // Look for "type" file in each subdirectory - snprintf(path, sizeof(path), "%s/%s/type", POWER_SUPPLY_PATH, name); - int length = readFromFile(path, buf, sizeof(buf)); - if (length > 0) { - if (buf[length - 1] == '\n') - buf[length - 1] = 0; - - if (strcmp(buf, "Mains") == 0) { - snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.acOnlinePath = strdup(path); + // ignore "." and ".." + if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) { + continue; } - else if (strcmp(buf, "USB") == 0) { - snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.usbOnlinePath = strdup(path); - } - else if (strcmp(buf, "Battery") == 0) { - snprintf(path, sizeof(path), "%s/%s/status", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.batteryStatusPath = strdup(path); - snprintf(path, sizeof(path), "%s/%s/health", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.batteryHealthPath = strdup(path); - snprintf(path, sizeof(path), "%s/%s/present", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.batteryPresentPath = strdup(path); - snprintf(path, sizeof(path), "%s/%s/capacity", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.batteryCapacityPath = strdup(path); - - snprintf(path, sizeof(path), "%s/%s/voltage_now", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) { - gPaths.batteryVoltagePath = strdup(path); - // voltage_now is in microvolts, not millivolts - gVoltageDivisor = 1000; - } else { - snprintf(path, sizeof(path), "%s/%s/batt_vol", POWER_SUPPLY_PATH, name); + + char buf[20]; + // Look for "type" file in each subdirectory + snprintf(path, sizeof(path), "%s/%s/type", POWER_SUPPLY_PATH, name); + int length = readFromFile(path, buf, sizeof(buf)); + if (length > 0) { + if (buf[length - 1] == '\n') + buf[length - 1] = 0; + + if (strcmp(buf, "Mains") == 0) { + snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); if (access(path, R_OK) == 0) - gPaths.batteryVoltagePath = strdup(path); + gPaths.acOnlinePath = strdup(path); } - - snprintf(path, sizeof(path), "%s/%s/temp", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) { - gPaths.batteryTemperaturePath = strdup(path); - } else { - snprintf(path, sizeof(path), "%s/%s/batt_temp", POWER_SUPPLY_PATH, name); + else if (strcmp(buf, "USB") == 0) { + snprintf(path, sizeof(path), "%s/%s/online", POWER_SUPPLY_PATH, name); if (access(path, R_OK) == 0) - gPaths.batteryTemperaturePath = strdup(path); + gPaths.usbOnlinePath = strdup(path); } + else if (strcmp(buf, "Battery") == 0) { + snprintf(path, sizeof(path), "%s/%s/status", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryStatusPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/health", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryHealthPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/present", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryPresentPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/capacity", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryCapacityPath = strdup(path); - snprintf(path, sizeof(path), "%s/%s/technology", POWER_SUPPLY_PATH, name); - if (access(path, R_OK) == 0) - gPaths.batteryTechnologyPath = strdup(path); + snprintf(path, sizeof(path), "%s/%s/voltage_now", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) { + gPaths.batteryVoltagePath = strdup(path); + // voltage_now is in microvolts, not millivolts + gVoltageDivisor = 1000; + } else { + snprintf(path, sizeof(path), "%s/%s/batt_vol", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryVoltagePath = strdup(path); + } + + snprintf(path, sizeof(path), "%s/%s/temp", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) { + gPaths.batteryTemperaturePath = strdup(path); + } else { + snprintf(path, sizeof(path), "%s/%s/batt_temp", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryTemperaturePath = strdup(path); + } + + snprintf(path, sizeof(path), "%s/%s/technology", POWER_SUPPLY_PATH, name); + if (access(path, R_OK) == 0) + gPaths.batteryTechnologyPath = strdup(path); + } } } + closedir(dir); } - closedir(dir); if (!gPaths.acOnlinePath) LOGE("acOnlinePath not found"); |