Yifan Hong | c2c955e | 2019-04-11 14:45:36 -0700 | [diff] [blame] | 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 | |
| 17 | import os |
| 18 | |
| 19 | from 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. |
| 26 | USERIMAGE_PARTITIONS = [ |
Enrico Granata | 617305f | 2020-02-23 17:11:12 -0800 | [diff] [blame] | 27 | "odm", |
Yifan Hong | c2c955e | 2019-04-11 14:45:36 -0700 | [diff] [blame] | 28 | "product", |
Justin Yun | 3e008ba | 2019-07-25 15:03:55 +0900 | [diff] [blame] | 29 | "system_ext", |
Yifan Hong | c2c955e | 2019-04-11 14:45:36 -0700 | [diff] [blame] | 30 | ] |
| 31 | |
| 32 | |
| 33 | def 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 | |
| 40 | def 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 | |
| 46 | def 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()] |