commands: conserve write cycles

When a record or a binary file is written the card goes throth a full
flash/eeprom write cycle at this location, even when the data does not
change. This can be optimized by reading before writing in order to
compere if the data we are about to write is actually different.

Change-Id: Ifd1b80d3ede15a7caa29077a37ac7cf58c9053f1
Related: OS#4963
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index cd08699..e959c52 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -566,6 +566,7 @@
             self.mf.add_application(a)
         for f in self.profile.files_in_mf:
             self.mf.add_file(f)
+        self.conserve_write = True
 
     def _match_applications(self):
         """match the applications from the profile with applications on the card"""
@@ -699,7 +700,7 @@
     def update_binary(self, data_hex, offset=0):
         if not isinstance(self.selected_file, TransparentEF):
             raise TypeError("Only works with TransparentEF")
-        return self.card._scc.update_binary(self.selected_file.fid, data_hex, offset)
+        return self.card._scc.update_binary(self.selected_file.fid, data_hex, offset, conserve=self.conserve_write)
 
     def update_binary_dec(self, data):
         data_hex = self.selected_file.encode_hex(data)
@@ -719,7 +720,7 @@
     def update_record(self, rec_nr, data_hex):
         if not isinstance(self.selected_file, LinFixedEF):
             raise TypeError("Only works with Linear Fixed EF")
-        return self.card._scc.update_record(self.selected_file.fid, rec_nr, data_hex)
+        return self.card._scc.update_record(self.selected_file.fid, rec_nr, data_hex, conserve=self.conserve_write)
 
     def update_record_dec(self, rec_nr, data):
         hex_data = self.selected_file.encode_record_hex(data)