Fix bpttool bug that prevents disabling A/B through stacking am: 99d3ca5673
am: a230e6a66c

Change-Id: I020159b3156cee2cb4f73e9790188c5044856662
diff --git a/bpt_unittest.py b/bpt_unittest.py
index cc1d925..7a53e58 100755
--- a/bpt_unittest.py
+++ b/bpt_unittest.py
@@ -346,6 +346,12 @@
                     'test/expected_json_stacked_change_flags.bpt',
                     disk_size=bpttool.ParseSize('10 GiB'))
 
+  def testStackedDisableAB(self):
+    """Checks that we can change disable A/B on partitions through stacking."""
+    self._MakeTable(['test/base.bpt', 'test/disable_ab.bpt'],
+                    'test/expected_json_stacked_disable_ab.bpt',
+                    disk_size=bpttool.ParseSize('10 GiB'))
+
   def testStackedNewPartitionOnTop(self):
     """Checks that we can add a new partition only given the output JSON.
 
diff --git a/bpttool b/bpttool
index 7b78e3d..cd7f4c7 100755
--- a/bpttool
+++ b/bpttool
@@ -258,36 +258,36 @@
     """
     self.label = pobj[JSON_KEYWORD_PARTITIONS_LABEL]
     value = pobj.get(JSON_KEYWORD_PARTITIONS_OFFSET)
-    if value:
+    if value is not None:
       self.offset = ParseSize(value)
     value = pobj.get(JSON_KEYWORD_PARTITIONS_SIZE)
-    if value:
+    if value is not None:
       self.size = ParseSize(value)
     value = pobj.get(JSON_KEYWORD_PARTITIONS_GROW)
-    if value:
-      self.grow = True
+    if value is not None:
+      self.grow = value
     value = pobj.get(JSON_KEYWORD_PARTITIONS_AB)
-    if value:
+    if value is not None:
       self.ab = value
     value = pobj.get(JSON_KEYWORD_PARTITIONS_AB_EXPANDED)
-    if value:
+    if value is not None:
       self.ab_expanded = value
     value = pobj.get(JSON_KEYWORD_PARTITIONS_GUID)
-    if value:
+    if value is not None:
       self.guid = value
     value = pobj.get(JSON_KEYWORD_PARTITIONS_IGNORE)
-    if value:
+    if value is not None:
       self.ignore = value
     value = pobj.get(JSON_KEYWORD_PARTITIONS_TYPE_GUID)
-    if value:
+    if value is not None:
       self.type_guid = str.lower(str(value))
       if self.type_guid in KNOWN_TYPE_GUIDS:
         self.type_guid = KNOWN_TYPE_GUIDS[self.type_guid]
     value = pobj.get(JSON_KEYWORD_PARTITIONS_FLAGS)
-    if value:
+    if value is not None:
       self.flags = ParseNumber(value)
     value = pobj.get(JSON_KEYWORD_PARTITIONS_POSITION)
-    if value:
+    if value is not None:
       self.position = ParseNumber(value)
 
   def expand_guid(self, guid_generator, partition_number):
diff --git a/test/disable_ab.bpt b/test/disable_ab.bpt
new file mode 100644
index 0000000..eb1d97e
--- /dev/null
+++ b/test/disable_ab.bpt
@@ -0,0 +1,16 @@
+{
+    "partitions": [
+        {
+            "ab": false,
+            "label": "boot"
+        },
+        {
+            "ab": false,
+            "label": "system"
+        },
+        {
+            "ab": false,
+            "label": "odm"
+        }
+    ]
+}
diff --git a/test/expected_json_stacked_disable_ab.bpt b/test/expected_json_stacked_disable_ab.bpt
new file mode 100644
index 0000000..e980b36
--- /dev/null
+++ b/test/expected_json_stacked_disable_ab.bpt
@@ -0,0 +1,62 @@
+{
+  "settings": {
+    "ab_suffixes": ["_a", "_b"],
+    "disk_size": 10737418240,
+    "disk_alignment": 4096,
+    "disk_guid": "01234567-89ab-cdef-0123-000000000000"
+  },
+  "partitions": [
+    {
+      "label": "boot",
+      "offset": 20480,
+      "size": 33554432,
+      "grow": false,
+      "guid": "01234567-89ab-cdef-0123-000000000001",
+      "type_guid": "bb499290-b57e-49f6-bf41-190386693794",
+      "flags": "0x0000000000000000",
+      "ignore": false,
+      "ab": false,
+      "ab_expanded": false,
+      "position": 0
+    },
+    {
+      "label": "system",
+      "offset": 33574912,
+      "size": 536870912,
+      "grow": false,
+      "guid": "01234567-89ab-cdef-0123-000000000002",
+      "type_guid": "0f2778c4-5cc1-4300-8670-6c88b7e57ed6",
+      "flags": "0x0000000000000000",
+      "ignore": false,
+      "ab": false,
+      "ab_expanded": false,
+      "position": 0
+    },
+    {
+      "label": "odm",
+      "offset": 570445824,
+      "size": 1073741824,
+      "grow": false,
+      "guid": "01234567-89ab-cdef-0123-000000000003",
+      "type_guid": "e99d84d7-2c1b-44cf-8c58-effae2dc2558",
+      "flags": "0x0000000000000000",
+      "ignore": false,
+      "ab": false,
+      "ab_expanded": false,
+      "position": 0
+    },
+    {
+      "label": "userdata",
+      "offset": 1644187648,
+      "size": 9093210112,
+      "grow": true,
+      "guid": "01234567-89ab-cdef-0123-000000000004",
+      "type_guid": "0bb7e6ed-4424-49c0-9372-7fbab465ab4c",
+      "flags": "0x0000000000000000",
+      "ignore": false,
+      "ab": false,
+      "ab_expanded": false,
+      "position": 0
+    }
+  ]
+}