aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-11-11 19:02:33 -0600
committerandroid-build-merger2016-11-11 19:02:33 -0600
commitf2574b8206030158b319f96fd78d82840da73194 (patch)
tree06938b7e126c084683f65034f9b0b36cbbe39856 /uncrypt/uncrypt.cpp
parent118e814bfeae5f761255dd34577b8865ac6d28d1 (diff)
parent4c1f3eda98b2c0fde45f71de4fdcea2a46a67cbd (diff)
downloadplatform-bootable-recovery-f2574b8206030158b319f96fd78d82840da73194.tar.gz
platform-bootable-recovery-f2574b8206030158b319f96fd78d82840da73194.tar.xz
platform-bootable-recovery-f2574b8206030158b319f96fd78d82840da73194.zip
Merge "Allow uncrypt to work without socket communication"
am: 4c1f3eda98 Change-Id: I8e86d4201d2fac0293e70df54e0816c96e85a9b7
Diffstat (limited to 'uncrypt/uncrypt.cpp')
-rw-r--r--uncrypt/uncrypt.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp
index f31d55aa..38b25abc 100644
--- a/uncrypt/uncrypt.cpp
+++ b/uncrypt/uncrypt.cpp
@@ -210,6 +210,11 @@ static const char* find_block_device(const char* path, bool* encryptable, bool*
210} 210}
211 211
212static bool write_status_to_socket(int status, int socket) { 212static bool write_status_to_socket(int status, int socket) {
213 // If socket equals -1, uncrypt is in debug mode without socket communication.
214 // Skip writing and return success.
215 if (socket == -1) {
216 return true;
217 }
213 int status_out = htonl(status); 218 int status_out = htonl(status);
214 return android::base::WriteFully(socket, &status_out, sizeof(int)); 219 return android::base::WriteFully(socket, &status_out, sizeof(int));
215} 220}
@@ -567,7 +572,7 @@ static void usage(const char* exename) {
567} 572}
568 573
569int main(int argc, char** argv) { 574int main(int argc, char** argv) {
570 enum { UNCRYPT, SETUP_BCB, CLEAR_BCB } action; 575 enum { UNCRYPT, SETUP_BCB, CLEAR_BCB, UNCRYPT_DEBUG } action;
571 const char* input_path = nullptr; 576 const char* input_path = nullptr;
572 const char* map_file = CACHE_BLOCK_MAP.c_str(); 577 const char* map_file = CACHE_BLOCK_MAP.c_str();
573 578
@@ -580,7 +585,7 @@ int main(int argc, char** argv) {
580 } else if (argc == 3) { 585 } else if (argc == 3) {
581 input_path = argv[1]; 586 input_path = argv[1];
582 map_file = argv[2]; 587 map_file = argv[2];
583 action = UNCRYPT; 588 action = UNCRYPT_DEBUG;
584 } else { 589 } else {
585 usage(argv[0]); 590 usage(argv[0]);
586 return 2; 591 return 2;
@@ -591,6 +596,17 @@ int main(int argc, char** argv) {
591 return 1; 596 return 1;
592 } 597 }
593 598
599 if (action == UNCRYPT_DEBUG) {
600 LOG(INFO) << "uncrypt called in debug mode, skip socket communication\n";
601 bool success = uncrypt_wrapper(input_path, map_file, -1);
602 if (success) {
603 LOG(INFO) << "uncrypt succeeded\n";
604 } else{
605 LOG(INFO) << "uncrypt failed\n";
606 }
607 return success ? 0 : 1;
608 }
609
594 // c3. The socket is created by init when starting the service. uncrypt 610 // c3. The socket is created by init when starting the service. uncrypt
595 // will use the socket to communicate with its caller. 611 // will use the socket to communicate with its caller.
596 android::base::unique_fd service_socket(android_get_control_socket(UNCRYPT_SOCKET.c_str())); 612 android::base::unique_fd service_socket(android_get_control_socket(UNCRYPT_SOCKET.c_str()));