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

Commit 97b2f250 authored by Ruchi Kandoi's avatar Ruchi Kandoi
Browse files

memtrack: Add android.hardware.memtrack@1.0-impl



Bug: 31180823
Change-Id: I5afa790a94eebf8f1755eb51ff8cfeb28b836543
Signed-off-by: default avatarRuchi <Kandoi&lt;kandoiruchi@google.com>
parent 02cfc4e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ subdirs = [
    "audio/effect/2.0",
    "benchmarks/msgq/1.0",
    "memtrack/1.0",
    "memtrack/1.0/default",
    "nfc/1.0",
    "nfc/1.0/default",
    "tests/bar/1.0",
+30 −0
Original line number Diff line number Diff line
// Copyright (C) 2016 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.

cc_library_shared {
    name: "android.hardware.memtrack@1.0-impl",
    relative_install_path: "hw",
    srcs: ["Memtrack.cpp"],

    shared_libs: [
        "libbase",
        "liblog",
        "libhidl",
        "libhardware",
        "libhwbinder",
        "libutils",
        "android.hardware.memtrack@1.0",
    ],

}
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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 LOG_TAG "android.hardware.memtrack@1.0-impl"
#include <hardware/hardware.h>
#include <hardware/memtrack.h>

#include "Memtrack.h"
namespace android {
namespace hardware {
namespace memtrack {
namespace V1_0 {
namespace implementation {

Memtrack::Memtrack(memtrack_module_t *module) : mModule(module) {
    if (mModule)
        mModule->init(mModule);
}

Memtrack::~Memtrack() {
    delete(mModule);
}

Return<void> Memtrack::getMemory(int32_t pid, MemtrackType type,
        getMemory_cb _hidl_cb)  {
    hidl_vec<MemtrackRecord> records;
    size_t temp = 0;
    size_t *size = &temp;
    int ret = 0;

    if (mModule->getMemory == nullptr)
    {
        _hidl_cb(MemtrackStatus::SUCCESS, records);
        return Void();
    }
    ret = mModule->getMemory(mModule, pid, static_cast<memtrack_type>(type),
            NULL, size);
    if (ret == 0)
    {
        memtrack_record *legacy_records = new memtrack_record[*size];
        ret = mModule->getMemory(mModule, pid,
                static_cast<memtrack_type>(type), legacy_records, size);
        if (ret == 0)
        {
            records.resize(*size);
            for(size_t i = 0; i < *size; i++)
            {
                records[i].sizeInBytes = legacy_records[i].size_in_bytes;
                records[i].flags = legacy_records[i].flags;
            }
        }
        delete[] legacy_records;
    }
    _hidl_cb(MemtrackStatus::SUCCESS, records);
    return Void();
}


IMemtrack* HIDL_FETCH_IMemtrack(const char* name) {
    int ret = 0;
    const hw_module_t* hw_module = NULL;
    memtrack_module_t *memtrack_module = NULL;

    ret = hw_get_module(name, &hw_module);
    if (ret == 0 && hw_module->methods->open > 0)
    {
        ret = hw_module->methods->open(hw_module, name,
                reinterpret_cast<hw_device_t**>(&memtrack_module));
        if (ret == 0)
                return new Memtrack(memtrack_module);
        else {
            ALOGE("Passthrough failed to load legacy HAL.");
        }
    }
    else {
        ALOGE ("hw_get_module %s failed: %d", name, ret);
    }
    return nullptr;
}

} // namespace implementation
}  // namespace V1_0
}  // namespace memtrack
}  // namespace hardware
}  // namespace android
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

#ifndef HIDL_GENERATED_android_hardware_memtrack_V1_0_Memtrack_H_
#define HIDL_GENERATED_android_hardware_memtrack_V1_0_Memtrack_H_

#include <android/hardware/memtrack/1.0/IMemtrack.h>
#include <hidl/Status.h>

#include <hidl/MQDescriptor.h>
namespace android {
namespace hardware {
namespace memtrack {
namespace V1_0 {
namespace implementation {

using ::android::hardware::memtrack::V1_0::IMemtrack;
using ::android::hardware::memtrack::V1_0::MemtrackRecord;
using ::android::hardware::memtrack::V1_0::MemtrackStatus;
using ::android::hardware::memtrack::V1_0::MemtrackType;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;

struct Memtrack : public IMemtrack {
    Memtrack(memtrack_module_t* module);
    ~Memtrack();
    Return<void> getMemory(int32_t pid, MemtrackType type, getMemory_cb _hidl_cb)  override;

  private:
    memtrack_module_t* mModule;
};

extern "C" IMemtrack* HIDL_FETCH_IMemtrack(const char* name);

}  // namespace implementation
}  // namespace V1_0
}  // namespace memtrack
}  // namespace hardware
}  // namespace android

#endif  // HIDL_GENERATED_android_hardware_memtrack_V1_0_Memtrack_H_