native: dock battery

Change-Id: I23eadf0361cbe25029b95dbd022ce1a2cc96e94d
Require: topic:dock_battery
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
This commit is contained in:
Jorge Ruesga 2015-06-28 01:12:46 +02:00 committed by Steve Kondik
parent c1c5240aa9
commit bfcd443950
4 changed files with 76 additions and 0 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -65,6 +66,16 @@ struct BatteryProperties {
int batteryTemperature;
String8 batteryTechnology;
bool dockBatterySupported;
bool chargerDockAcOnline;
int dockBatteryStatus;
int dockBatteryHealth;
bool dockBatteryPresent;
int dockBatteryLevel;
int dockBatteryVoltage;
int dockBatteryTemperature;
String8 dockBatteryTechnology;
status_t writeToParcel(Parcel* parcel) const;
status_t readFromParcel(Parcel* parcel);
};

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +28,7 @@ enum {
REGISTER_LISTENER = IBinder::FIRST_CALL_TRANSACTION,
UNREGISTER_LISTENER,
GET_PROPERTY,
GET_DOCK_PROPERTY,
};
class IBatteryPropertiesRegistrar : public IInterface {
@ -36,6 +38,7 @@ public:
virtual void registerListener(const sp<IBatteryPropertiesListener>& listener) = 0;
virtual void unregisterListener(const sp<IBatteryPropertiesListener>& listener) = 0;
virtual status_t getProperty(int id, struct BatteryProperty *val) = 0;
virtual status_t getDockProperty(int id, struct BatteryProperty *val) = 0;
};
class BnBatteryPropertiesRegistrar : public BnInterface<IBatteryPropertiesRegistrar> {

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -40,6 +41,27 @@ status_t BatteryProperties::readFromParcel(Parcel* p) {
batteryVoltage = p->readInt32();
batteryTemperature = p->readInt32();
batteryTechnology = String8((p->readString16()).string());
dockBatterySupported = p->readInt32() == 1 ? true : false;
if (dockBatterySupported) {
chargerDockAcOnline = p->readInt32() == 1 ? true : false;
dockBatteryStatus = p->readInt32();
dockBatteryHealth = p->readInt32();
dockBatteryPresent = p->readInt32() == 1 ? true : false;
dockBatteryLevel = p->readInt32();
dockBatteryVoltage = p->readInt32();
dockBatteryTemperature = p->readInt32();
dockBatteryTechnology = String8((p->readString16()).string());
} else {
chargerDockAcOnline = false;
dockBatteryStatus = BATTERY_STATUS_UNKNOWN;
dockBatteryHealth = BATTERY_HEALTH_UNKNOWN;
dockBatteryPresent = false;
dockBatteryLevel = 0;
dockBatteryVoltage = 0;
dockBatteryTemperature = 0;
dockBatteryTechnology = String8(String8::kEmptyString);
}
return OK;
}
@ -54,6 +76,18 @@ status_t BatteryProperties::writeToParcel(Parcel* p) const {
p->writeInt32(batteryVoltage);
p->writeInt32(batteryTemperature);
p->writeString16(String16(batteryTechnology));
p->writeInt32(dockBatterySupported ? 1 : 0);
if (dockBatterySupported) {
p->writeInt32(chargerDockAcOnline ? 1 : 0);
p->writeInt32(dockBatteryStatus);
p->writeInt32(dockBatteryHealth);
p->writeInt32(dockBatteryPresent ? 1 : 0);
p->writeInt32(dockBatteryLevel);
p->writeInt32(dockBatteryVoltage);
p->writeInt32(dockBatteryTemperature);
p->writeString16(String16(dockBatteryTechnology));
}
return OK;
}

View File

@ -60,6 +60,22 @@ public:
val->readFromParcel(&reply);
return ret;
}
status_t getDockProperty(int id, struct BatteryProperty *val) {
Parcel data, reply;
data.writeInterfaceToken(IBatteryPropertiesRegistrar::getInterfaceDescriptor());
data.writeInt32(id);
remote()->transact(GET_DOCK_PROPERTY, data, &reply);
int32_t ret = reply.readExceptionCode();
if (ret != 0) {
return ret;
}
ret = reply.readInt32();
int parcelpresent = reply.readInt32();
if (parcelpresent)
val->readFromParcel(&reply);
return ret;
}
};
IMPLEMENT_META_INTERFACE(BatteryPropertiesRegistrar, "android.os.IBatteryPropertiesRegistrar");
@ -97,6 +113,18 @@ status_t BnBatteryPropertiesRegistrar::onTransact(uint32_t code,
val.writeToParcel(reply);
return OK;
}
case GET_DOCK_PROPERTY: {
CHECK_INTERFACE(IBatteryPropertiesRegistrar, data, reply);
int id = data.readInt32();
struct BatteryProperty val;
status_t result = getDockProperty(id, &val);
reply->writeNoException();
reply->writeInt32(result);
reply->writeInt32(1);
val.writeToParcel(reply);
return OK;
}
}
return BBinder::onTransact(code, data, reply, flags);
};