AOSP10 TWRP Merge: fix conflicts and update libraries needed

This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.

The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
diff --git a/install/include/install/adb_install.h b/install/include/install/adb_install.h
old mode 100644
new mode 100755
index 3a0a817..f7b15b2
--- a/install/include/install/adb_install.h
+++ b/install/include/install/adb_install.h
@@ -21,4 +21,4 @@
 // Applies a package via `adb sideload` or `adb rescue`. Returns the install result (in `enum
 // InstallResult`). When a reboot has been requested, INSTALL_REBOOT will be the return value, with
 // the reboot target set in reboot_action.
-int ApplyFromAdb(Device* device, bool rescue_mode, Device::BuiltinAction* reboot_action);
+int ApplyFromAdb(const char* install_file, Device::BuiltinAction* reboot_action);
diff --git a/install/include/install/fuse_sdcard_install.h b/install/include/install/fuse_sdcard_install.h
old mode 100644
new mode 100755
index 43f2489..d9214ca
--- a/install/include/install/fuse_sdcard_install.h
+++ b/install/include/install/fuse_sdcard_install.h
@@ -16,17 +16,7 @@
 
 #pragma once
 
-<<<<<<< HEAD:adb_install.h
-#include <sys/types.h>
-
-//class RecoveryUI;
-
-//static void set_usb_driver(bool enabled);
-//static void maybe_restart_adbd();
-int apply_from_adb(const char* install_file, pid_t* child_pid);
-=======
 #include "recovery_ui/device.h"
 #include "recovery_ui/ui.h"
->>>>>>> android-10.0.0_r25:install/include/install/fuse_sdcard_install.h
 
 int ApplyFromSdcard(Device* device, RecoveryUI* ui);
diff --git a/install/include/install/install.h b/install/include/install/install.h
old mode 100644
new mode 100755
index c0a8f1f..9e6787f
--- a/install/include/install/install.h
+++ b/install/include/install/install.h
@@ -48,11 +48,11 @@
 // successful installation if |should_wipe_cache| is true or an updater command asks to wipe the
 // cache.
 int install_package(const std::string& package, bool should_wipe_cache, bool needs_mount,
-                    int retry_count, RecoveryUI* ui);
+                    int retry_count);
 
 // Verifies the package by ota keys. Returns true if the package is verified successfully,
 // otherwise returns false.
-bool verify_package(Package* package, RecoveryUI* ui);
+bool verify_package(Package* package);
 
 // Reads meta data file of the package; parses each line in the format "key=value"; and writes the
 // result to |metadata|. Return true if succeed, otherwise return false.
diff --git a/install/include/install/package.h b/install/include/install/package.h
old mode 100644
new mode 100755
index cd44d10..50a4ffa
--- a/install/include/install/package.h
+++ b/install/include/install/package.h
@@ -33,9 +33,9 @@
 class Package : public VerifierInterface {
  public:
   static std::unique_ptr<Package> CreateMemoryPackage(
-      const std::string& path, const std::function<void(float)>& set_progress);
+      const std::string& path);
   static std::unique_ptr<Package> CreateMemoryPackage(
-      std::vector<uint8_t> content, const std::function<void(float)>& set_progress);
+      std::vector<uint8_t> content);
   static std::unique_ptr<Package> CreateFilePackage(const std::string& path,
                                                     const std::function<void(float)>& set_progress);
 
diff --git a/install/include/install/wipe_data.h b/install/include/install/wipe_data.h
old mode 100644
new mode 100755
index b34891f..76ebf05
--- a/install/include/install/wipe_data.h
+++ b/install/include/install/wipe_data.h
@@ -24,7 +24,7 @@
 struct selabel_handle;
 
 // Returns true on success.
-bool WipeCache(RecoveryUI* ui, const std::function<bool()>& confirm);
+bool WipeCache(const std::function<bool()>& confirm);
 
 // Returns true on success.
 bool WipeData(Device* device, bool convert_fbe);
