Adding thread safety to proto uploader

Due to lack of thread safety it seems that protobuf values were
occasionally getting deleted during parsing, causing ubsan to register
an error down the line in the protobuf library.

Bug: 128991260
Bug: 128810613
Test: atest cts/tests/tests/keystore/src/android/keystore/cts
Change-Id: Iee7ec6195e1e0aa4b28a7484737f984ed389a75e
diff --git a/keystore/operation_proto_handler.cpp b/keystore/operation_proto_handler.cpp
index 1833acb..dfc0692 100644
--- a/keystore/operation_proto_handler.cpp
+++ b/keystore/operation_proto_handler.cpp
@@ -106,6 +106,7 @@
 }
 
 void OperationProtoHandler::uploadOpAsProto(Operation& op, bool wasOpSuccessful) {
+    std::lock_guard<std::mutex> lock(op_upload_mutex);
     OperationConfig operationConfig;
     determinePurpose(op.purpose, &operationConfig);
     checkKeyCharacteristics(op.characteristics.softwareEnforced, &operationConfig);
diff --git a/keystore/operation_proto_handler.h b/keystore/operation_proto_handler.h
index 838f3ec..64d0a59 100644
--- a/keystore/operation_proto_handler.h
+++ b/keystore/operation_proto_handler.h
@@ -20,6 +20,7 @@
 #include "operation_config.pb.h"
 #include "operation_struct.h"
 #include <chrono>
+#include <mutex>
 #include <unordered_map>
 #include <vector>
 
@@ -35,6 +36,7 @@
   private:
     std::unordered_map<std::string, int> protoMap;
     std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();
+    std::mutex op_upload_mutex;
 };
 
 }  // namespace keystore