diff --git a/Android.mk b/Android.mk index 1fc560c..a89d84c 100644 --- a/Android.mk +++ b/Android.mk @@ -147,13 +147,15 @@ LOCAL_CLANG := true LOCAL_TIDY := $(common_local_tidy_enabled) LOCAL_TIDY_FLAGS := $(common_local_tidy_flags) LOCAL_TIDY_CHECKS := $(common_local_tidy_checks) -LOCAL_SRC_FILES := vdc.cpp +LOCAL_SRC_FILES := vdc.cpp binder/android/os/IVold.aidl LOCAL_MODULE := vdc -LOCAL_SHARED_LIBRARIES := libcutils libbase +LOCAL_SHARED_LIBRARIES := libbase libbinder libcutils libutils LOCAL_CFLAGS := $(vold_cflags) LOCAL_CONLYFLAGS := $(vold_conlyflags) LOCAL_INIT_RC := vdc.rc +LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/binder + include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) diff --git a/vdc.cpp b/vdc.cpp index 7ab5fcc..3a38641 100644 --- a/vdc.cpp +++ b/vdc.cpp @@ -30,15 +30,23 @@ #include #include +#include "android/os/IVold.h" + #include #include +#include #include #include +#define ENABLE_BINDER 1 + static void usage(char *progname); + +#if !ENABLE_BINDER static int do_monitor(int sock, int stop_after_cmd); static int do_cmd(int sock, int argc, char **argv); +#endif static constexpr int kCommandTimeoutMs = 20 * 1000; @@ -62,11 +70,39 @@ int main(int argc, char **argv) { argc--; } - if (argc < 2) { + if (argc < 3) { usage(progname); exit(5); } +#if ENABLE_BINDER + std::string arg1 = argv[1]; + std::string arg2 = argv[2]; + + android::sp binder = android::defaultServiceManager()->getService( + android::String16("vold")); + if (!binder) { + LOG(ERROR) << "Failed to obtain vold Binder"; + exit(EINVAL); + } + auto vold = android::interface_cast(binder); + + if (arg1 == "cryptfs" && arg2 == "enablefilecrypto") { + exit(vold->fbeEnable().isOk() ? 0 : ENOTTY); + } else if (arg1 == "cryptfs" && arg2 == "init_user0") { + exit(vold->initUser0().isOk() ? 0 : ENOTTY); + } else if (arg1 == "cryptfs" && arg2 == "enablecrypto") { + int passwordType = android::os::IVold::PASSWORD_TYPE_DEFAULT; + int encryptionFlags = android::os::IVold::ENCRYPTION_FLAG_IN_PLACE + | android::os::IVold::ENCRYPTION_FLAG_NO_UI; + exit(vold->fdeEnable(passwordType, "", encryptionFlags).isOk() ? 0 : ENOTTY); + } else if (arg1 == "volume" && arg2 == "shutdown") { + exit(vold->shutdown().isOk() ? 0 : ENOTTY); + } else { + LOG(ERROR) << "Raw commands are no longer supported"; + exit(EINVAL); + } +#else const char* sockname = "vold"; if (!strcmp(argv[1], "cryptfs")) { sockname = "cryptd"; @@ -88,8 +124,10 @@ int main(int argc, char **argv) { } else { exit(do_cmd(sock, argc, argv)); } +#endif } +#if !ENABLE_BINDER static int do_cmd(int sock, int argc, char **argv) { int seq = getpid(); @@ -175,6 +213,7 @@ static int do_monitor(int sock, int stop_after_seq) { } return EIO; } +#endif static void usage(char *progname) { LOG(INFO) << "Usage: " << progname << " [--wait] | [arg1] [arg2...]";