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

Commit bf972d99 authored by Tej Singh's avatar Tej Singh
Browse files

Atom: Remaining and full battery capacity

Add pulled remaining battery capacity and full battery capacity atoms.

Test: cts test accompanies
Change-Id: I0f09e9459b56e25cc3ac21e1a5e781daadea0a01
parent 00646ee7
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ statsd_common_src := \
    src/external/StatsPuller.cpp \
    src/external/StatsCompanionServicePuller.cpp \
    src/external/SubsystemSleepStatePuller.cpp \
    src/external/ResourceHealthManagerPuller.cpp \
    src/external/CpuTimePerUidPuller.cpp \
    src/external/CpuTimePerUidFreqPuller.cpp \
    src/external/StatsPullerManagerImpl.cpp \
@@ -75,7 +76,8 @@ statsd_common_aidl_includes := \
    $(LOCAL_PATH)/../../core/java

statsd_common_static_libraries := \
    libplatformprotos
    libhealthhalutils \
    libplatformprotos \

statsd_common_shared_libraries := \
    libbase \
@@ -93,6 +95,7 @@ statsd_common_shared_libraries := \
    libhidlbase \
    libhidltransport \
    libhwbinder \
    android.hardware.health@2.0 \
    android.hardware.power@1.0 \
    android.hardware.power@1.1 \
    libmemunreachable
+19 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ message Atom {
    }

    // Pulled events will start at field 10000.
    // Next: 10019
    // Next: 10021
    oneof pulled {
        WifiBytesTransfer wifi_bytes_transfer = 10000;
        WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001;
@@ -120,6 +120,8 @@ message Atom {
        CpuActiveTime cpu_active_time = 10016;
        CpuClusterTime cpu_cluster_time = 10017;
        DiskSpace disk_space = 10018;
        RemainingBatteryCapacity remaining_battery_capacity = 10019;
        FullBatteryCapacity full_battery_capacity = 10020;
    }
}

@@ -1410,3 +1412,19 @@ message DiskSpace {
    // available bytes in download cache or temp directories
    optional uint64 temp_available_bytes = 3;
}

/**
 * Pulls battery coulomb counter, which is the remaining battery charge in uAh.
 * Logged from: frameworks/base/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
 */
message RemainingBatteryCapacity {
    optional int32 charge_uAh = 1;
}

/**
 * Pulls battery capacity, which is the battery capacity when full in uAh.
 * Logged from: frameworks/base/cmds/statsd/src/external/ResourceHealthManagerPuller.cpp
 */
message FullBatteryCapacity {
    optional int32 capacity_uAh = 1;
}
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define DEBUG true  // STOPSHIP if true
#include "Log.h"

#include <android/hardware/health/2.0/IHealth.h>
#include <healthhalutils/HealthHalUtils.h>
#include "external/ResourceHealthManagerPuller.h"
#include "external/StatsPuller.h"

#include "ResourceHealthManagerPuller.h"
#include "logd/LogEvent.h"
#include "statslog.h"

using android::hardware::hidl_vec;
using android::hardware::health::V2_0::get_health_service;
using android::hardware::health::V2_0::HealthInfo;
using android::hardware::health::V2_0::IHealth;
using android::hardware::health::V2_0::Result;
using android::hardware::Return;
using android::hardware::Void;

using std::make_shared;
using std::shared_ptr;

namespace android {
namespace os {
namespace statsd {

sp<android::hardware::health::V2_0::IHealth> gHealthHal = nullptr;

bool getHealthHal() {
    if (gHealthHal == nullptr) {
        gHealthHal = get_health_service();

    }
    return gHealthHal != nullptr;
}

ResourceHealthManagerPuller::ResourceHealthManagerPuller(int tagId) : StatsPuller(tagId) {
}

// TODO: add other health atoms (eg. Temperature).
bool ResourceHealthManagerPuller::PullInternal(vector<shared_ptr<LogEvent>>* data) {
    if (!getHealthHal()) {
        ALOGE("Health Hal not loaded");
        return false;
    }

    uint64_t timestamp = time(nullptr) * NS_PER_SEC;

    data->clear();
    bool result_success = true;

    Return<void> ret = gHealthHal->getHealthInfo([&](Result r, HealthInfo v) {
        if (r != Result::SUCCESS) {
            result_success = false;
            return;
        }
        if (mTagId == android::util::REMAINING_BATTERY_CAPACITY) {
            auto ptr = make_shared<LogEvent>(android::util::REMAINING_BATTERY_CAPACITY, timestamp);
            ptr->write(v.legacy.batteryChargeCounter);
            ptr->init();
            data->push_back(ptr);
        } else if (mTagId == android::util::FULL_BATTERY_CAPACITY) {
            auto ptr = make_shared<LogEvent>(android::util::FULL_BATTERY_CAPACITY, timestamp);
            ptr->write(v.legacy.batteryFullCharge);
            ptr->init();
            data->push_back(ptr);
        } else {
            ALOGE("Unsupported tag in ResourceHealthManagerPuller: %d", mTagId);
        }
    });
    if (!result_success || !ret.isOk()) {
        ALOGE("getHealthHal() failed: health HAL service not available. Description: %s",
                ret.description().c_str());
        if (!ret.isOk() && ret.isDeadObject()) {
            gHealthHal = nullptr;
        }
        return false;
    }
    return true;
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <utils/String16.h>
#include "StatsPuller.h"

namespace android {
namespace os {
namespace statsd {

/**
 * Reads Ihealth.hal
 */
class ResourceHealthManagerPuller : public StatsPuller {
public:
    ResourceHealthManagerPuller(int tagId);
    bool PullInternal(vector<std::shared_ptr<LogEvent>>* data) override;
};

}  // namespace statsd
}  // namespace os
}  // namespace android
+6 −2
Original line number Diff line number Diff line
@@ -23,10 +23,11 @@
#include <climits>
#include "CpuTimePerUidFreqPuller.h"
#include "CpuTimePerUidPuller.h"
#include "SubsystemSleepStatePuller.h"
#include "ResourceHealthManagerPuller.h"
#include "StatsCompanionServicePuller.h"
#include "StatsPullerManagerImpl.h"
#include "StatsService.h"
#include "SubsystemSleepStatePuller.h"
#include "logd/LogEvent.h"
#include "statslog.h"

@@ -83,7 +84,10 @@ StatsPullerManagerImpl::StatsPullerManagerImpl()
             make_shared<StatsCompanionServicePuller>(android::util::WIFI_ACTIVITY_ENERGY_INFO)});
    mPullers.insert({android::util::MODEM_ACTIVITY_INFO,
                     make_shared<StatsCompanionServicePuller>(android::util::MODEM_ACTIVITY_INFO)});

    mPullers.insert({android::util::REMAINING_BATTERY_CAPACITY,
                     make_shared<ResourceHealthManagerPuller>(android::util::REMAINING_BATTERY_CAPACITY)});
    mPullers.insert({android::util::FULL_BATTERY_CAPACITY,
                     make_shared<ResourceHealthManagerPuller>(android::util::FULL_BATTERY_CAPACITY)});
    mStatsCompanionService = StatsService::getStatsCompanionService();
}