1#
2# Copyright 2019 The Android Open-Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17import os
18
19from common import BlockDifference, EmptyImage, GetUserImage
20
21# The joint list of user image partitions of source and target builds.
22# - Items should be added to the list if new dynamic partitions are added.
23# - Items should not be removed from the list even if dynamic partitions are
24#   deleted. When generating an incremental OTA package, this script needs to
25#   know that an image is present in source build but not in target build.
26USERIMAGE_PARTITIONS = [
27    "odm",
28    "product",
29    "system_ext",
30]
31
32
33def GetUserImages(input_tmp, input_zip):
34  return {partition: GetUserImage(partition, input_tmp, input_zip)
35          for partition in USERIMAGE_PARTITIONS
36          if os.path.exists(os.path.join(input_tmp,
37                                         "IMAGES", partition + ".img"))}
38
39
40def FullOTA_GetBlockDifferences(info):
41  images = GetUserImages(info.input_tmp, info.input_zip)
42  return [BlockDifference(partition, image)
43          for partition, image in images.items()]
44
45
46def IncrementalOTA_GetBlockDifferences(info):
47  source_images = GetUserImages(info.source_tmp, info.source_zip)
48  target_images = GetUserImages(info.target_tmp, info.target_zip)
49
50  # Use EmptyImage() as a placeholder for partitions that will be deleted.
51  for partition in source_images:
52    target_images.setdefault(partition, EmptyImage())
53
54  # Use source_images.get() because new partitions are not in source_images.
55  return [BlockDifference(partition, target_image, source_images.get(partition))
56          for partition, target_image in target_images.items()]
57