BatteryProperties.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2013 The Android Open Source Project
  3. * Copyright (C) 2015 The CyanogenMod Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <stdint.h>
  18. #include <sys/types.h>
  19. #include <batteryservice/BatteryService.h>
  20. #include <binder/Parcel.h>
  21. #include <utils/Errors.h>
  22. #include <utils/String8.h>
  23. #include <utils/String16.h>
  24. namespace android {
  25. /*
  26. * Parcel read/write code must be kept in sync with
  27. * frameworks/base/core/java/android/os/BatteryProperties.java
  28. */
  29. status_t BatteryProperties::readFromParcel(Parcel* p) {
  30. chargerAcOnline = p->readInt32() == 1 ? true : false;
  31. chargerUsbOnline = p->readInt32() == 1 ? true : false;
  32. chargerWirelessOnline = p->readInt32() == 1 ? true : false;
  33. maxChargingCurrent = p->readInt32();
  34. batteryStatus = p->readInt32();
  35. batteryHealth = p->readInt32();
  36. batteryPresent = p->readInt32() == 1 ? true : false;
  37. batteryLevel = p->readInt32();
  38. batteryVoltage = p->readInt32();
  39. batteryTemperature = p->readInt32();
  40. batteryTechnology = String8((p->readString16()).string());
  41. dockBatterySupported = p->readInt32() == 1 ? true : false;
  42. if (dockBatterySupported) {
  43. chargerDockAcOnline = p->readInt32() == 1 ? true : false;
  44. dockBatteryStatus = p->readInt32();
  45. dockBatteryHealth = p->readInt32();
  46. dockBatteryPresent = p->readInt32() == 1 ? true : false;
  47. dockBatteryLevel = p->readInt32();
  48. dockBatteryVoltage = p->readInt32();
  49. dockBatteryTemperature = p->readInt32();
  50. dockBatteryTechnology = String8((p->readString16()).string());
  51. } else {
  52. chargerDockAcOnline = false;
  53. dockBatteryStatus = BATTERY_STATUS_UNKNOWN;
  54. dockBatteryHealth = BATTERY_HEALTH_UNKNOWN;
  55. dockBatteryPresent = false;
  56. dockBatteryLevel = 0;
  57. dockBatteryVoltage = 0;
  58. dockBatteryTemperature = 0;
  59. dockBatteryTechnology = String8(String8::kEmptyString);
  60. }
  61. return OK;
  62. }
  63. status_t BatteryProperties::writeToParcel(Parcel* p) const {
  64. p->writeInt32(chargerAcOnline ? 1 : 0);
  65. p->writeInt32(chargerUsbOnline ? 1 : 0);
  66. p->writeInt32(chargerWirelessOnline ? 1 : 0);
  67. p->writeInt32(maxChargingCurrent);
  68. p->writeInt32(batteryStatus);
  69. p->writeInt32(batteryHealth);
  70. p->writeInt32(batteryPresent ? 1 : 0);
  71. p->writeInt32(batteryLevel);
  72. p->writeInt32(batteryVoltage);
  73. p->writeInt32(batteryTemperature);
  74. p->writeString16(String16(batteryTechnology));
  75. p->writeInt32(dockBatterySupported ? 1 : 0);
  76. if (dockBatterySupported) {
  77. p->writeInt32(chargerDockAcOnline ? 1 : 0);
  78. p->writeInt32(dockBatteryStatus);
  79. p->writeInt32(dockBatteryHealth);
  80. p->writeInt32(dockBatteryPresent ? 1 : 0);
  81. p->writeInt32(dockBatteryLevel);
  82. p->writeInt32(dockBatteryVoltage);
  83. p->writeInt32(dockBatteryTemperature);
  84. p->writeString16(String16(dockBatteryTechnology));
  85. }
  86. return OK;
  87. }
  88. }; // namespace android