244 lines
7.7 KiB
C++
Executable File
244 lines
7.7 KiB
C++
Executable File
// MBrainClient
|
|
#include <list>
|
|
#include <map>
|
|
#include <thread>
|
|
#include <memory>
|
|
#include <chrono>
|
|
#include <android-base/logging.h>
|
|
#include <aidl/vendor/mediatek/hardware/mbrain/IMBrain.h>
|
|
#include <aidl/vendor/mediatek/hardware/mbrain/BnMBrainCallbacks.h>
|
|
#include <android/binder_manager.h>
|
|
#include <android/binder_process.h>
|
|
#include <binder/IServiceManager.h>
|
|
#include <getopt.h>
|
|
#include <json/json.h>
|
|
#include "utils/Log.h"
|
|
#include "MBrainT3.h"
|
|
#include <gui/TraceUtils.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include "FrameInfo.h"
|
|
using namespace Json;
|
|
using namespace std;
|
|
using ::ndk::SpAIBinder;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::IMBrain;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_Parcelable;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_Event;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_CallbackType;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::IMBrainCallbacks;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::BnMBrainCallbacks;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_CallbackConfigData;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_CallbackDataType;
|
|
using ::aidl::vendor::mediatek::hardware::mbrain::MBrain_CallbackRegisterData;
|
|
namespace android {
|
|
namespace uirenderer {
|
|
namespace renderthread {
|
|
|
|
std::vector <std::array <int64_t, 13>> dataSet;
|
|
int ret = -1;
|
|
static const std::string serviceName = std::string() +
|
|
(IMBrain::descriptor ? IMBrain::descriptor : "") + "/default";
|
|
std::shared_ptr<IMBrain> mbrain;
|
|
shared_ptr<IMBrainCallbacks> m_pCallbackObj;
|
|
|
|
int64_t lastTimestamp = 0;
|
|
|
|
int enableSetT3 = 0;
|
|
int Mbraincheck = 0;
|
|
int m_t3MBrainToken = 0;
|
|
int m_t3SupportMBrain = 0;
|
|
|
|
__attribute__((unused)) static int64_t GetCurrentTimeInMS() {
|
|
struct timespec spec;
|
|
if (clock_gettime(CLOCK_REALTIME, &spec) == -1)
|
|
{
|
|
return 0;
|
|
}
|
|
return spec.tv_sec * 1000 + spec.tv_nsec / 1e6;
|
|
}
|
|
|
|
std::shared_ptr<IMBrain> getMBrainServer()
|
|
{
|
|
if (mbrain == nullptr) {
|
|
mbrain = IMBrain::fromBinder(SpAIBinder(AServiceManager_checkService(serviceName.c_str())));
|
|
}
|
|
return mbrain;
|
|
}
|
|
|
|
class T3MBCallback : public BnMBrainCallbacks
|
|
{
|
|
public:
|
|
T3MBCallback()
|
|
{
|
|
// ALOGD("T3MBCallback construct");
|
|
}
|
|
|
|
virtual ~T3MBCallback()
|
|
{
|
|
// ALOGD("T3MBCallback release");
|
|
}
|
|
|
|
::ndk::ScopedAStatus notifyToClient(const std::string& in_callbackData, bool* _aidl_return) override
|
|
{
|
|
*_aidl_return = 1;
|
|
Reader jsonReader;
|
|
Value root = Value(objectValue);
|
|
bool bParse = jsonReader.parse(in_callbackData, root);
|
|
if ((true == bParse) && (true == root.isObject()))
|
|
{
|
|
if (true == root.isMember("touchdebug"))
|
|
{
|
|
int touchDebug = root["touchdebug"].asInt();
|
|
ALOGD("T3 Get Callback from server, set touchDebug %d", touchDebug);
|
|
enableSetT3 = touchDebug;
|
|
}
|
|
}
|
|
return ::ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
::ndk::ScopedAStatus getMessgeFromClient(MBrain_Parcelable* pCommunicateData, bool* _aidl_return) override
|
|
{
|
|
return ::ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
::ndk::ScopedAStatus getDataFromClient(MBrain_CallbackDataType* pCallbackData, bool* _aidl_return) override
|
|
{
|
|
return ::ndk::ScopedAStatus::ok();
|
|
}
|
|
};
|
|
|
|
void init_MBrain()
|
|
{
|
|
if (Mbraincheck)
|
|
{
|
|
return;
|
|
}
|
|
shared_ptr<IMBrain> ptr = getMBrainServer();
|
|
if (nullptr != ptr)
|
|
{
|
|
ptr->IsMBrainSupport(&ret);
|
|
if (1 == ret)
|
|
{
|
|
if (m_t3SupportMBrain == 0) {
|
|
int retToken = 0;
|
|
MBrain_CallbackRegisterData regData = {};
|
|
regData.registerEvent = MBrain_Event::MB_UX_SET_INFO;
|
|
regData.registerSubType = 0;
|
|
regData.registerData = String8("T3");
|
|
ptr->GetRegisterToken(regData, &retToken);
|
|
m_t3MBrainToken = retToken;
|
|
// ALOGD("T3 get register token %d", m_t3MBrainToken);
|
|
}
|
|
m_t3SupportMBrain = true;
|
|
}
|
|
else
|
|
{
|
|
// ALOGE("T3 failed to get register token");
|
|
m_t3SupportMBrain = false;
|
|
}
|
|
}
|
|
|
|
if (m_t3MBrainToken && m_t3SupportMBrain)
|
|
{
|
|
registerCallback();
|
|
}
|
|
Mbraincheck = 1;
|
|
}
|
|
|
|
void uninit_MBrain()
|
|
{
|
|
if (!enableSetT3) {
|
|
return;
|
|
}
|
|
unregisterCallback();
|
|
mbrain = nullptr;
|
|
Mbraincheck = 0;
|
|
enableSetT3 = 0;
|
|
}
|
|
|
|
void setT3(int64_t vsyncId, int64_t frameInterval, int64_t frameCompleteNr,
|
|
int64_t swapCompletedDuration, int64_t intendedVsync,
|
|
int64_t dequeueBufferDuration, FrameInfo* mCurrentFrameInfo) {
|
|
int64_t processPid = static_cast<int64_t>(getpid());
|
|
int64_t doFrameStart = mCurrentFrameInfo->get(FrameInfoIndex::FrameStartTime);
|
|
int64_t traversalStart = mCurrentFrameInfo->get(FrameInfoIndex::PerformTraversalsStart);
|
|
int64_t drawStart = mCurrentFrameInfo->get(FrameInfoIndex::DrawStart);
|
|
int64_t dequeueBufferStart = mCurrentFrameInfo->get(FrameInfoIndex::IssueDrawCommandsStart);
|
|
int64_t queueBufferDuration = mCurrentFrameInfo->get(FrameInfoIndex::QueueBufferDuration);
|
|
int64_t timestamp = GetCurrentTimeInMS();
|
|
dataSet.push_back({timestamp, processPid, vsyncId, frameInterval, frameCompleteNr,
|
|
swapCompletedDuration, intendedVsync, doFrameStart, traversalStart, drawStart,
|
|
dequeueBufferStart, dequeueBufferDuration, queueBufferDuration});
|
|
if (lastTimestamp == 0) {
|
|
lastTimestamp = timestamp;
|
|
}
|
|
if ((timestamp - lastTimestamp) >= 5000) {
|
|
Json::Value root(Json::objectValue);
|
|
Json::Value jsonT3(Json::arrayValue);
|
|
for (const auto& data : dataSet) {
|
|
Json::Value jsonData(Json::arrayValue);
|
|
for (const auto& element : data) {
|
|
jsonData.append(element);
|
|
}
|
|
jsonT3.append(jsonData);
|
|
}
|
|
root["timestamp"] = timestamp;
|
|
root["T3"] = jsonT3;
|
|
Json::FastWriter writer;
|
|
writer.omitEndingLineFeed();
|
|
std::string jsonString = writer.write(root);
|
|
ALOGD("setT3 jsonString=%s", jsonString.c_str());
|
|
|
|
shared_ptr<IMBrain> ptr = getMBrainServer();
|
|
if (ptr != nullptr) {
|
|
MBrain_Event mbEvent = MBrain_Event::MB_UX_SET_INFO;
|
|
MBrain_Parcelable mbrain_parcelable_input;
|
|
mbrain_parcelable_input.eventHint = 0;
|
|
mbrain_parcelable_input.privData = String8(jsonString.c_str());
|
|
ndk::ScopedAStatus status = ptr->Notify(mbEvent, mbrain_parcelable_input, &ret);
|
|
dataSet.clear();
|
|
lastTimestamp = GetCurrentTimeInMS();
|
|
}
|
|
}
|
|
}
|
|
|
|
void registerCallback()
|
|
{
|
|
if (Mbraincheck)
|
|
{
|
|
return;
|
|
}
|
|
shared_ptr<IMBrain> ptr = getMBrainServer();
|
|
if (nullptr != ptr && 0 != m_t3MBrainToken)
|
|
{
|
|
m_pCallbackObj = ::ndk::SharedRefBase::make<T3MBCallback>();
|
|
|
|
int ret = -1;
|
|
MBrain_CallbackConfigData config = {};
|
|
config.configToken = m_t3MBrainToken;
|
|
config.configSubToken = 0;
|
|
config.configData = String8("");
|
|
ptr->RegisterCallbackByHashID(config, m_pCallbackObj, &ret);
|
|
}
|
|
}
|
|
|
|
void unregisterCallback()
|
|
{
|
|
shared_ptr<IMBrain> ptr = getMBrainServer();
|
|
int ret = -1;
|
|
MBrain_CallbackConfigData config = {};
|
|
config.configToken = m_t3MBrainToken;
|
|
config.configSubToken = 0;
|
|
config.configData = String8("");
|
|
if (nullptr != ptr)
|
|
{
|
|
ptr->UnRegisterCallbackByHashID(config, m_pCallbackObj, &ret);
|
|
}
|
|
m_t3MBrainToken = 0;
|
|
m_pCallbackObj = nullptr;
|
|
}
|
|
|
|
} /* namespace renderthread */
|
|
} /* namespace uirenderer */
|
|
} /* namespace android */
|