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

Commit 00443f3a authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10094917 from 723eeecb to udc-qpr1-release

Change-Id: Ib3f0a68345c327ba215cfae395eeb49703e7661f
parents d5a4b538 723eeecb
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -105,6 +105,8 @@ class RemoteAccessService
    size_t mRetryWaitInMs = 10'000;
    size_t mRetryWaitInMs = 10'000;
    std::shared_ptr<DebugRemoteTaskCallback> mDebugCallback;
    std::shared_ptr<DebugRemoteTaskCallback> mDebugCallback;


    std::thread mInjectDebugTaskThread;

    void runTaskLoop();
    void runTaskLoop();
    void maybeStartTaskLoop();
    void maybeStartTaskLoop();
    void maybeStopTaskLoop();
    void maybeStopTaskLoop();
@@ -116,6 +118,8 @@ class RemoteAccessService
    void printCurrentStatus(int fd);
    void printCurrentStatus(int fd);
    std::string clientIdToTaskCountToStringLocked() REQUIRES(mLock);
    std::string clientIdToTaskCountToStringLocked() REQUIRES(mLock);
    void debugInjectTask(int fd, std::string_view clientId, std::string_view taskData);
    void debugInjectTask(int fd, std::string_view clientId, std::string_view taskData);
    void debugInjectTaskNextReboot(int fd, std::string_view clientId, std::string_view taskData,
                                   const char* latencyInSecStr);
    void updateGrpcConnected(bool connected);
    void updateGrpcConnected(bool connected);
    android::base::Result<void> deliverRemoteTaskThroughCallback(const std::string& clientId,
    android::base::Result<void> deliverRemoteTaskThroughCallback(const std::string& clientId,
                                                                 std::string_view taskData);
                                                                 std::string_view taskData);
+82 −3
Original line number Original line Diff line number Diff line
@@ -18,12 +18,16 @@


#include <VehicleUtils.h>
#include <VehicleUtils.h>
#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
#include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android/binder_status.h>
#include <android/binder_status.h>
#include <grpc++/grpc++.h>
#include <grpc++/grpc++.h>
#include <private/android_filesystem_config.h>
#include <private/android_filesystem_config.h>
#include <sys/stat.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <chrono>
#include <chrono>
#include <fstream>
#include <iostream>
#include <thread>
#include <thread>


