Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bfcd4439 authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Steve Kondik
Browse files

native: dock battery



Change-Id: I23eadf0361cbe25029b95dbd022ce1a2cc96e94d
Require: topic:dock_battery
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent c1c5240a
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -65,6 +66,16 @@ struct BatteryProperties {
    int batteryTemperature;
    int batteryTemperature;
    String8 batteryTechnology;
    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 writeToParcel(Parcel* parcel) const;
    status_t readFromParcel(Parcel* parcel);
    status_t readFromParcel(Parcel* parcel);
};
};
+3 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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,
    REGISTER_LISTENER = IBinder::FIRST_CALL_TRANSACTION,
    UNREGISTER_LISTENER,
    UNREGISTER_LISTENER,
    GET_PROPERTY,
    GET_PROPERTY,
    GET_DOCK_PROPERTY,
};
};


class IBatteryPropertiesRegistrar : public IInterface {
class IBatteryPropertiesRegistrar : public IInterface {
@@ -36,6 +38,7 @@ public:
    virtual void registerListener(const sp<IBatteryPropertiesListener>& listener) = 0;
    virtual void registerListener(const sp<IBatteryPropertiesListener>& listener) = 0;
    virtual void unregisterListener(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 getProperty(int id, struct BatteryProperty *val) = 0;
    virtual status_t getDockProperty(int id, struct BatteryProperty *val) = 0;
};
};


class BnBatteryPropertiesRegistrar : public BnInterface<IBatteryPropertiesRegistrar> {
class BnBatteryPropertiesRegistrar : public BnInterface<IBatteryPropertiesRegistrar> {
+34 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2013 The Android Open Source Project
 * Copyright (C) 2015 The CyanogenMod Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with 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();
    batteryVoltage = p->readInt32();
    batteryTemperature = p->readInt32();
    batteryTemperature = p->readInt32();
    batteryTechnology = String8((p->readString16()).string());
    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;
    return OK;
}
}


@@ -54,6 +76,18 @@ status_t BatteryProperties::writeToParcel(Parcel* p) const {
    p->writeInt32(batteryVoltage);
    p->writeInt32(batteryVoltage);
    p->writeInt32(batteryTemperature);
    p->writeInt32(batteryTemperature);
    p->writeString16(String16(batteryTechnology));
    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;
    return OK;
}
}


+28 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,22 @@ public:
                val->readFromParcel(&reply);
                val->readFromParcel(&reply);
            return ret;
            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");
IMPLEMENT_META_INTERFACE(BatteryPropertiesRegistrar, "android.os.IBatteryPropertiesRegistrar");
@@ -97,6 +113,18 @@ status_t BnBatteryPropertiesRegistrar::onTransact(uint32_t code,
            val.writeToParcel(reply);
            val.writeToParcel(reply);
            return OK;
            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);
    return BBinder::onTransact(code, data, reply, flags);
};
};