static void android_server_BatteryService_update(JNIEnv* env, jobject obj) { setBooleanField(env, obj, gPaths.acOnlinePath, gFieldIds.mAcOnline); setBooleanField(env, obj, gPaths.usbOnlinePath, gFieldIds.mUsbOnline); setBooleanField(env, obj, gPaths.wirelessOnlinePath, gFieldIds.mWirelessOnline); setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent); setIntFieldMax(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel, 100); setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage); setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature); const int SIZE = 128; char buf[SIZE]; if (readFromFile(gPaths.batteryStatusPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf)); else env->SetIntField(obj, gFieldIds.mBatteryStatus, gConstants.statusUnknown); if (readFromFile(gPaths.batteryHealthPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf)); if (readFromFile(gPaths.batteryTechnologyPath, buf, SIZE) > 0) env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf)); }
static void android_server_BatteryService_update(JNIEnv* env, jobject obj) { setBooleanField(env, obj, gPaths.batteryPresentPath, gFieldIds.mBatteryPresent); setIntFieldMax(env, obj, gPaths.batteryCapacityPath, gFieldIds.mBatteryLevel, 100); setVoltageField(env, obj, gPaths.batteryVoltagePath, gFieldIds.mBatteryVoltage); setIntField(env, obj, gPaths.batteryTemperaturePath, gFieldIds.mBatteryTemperature); const int SIZE = 128; char buf[SIZE]; if (readFromFile(gPaths.batteryStatusPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryStatus, getBatteryStatus(buf)); else env->SetIntField(obj, gFieldIds.mBatteryStatus, gConstants.statusUnknown); if (readFromFile(gPaths.batteryHealthPath, buf, SIZE) > 0) env->SetIntField(obj, gFieldIds.mBatteryHealth, getBatteryHealth(buf)); if (readFromFile(gPaths.batteryTechnologyPath, buf, SIZE) > 0) env->SetObjectField(obj, gFieldIds.mBatteryTechnology, env->NewStringUTF(buf)); unsigned int i; String8 path; jboolean acOnline = false; jboolean usbOnline = false; jboolean wirelessOnline = false; for (i = 0; i < gChargerNames.size(); i++) { path.clear(); path.appendFormat("%s/%s/online", POWER_SUPPLY_PATH, gChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_PATH, gChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: acOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: usbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: wirelessOnline = true; break; default: ALOGW("%s: Unknown power supply type", gChargerNames[i].string()); } } } } env->SetBooleanField(obj, gFieldIds.mAcOnline, acOnline); env->SetBooleanField(obj, gFieldIds.mUsbOnline, usbOnline); env->SetBooleanField(obj, gFieldIds.mWirelessOnline, wirelessOnline); }