namespace android {
namespace android {
@@ -37,6 +41,7 @@ using ::aidl::android::hardware::automotive::remoteaccess::ApState;
using ::aidl::android::hardware::automotive::remoteaccess::IRemoteTaskCallback;
using ::aidl::android::hardware::automotive::remoteaccess::IRemoteTaskCallback;
using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::android::base::Error;
using ::android::base::Error;
using ::android::base::ParseInt;
using ::android::base::Result;
using ::android::base::Result;
using ::android::base::ScopedLockAssertion;
using ::android::base::ScopedLockAssertion;
using ::android::base::StringAppendF;
using ::android::base::StringAppendF;
@@ -57,8 +62,12 @@ constexpr char COMMAND_STOP_DEBUG_CALLBACK[] = "--stop-debug-callback";
constexpr char COMMAND_SHOW_TASK[] = "--show-task";
constexpr char COMMAND_SHOW_TASK[] = "--show-task";
constexpr char COMMAND_GET_VEHICLE_ID[] = "--get-vehicle-id";
constexpr char COMMAND_GET_VEHICLE_ID[] = "--get-vehicle-id";
constexpr char COMMAND_INJECT_TASK[] = "--inject-task";
constexpr char COMMAND_INJECT_TASK[] = "--inject-task";
constexpr char COMMAND_INJECT_TASK_NEXT_REBOOT[] = "--inject-task-next-reboot";
constexpr char COMMAND_STATUS[] = "--status";
constexpr char COMMAND_STATUS[] = "--status";


constexpr char DEBUG_TASK_FOLDER[] = "/data/local/tests";
constexpr char DEBUG_TASK_FILE[] = "/data/local/tests/debugTask";

std::vector<uint8_t> stringToBytes(std::string_view s) {
std::vector<uint8_t> stringToBytes(std::string_view s) {
    const char* data = s.data();
    const char* data = s.data();
    return std::vector<uint8_t>(data, data + s.size());
    return std::vector<uint8_t>(data, data + s.size());
@@ -92,10 +101,43 @@ std::string boolToString(bool x) {
}  // namespace
}  // namespace


RemoteAccessService::RemoteAccessService(WakeupClient::StubInterface* grpcStub)
RemoteAccessService::RemoteAccessService(WakeupClient::StubInterface* grpcStub)
    : mGrpcStub(grpcStub){};
    : mGrpcStub(grpcStub) {
    std::ifstream debugTaskFile;
    debugTaskFile.open(DEBUG_TASK_FILE, std::ios::in);
    if (!debugTaskFile.is_open()) {
        ALOGD("No debug task available");
        return;
    }

    char buffer[1024] = {};
    debugTaskFile.getline(buffer, sizeof(buffer));
    std::string clientId = std::string(buffer);
    debugTaskFile.getline(buffer, sizeof(buffer));
    std::string taskData = std::string(buffer);
    int latencyInSec;
    debugTaskFile >> latencyInSec;
    debugTaskFile.close();

    ALOGD("Task for client: %s, data: [%s], latency: %d\n", clientId.c_str(), taskData.c_str(),
          latencyInSec);

    mInjectDebugTaskThread = std::thread([this, clientId, taskData, latencyInSec] {
        std::this_thread::sleep_for(std::chrono::seconds(latencyInSec));
        if (auto result = deliverRemoteTaskThroughCallback(clientId, taskData); !result.ok()) {
            ALOGE("Failed to inject debug task, clientID: %s, taskData: %s, error: %s",
                  clientId.c_str(), taskData.c_str(), result.error().message().c_str());
            return;
        }
        ALOGD("Task for client: %s, data: [%s] successfully injected\n", clientId.c_str(),
              taskData.c_str());
    });
}


RemoteAccessService::~RemoteAccessService() {
RemoteAccessService::~RemoteAccessService() {
    maybeStopTaskLoop();
    maybeStopTaskLoop();
    if (mInjectDebugTaskThread.joinable()) {
        mInjectDebugTaskThread.join();
    }
}
}


void RemoteAccessService::maybeStartTaskLoop() {
void RemoteAccessService::maybeStartTaskLoop() {
@@ -286,9 +328,12 @@ void RemoteAccessService::dumpHelp(int fd) {
            "%s: Show tasks received by debug callback\n"
            "%s: Show tasks received by debug callback\n"
            "%s: Get vehicle id\n"
            "%s: Get vehicle id\n"
            "%s [client_id] [task_data]: Inject a task\n"
            "%s [client_id] [task_data]: Inject a task\n"
            "%s [client_id] [task_data] [latencyInSec]: "
            "Inject a task on next reboot after latencyInSec seconds\n"
            "%s: Show status\n",
            "%s: Show status\n",
            COMMAND_SET_AP_STATE, COMMAND_START_DEBUG_CALLBACK, COMMAND_STOP_DEBUG_CALLBACK,
            COMMAND_SET_AP_STATE, COMMAND_START_DEBUG_CALLBACK, COMMAND_STOP_DEBUG_CALLBACK,
            COMMAND_SHOW_TASK, COMMAND_GET_VEHICLE_ID, COMMAND_INJECT_TASK, COMMAND_STATUS);
            COMMAND_SHOW_TASK, COMMAND_GET_VEHICLE_ID, COMMAND_INJECT_TASK,
            COMMAND_INJECT_TASK_NEXT_REBOOT, COMMAND_STATUS);
}
}


binder_status_t RemoteAccessService::dump(int fd, const char** args, uint32_t numArgs) {
binder_status_t RemoteAccessService::dump(int fd, const char** args, uint32_t numArgs) {
@@ -365,6 +410,12 @@ binder_status_t RemoteAccessService::dump(int fd, const char** args, uint32_t nu
            return STATUS_OK;
            return STATUS_OK;
        }
        }
        debugInjectTask(fd, args[1], args[2]);
        debugInjectTask(fd, args[1], args[2]);
    } else if (!strcmp(args[0], COMMAND_INJECT_TASK_NEXT_REBOOT)) {
        if (numArgs < 4) {
            dumpHelp(fd);
            return STATUS_OK;
        }
        debugInjectTaskNextReboot(fd, args[1], args[2], args[3]);
    } else if (!strcmp(args[0], COMMAND_STATUS)) {
    } else if (!strcmp(args[0], COMMAND_STATUS)) {
        printCurrentStatus(fd);
        printCurrentStatus(fd);
    } else {
    } else {
@@ -389,13 +440,41 @@ void RemoteAccessService::debugInjectTask(int fd, std::string_view clientId,
                                          std::string_view taskData) {
                                          std::string_view taskData) {
    std::string clientIdCopy = std::string(clientId);
    std::string clientIdCopy = std::string(clientId);
    if (auto result = deliverRemoteTaskThroughCallback(clientIdCopy, taskData); !result.ok()) {
    if (auto result = deliverRemoteTaskThroughCallback(clientIdCopy, taskData); !result.ok()) {
        dprintf(fd, "Failed to inject task: %s", result.error().message().c_str());
        dprintf(fd, "Failed to inject task: %s\n", result.error().message().c_str());
        return;
        return;
    }
    }
    dprintf(fd, "Task for client: %s, data: [%s] successfully injected\n", clientId.data(),
    dprintf(fd, "Task for client: %s, data: [%s] successfully injected\n", clientId.data(),
            taskData.data());
            taskData.data());
}
}


void RemoteAccessService::debugInjectTaskNextReboot(int fd, std::string_view clientId,
                                                    std::string_view taskData,
                                                    const char* latencyInSecStr) {
    int latencyInSec;
    if (!ParseInt(latencyInSecStr, &latencyInSec)) {
        dprintf(fd, "The input latency in second is not a valid integer");
        return;
    }
    std::ofstream debugTaskFile;
    debugTaskFile.open(DEBUG_TASK_FILE, std::ios::out);
    if (!debugTaskFile.is_open()) {
        dprintf(fd,
                "Failed to open debug task file, please run the command: "
                "'adb shell touch %s' first\n",
                DEBUG_TASK_FILE);
        return;
    }
    if (taskData.find("\n") != std::string::npos) {
        dprintf(fd, "Task data must not contain newline\n");
        return;
    }
    debugTaskFile << clientId << "\n" << taskData << "\n" << latencyInSec;
    debugTaskFile.close();
    dprintf(fd,
            "Task with clientId: %s, task data: %s, latency: %d sec scheduled for next reboot\n",
            clientId.data(), taskData.data(), latencyInSec);
}

std::string RemoteAccessService::clientIdToTaskCountToStringLocked() {
std::string RemoteAccessService::clientIdToTaskCountToStringLocked() {
    // Print the table header
    // Print the table header
    std::string output = "| ClientId | Count |\n";
    std::string output = "| ClientId | Count |\n";
+26 −0
Original line number Original line Diff line number Diff line
@@ -110,6 +110,32 @@ cc_test {
    require_root: true,
    require_root: true,
}
}


cc_test {
    name: "android.hardware.biometrics.fingerprint.SessionTest",
    local_include_dirs: ["include"],
    srcs: [
        "tests/SessionTest.cpp",
        "Session.cpp",
        "FakeFingerprintEngine.cpp",
        "FakeLockoutTracker.cpp",
    ],
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "android.hardware.biometrics.common.thread",
    ],
    static_libs: [
        "libandroid.hardware.biometrics.fingerprint.VirtualProps",
        "android.hardware.biometrics.fingerprint-V3-ndk",
        "android.hardware.biometrics.common-V3-ndk",
        "android.hardware.keymaster-V4-ndk",
        "android.hardware.biometrics.common.util",
    ],
    vendor: true,
    test_suites: ["general-tests"],
    require_root: true,
}

sysprop_library {
sysprop_library {
    name: "android.hardware.biometrics.fingerprint.VirtualProps",
    name: "android.hardware.biometrics.fingerprint.VirtualProps",
    srcs: ["fingerprint.sysprop"],
    srcs: ["fingerprint.sysprop"],
+2 −0
Original line number Original line Diff line number Diff line
@@ -103,6 +103,8 @@ ndk::ScopedAStatus Fingerprint::createSession(int32_t sensorId, int32_t userId,
    mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker);
    mSession = SharedRefBase::make<Session>(sensorId, userId, cb, mEngine.get(), &mWorker);
    *out = mSession;
    *out = mSession;


    mSession->linkToDeath(cb->asBinder().get());

    LOG(INFO) << "createSession: sensorId:" << sensorId << " userId:" << userId;
    LOG(INFO) << "createSession: sensorId:" << sensorId << " userId:" << userId;
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::ok();
}
}
+15 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,14 @@


namespace aidl::android::hardware::biometrics::fingerprint {
namespace aidl::android::hardware::biometrics::fingerprint {


void onClientDeath(void* cookie) {
    LOG(INFO) << "FingerprintService has died";
    Session* session = static_cast<Session*>(cookie);
    if (session && !session->isClosed()) {
        session->close();
    }
}

Session::Session(int sensorId, int userId, std::shared_ptr<ISessionCallback> cb,
Session::Session(int sensorId, int userId, std::shared_ptr<ISessionCallback> cb,
                 FakeFingerprintEngine* engine, WorkerThread* worker)
                 FakeFingerprintEngine* engine, WorkerThread* worker)
    : mSensorId(sensorId),
    : mSensorId(sensorId),
@@ -39,6 +47,12 @@ Session::Session(int sensorId, int userId, std::shared_ptr<ISessionCallback> cb,
    CHECK(mEngine);
    CHECK(mEngine);
    CHECK(mWorker);
    CHECK(mWorker);
    CHECK(mCb);
    CHECK(mCb);

    mDeathRecipient = AIBinder_DeathRecipient_new(onClientDeath);
}

binder_status_t Session::linkToDeath(AIBinder* binder) {
    return AIBinder_linkToDeath(binder, mDeathRecipient, this);
}
}


void Session::scheduleStateOrCrash(SessionState state) {
void Session::scheduleStateOrCrash(SessionState state) {
@@ -228,6 +242,7 @@ ndk::ScopedAStatus Session::close() {
    // Crashing.";
    // Crashing.";
    mCurrentState = SessionState::CLOSED;
    mCurrentState = SessionState::CLOSED;
    mCb->onSessionClosed();
    mCb->onSessionClosed();
    AIBinder_DeathRecipient_delete(mDeathRecipient);
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::ok();
}
}


Loading