Revert "Revert "Add profman tool: responsible to process profiles""

This reverts commit 3da74687e42de7d33a8e75df9bd64374e650f75e.

(cherry picked from commit 2e2db786b8fbaa4dceb37603a4296b0b2aea4e9e)

Change-Id: I38086cc9de939bad33bcd13b1677e1626af61c29
diff --git a/runtime/base/scoped_flock.cc b/runtime/base/scoped_flock.cc
index 814cbd0..0e8031f 100644
--- a/runtime/base/scoped_flock.cc
+++ b/runtime/base/scoped_flock.cc
@@ -83,7 +83,7 @@
 }
 
 bool ScopedFlock::Init(File* file, std::string* error_msg) {
-  file_.reset(new File(dup(file->Fd()), true));
+  file_.reset(new File(dup(file->Fd()), file->GetPath(), file->CheckUsage(), file->ReadOnlyMode()));
   if (file_->Fd() == -1) {
     file_.reset();
     *error_msg = StringPrintf("Failed to duplicate open file '%s': %s",
@@ -114,7 +114,13 @@
   if (file_.get() != nullptr) {
     int flock_result = TEMP_FAILURE_RETRY(flock(file_->Fd(), LOCK_UN));
     CHECK_EQ(0, flock_result);
-    if (file_->FlushCloseOrErase() != 0) {
+    int close_result = -1;
+    if (file_->ReadOnlyMode()) {
+      close_result = file_->Close();
+    } else {
+      close_result = file_->FlushCloseOrErase();
+    }
+    if (close_result != 0) {
       PLOG(WARNING) << "Could not close scoped file lock file.";
     }
   }