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

Commit d158a080 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "servicedispatcher: exit when adb debugging is turned off." am: 60969843

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1775686

Change-Id: I016071be5cf1090f25d3c5c0c78fd4c59fc62c7c
parents bd3eee40 60969843
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -360,5 +360,6 @@ cc_binary {
        "libbinder",
        "libbinder",
        "liblog",
        "liblog",
        "libutils",
        "libutils",
        "android.debug_aidl-cpp",
    ],
    ],
}
}
+27 −0
Original line number Original line Diff line number Diff line
@@ -23,9 +23,12 @@
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android/debug/BnAdbCallback.h>
#include <android/debug/IAdbManager.h>
#include <android/os/BnServiceManager.h>
#include <android/os/BnServiceManager.h>
#include <android/os/IServiceManager.h>
#include <android/os/IServiceManager.h>
#include <binder/IServiceManager.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <binder/RpcServer.h>
#include <binder/RpcServer.h>


using android::BBinder;
using android::BBinder;
@@ -50,6 +53,7 @@ namespace {


const char* kLocalInetAddress = "127.0.0.1";
const char* kLocalInetAddress = "127.0.0.1";
using ServiceRetriever = decltype(&android::IServiceManager::checkService);
using ServiceRetriever = decltype(&android::IServiceManager::checkService);
using android::debug::IAdbManager;


int Usage(const char* program) {
int Usage(const char* program) {
    auto basename = Basename(program);
    auto basename = Basename(program);
@@ -213,6 +217,25 @@ int wrapServiceManager(const ServiceRetriever& serviceRetriever) {
    __builtin_unreachable();
    __builtin_unreachable();
}
}


class AdbCallback : public android::debug::BnAdbCallback {
public:
    android::binder::Status onDebuggingChanged(bool enabled,
                                               android::debug::AdbTransportType) override {
        if (!enabled) {
            LOG(ERROR) << "ADB debugging disabled, exiting.";
            exit(EX_SOFTWARE);
        }
        return android::binder::Status::ok();
    }
};

void exitOnAdbDebuggingDisabled() {
    auto adb = android::waitForService<IAdbManager>(String16("adb"));
    CHECK(adb != nullptr) << "Unable to retrieve service adb";
    auto status = adb->registerCallback(sp<AdbCallback>::make());
    CHECK(status.isOk()) << "Unable to call IAdbManager::registerCallback: " << status;
}

// Log to logd. For warning and more severe messages, also log to stderr.
// Log to logd. For warning and more severe messages, also log to stderr.
class ServiceDispatcherLogger {
class ServiceDispatcherLogger {
public:
public:
@@ -253,6 +276,10 @@ int main(int argc, char* argv[]) {
        }
        }
    }
    }


    android::ProcessState::self()->setThreadPoolMaxThreadCount(1);
    android::ProcessState::self()->startThreadPool();
    exitOnAdbDebuggingDisabled();

    if (optind + 1 != argc) return Usage(argv[0]);
    if (optind + 1 != argc) return Usage(argv[0]);
    auto name = argv[optind];
    auto name = argv[optind];