diff --git a/install/include/installcommand.h b/install/include/installcommand.h
new file mode 100644
index 0000000..957f016
--- /dev/null
+++ b/install/include/installcommand.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef RECOVERY_INSTALL_COMMAND_H_
+#define RECOVERY_INSTALL_COMMAND_H_
+
+#define TMP_UPDATER_BINARY_PATH "/tmp/updater"
+
+#include <string>
+
+#include "zipwrap.hpp"
+
+bool read_metadata_from_package(ZipWrap* zip, std::string* meta_data);
+
+int
+abupdate_binary_command(const char* path, ZipWrap* zip, int retry_count,
+                      int status_fd, std::vector<std::string>* cmd);
+int
+update_binary_command(const char* path, int retry_count,
+                      int status_fd, std::vector<std::string>* cmd);
+
+bool verify_package_compatibility(ZipWrap *package_zip);
+
+void read_source_target_build(ZipWrap* zip/*, std::vector<std::string>& log_buffer*/);
+
+#endif  // RECOVERY_INSTALL_COMMAND_H_
diff --git a/install/include/legacy_property_service.h b/install/include/legacy_property_service.h
new file mode 100644
index 0000000..d20bdef
--- /dev/null
+++ b/install/include/legacy_property_service.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LEGACY_PROPERTY_H
+#define _LEGACY_PROPERTY_H
+
+#include <stdbool.h>
+
+void legacy_get_property_workspace(int *fd, int *sz);
+int legacy_properties_init();
+
+#endif	/* _LEGACY_PROPERTY_H */
diff --git a/install/include/set_metadata.h b/install/include/set_metadata.h
new file mode 100644
index 0000000..9a46be9
--- /dev/null
+++ b/install/include/set_metadata.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 The Team Win Recovery Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * The purpose of these functions is to try to get and set the proper
+ * file permissions, SELinux contexts, owner, and group so that these
+ * files are accessible when we boot up to normal Android via MTP and to
+ * file manager apps. During early boot we try to read the contexts and
+ * owner / group info from /data/media or from /data/media/0 and store
+ * them in static variables. From there, we'll try to set the same
+ * contexts, owner, and group information on most files we create during
+ * operations like backups, copying the log, and MTP operations.
+ */
+
+#ifndef _RECOVERY_SET_CONTEXTS_H
+#define _RECOVERY_SET_CONTEXTS_H
+
+#include <sys/stat.h>
+#include "selinux/selinux.h"
+
+int tw_get_default_metadata(const char* filename);
+int tw_set_default_metadata(const char* filename);
+
+#endif //_RECOVERY_SET_CONTEXTS_H
diff --git a/install/include/tw_atomic.hpp b/install/include/tw_atomic.hpp
new file mode 100644
index 0000000..0f29f02
--- /dev/null
+++ b/install/include/tw_atomic.hpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 The Team Win Recovery Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _TWATOMIC_HPP_HEADER
+#define _TWATOMIC_HPP_HEADER
+
+#include <pthread.h>
+
+class TWAtomicInt
+{
+public:
+	TWAtomicInt(int initial_value = 0);
+	~TWAtomicInt();
+	void set_value(int new_value);
+	int get_value();
+
+private:
+	int value;
+	bool use_mutex;
+	pthread_mutex_t mutex_lock;
+};
+
+#endif //_TWATOMIC_HPP_HEADER
diff --git a/install/include/zipwrap.hpp b/install/include/zipwrap.hpp
new file mode 100755
index 0000000..7102116
--- /dev/null
+++ b/install/include/zipwrap.hpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) TeamWin
+ * This file is part of TWRP/TeamWin Recovery Project.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ZIPWRAP_HPP
+#define __ZIPWRAP_HPP
+
+#include <string>
+#ifdef USE_MINZIP
+#include "minzip/Zip.h"
+#include "minzip/SysUtil.h"
+#else
+#include <ziparchive/zip_archive.h>
+#include "otautil/sysutil.h"
+#endif
+
+using namespace std;
+
+class ZipWrap {
+	public:
+		ZipWrap();
+		~ZipWrap();
+
+		bool Open(const char* file, MemMapping* map);
+		void Close();
+		bool EntryExists(const string& filename);
+		bool ExtractEntry(const string& source_file, const string& target_file, mode_t mode);
+
+		long GetUncompressedSize(const string& filename);
+		bool ExtractToBuffer(const string& filename, uint8_t* begin);
+		bool ExtractRecursive(const string& source_dir, const string& target_dir);
+#ifdef USE_MINZIP
+		loff_t GetEntryOffset(const string& filename);
+#else
+		off64_t GetEntryOffset(const string& filename);
+		ZipArchiveHandle GetZipArchiveHandle();
+#endif
+
+	private:
+#ifdef USE_MINZIP
+		ZipArchive Zip;
+#else
+		ZipArchiveHandle Zip;
+#endif
+		string zip_file;
+		bool zip_open;
+};
+
+#endif //__ZIPWRAP_HPP