Skip identical SOURCE_COPY operations

When Virtual A/B devices are updated, SOURCE_COPY operations that are
copying data from source to destination at the same locations:
- are useless;
- introduce an overhead for overwritingin identical data;
- increase the COW device size when using dm-snapshot.
This patch analyzes SOURCE_COPY operations and skips them if applied to
Virtual A/B devices and source and destination addresses are identical.

Bug: 141207436
Test: DynamicPartitionControlAndroidTest:ShouldSkipOperationTest
Depends-On: I146aeba1c8ede35f21cfef8e21d4af62274bda84
Change-Id: Ifec33abaf81b1d4cbd61533293735de68578c9c4
Signed-off-by: Alessio Balsini <balsini@google.com>
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index c24aee9..4414e4b 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -50,6 +50,7 @@
 using android::fs_mgr::Partition;
 using android::fs_mgr::PartitionOpener;
 using android::fs_mgr::SlotSuffixForSlotNumber;
+using android::snapshot::SourceCopyOperationIsClone;
 
 namespace chromeos_update_engine {
 
@@ -106,6 +107,15 @@
 
 bool DynamicPartitionControlAndroid::ShouldSkipOperation(
     const InstallOperation& operation) {
+  switch (operation.type()) {
+    case InstallOperation::SOURCE_COPY:
+      return target_supports_snapshot_ &&
+             GetVirtualAbFeatureFlag().IsEnabled() &&
+             SourceCopyOperationIsClone(operation);
+      break;
+    default:
+      break;
+  }
   return false;
 }