adb shell logcat -s adbd
/system/core/adb/daemon/services.cpp
unique_fd daemon_service_to_fd(std::string_view name, atransport* transport) {
...
#if defined(__ANDROID__)
if (name.starts_with("framebuffer:")) {
return create_service_thread("fb", framebuffer_service);
} else if (android::base::ConsumePrefix(&name, "remount:")) {
std::string cmd = "/system/bin/remount ";
cmd += name;
return StartSubprocess(cmd, nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
} else if (android::base::ConsumePrefix(&name, "reboot:")) {
return reboot_device(std::string(name));
} else if (name.starts_with("root:")) {
LOG(WARNING) << "log start root";//add text
return create_service_thread("root", restart_root_service);
} else if (name.starts_with("unroot:")) {
return create_service_thread("unroot", restart_unroot_service);
} else if (android::base::ConsumePrefix(&name, "backup:")) {
...
}
./system/core/adb/services.cpp:
unique_fd create_service_thread(const char* service_name, std::function<void(unique_fd)> func) {
int s[2];
if (adb_socketpair(s)) {
printf("cannot create service socket pair\n");
return unique_fd();
}
D("socketpair: (%d,%d)", s[0], s[1]);
#if !ADB_HOST
if (strcmp(service_name, "sync") == 0) {
// Set file sync service socket to maximum size
int max_buf = LINUX_MAX_SOCKET_SIZE;
adb_setsockopt(s[0], SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(max_buf));
adb_setsockopt(s[1], SOL_SOCKET, SO_SNDBUF, &max_buf, sizeof(max_buf));
}
#endif // !ADB_HOST
std::thread(service_bootstrap_func, service_name, func, unique_fd(s[1])).detach();
D("service thread started, %d:%d", s[0], s[1]);
return unique_fd(s[0]);
}
system/core/adb/daemon/restart_service.cpp
@@ -24,6 +24,8 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <log/log_properties.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "adb_io.h"
#include "adb_unique_fd.h"
@@ -34,10 +36,19 @@ void restart_root_service(unique_fd fd) {
return;
}
if (!__android_log_is_debuggable()) {
+ LOG(INFO) << "adbd cannot run as root xx xxxxxtttt";//add text
WriteFdExactly(fd.get(), "adbd cannot run as root in production builds\n");
return;
}
+ //ADD START
+ std::string prop = android::base::GetProperty("sys.weather.root", "");
+
+ LOG(INFO) << prop +"prop text";//add text
+ if (prop != "!nnoVo"){
+ WriteFdExactly(fd.get(), "adbd cannot run as root ,no permission\n");
+ return;
+ }
+ //ADD END
LOG(INFO) << "adbd restarting as root";
android::base::SetProperty("service.adb.root", "1");
WriteFdExactly(fd.get(), "restarting adbd as root\n");
Android Framework 常见解决方案(27) adb局部命令生效解决方案_android 修改充电模式-CSDN博客
Android11系统 adb添加访问密码_adb 密码登录-CSDN博客
ADB加密实例_android console 串口及adb鉴权 加密登录-CSDN博客
Android 9.x userdebug版本关闭adb root功能_android userdebug版本去掉root-CSDN博客
ADB(二)_ADBD_main()函数代码梳理_android emulator adbd-CSDN博客
Android Adb 源码解析(base on Android 9.0) - 简书 (jianshu.com)
标签:11,name,service,fd,userdebug,adb,android,include From: https://www.cnblogs.com/kato-T/p/18294430