/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// If you change this file,
// Please update ota_metadata_pb2.py by executing
// protoc ota_metadata.proto --python_out $ANDROID_BUILD_TOP/build/tools/releasetools


syntax = "proto3";

package build.tools.releasetools;
option optimize_for = LITE_RUNTIME;

// The build information of a particular partition on the device.
message PartitionState {
  string partition_name = 1;
  repeated string device = 2;
  repeated string build = 3;
  // The version string of the partition. It's usually timestamp if present.
  // One known exception is the boot image, who uses the kmi version, e.g.
  // 5.4.42-android12-0
  string version = 4;

  // TODO(xunchang), revisit other necessary fields, e.g. security_patch_level.
}

// The build information on the device. The bytes of the running images are thus
// inferred from the device state. For more information of the meaning of each
// subfield, check
// https://source.android.com/compatibility/android-cdd#3_2_2_build_parameters
message DeviceState {
  // device name. i.e. ro.product.device; if the field has multiple values, it
  // means the ota package supports multiple devices. This usually happens when
  // we use the same image to support multiple skus.
  repeated string device = 1;
  // device fingerprint. Up to R build, the value reads from
  // ro.build.fingerprint.
  repeated string build = 2;
  // A value that specify a version of the android build.
  string build_incremental = 3;
  // The timestamp when the build is generated.
  int64 timestamp = 4;
  // The version of the currently-executing Android system.
  string sdk_level = 5;
  // A value indicating the security patch level of a build.
  string security_patch_level = 6;

  // The detailed state of each partition. For partial updates or devices with
  // mixed build of partitions, some of the above fields may left empty. And the
  // client will rely on the information of specific partitions to target the
  // update.
  repeated PartitionState partition_state = 7;
}

// The metadata of an OTA package. It contains the information of the package
// and prerequisite to install the update correctly.
message OtaMetadata {
  enum OtaType {
    UNKNOWN = 0;
    AB = 1;
    BLOCK = 2;
    BRICK = 3;
  };
  OtaType type = 1;
  // True if we need to wipe after the update.
  bool wipe = 2;
  // True if the timestamp of the post build is older than the pre build.
  bool downgrade = 3;
  // A map of name:content of property files, e.g. ota-property-files.
  map<string, string> property_files = 4;

  // The required device state in order to install the package.
  DeviceState precondition = 5;
  // The expected device state after the update.
  DeviceState postcondition = 6;

  // True if the ota that updates a device to support dynamic partitions, where
  // the source build doesn't support it.
  bool retrofit_dynamic_partitions = 7;
  // The required size of the cache partition, only valid for non-A/B update.
  int64 required_cache = 8;
}
