// Copyright (C) 2018 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.

// [START declaration]
syntax = "proto3";
package com_android_cts_releaseparser;
// [END declaration]

// [START java_declaration]
option java_package = "com.android.cts.releaseparser";
option java_outer_classname = "ReleaseProto";
// [END java_declaration]

// [START messages]
message Option {
    string name = 1;
    string key = 2;
    string value =3;
}

message TestModuleConfig {
    string module_name = 1;
    string component = 2;
    string description = 3;
    repeated Option options = 4;

    message TargetPreparer {
        string test_class = 1;
        repeated Option options = 2;
    }
    repeated TargetPreparer target_preparers = 5;
    repeated string test_file_names = 6;

    message TestClass {
        string test_class = 1;
        string package = 2;
        repeated Option options = 3;
    }
    repeated TestClass test_classes = 7;
    repeated string test_jars = 8;
}

message Element {
    string name = 1;
    string value = 2;
}

message ApiAnnotation {
    int32 visibility = 1;
    string type = 2;

    repeated Element elements = 3;
}

message ApiField {
    string defining_class = 1;
    string name = 2;
    string type = 3;
    int32 access_flags = 4;
    string initial_value = 5;
    repeated ApiAnnotation annotations = 6;
    string value = 7;
}

message ApiMethod {
    string defining_class = 1;
    string name = 2;
    repeated string parameters = 3;
    string return_type = 4;
    int32 access_flags = 5;
    string known_failure_filter = 6;
    repeated ApiAnnotation annotations = 7;
}

message ApiClass {
    string name = 1;
    string type = 2;
    string super_class = 3;
    repeated string interfaces = 4;
    TestClassType test_class_type = 5;
    int32 access_flags = 6;
    repeated ApiAnnotation annotations = 7;
    repeated ApiMethod methods = 8;
    repeated ApiField fields = 9;
}

message ApiPackage {
    string name = 1;
    string package_file = 2;
    string content_id = 3;
    string op_codes = 4;

    repeated ApiClass classes = 5;
    string error = 6;
}

enum TestClassType {
    UNKNOWN = 0;
    JUNIT3 = 1;
    JUNIT4 = 2;
    PARAMETERIZED = 3;
    JAVAHOST = 4;
}

message TestSuite {
    string name = 1;
    // Version
    string version = 2;
    // Build Number
    string build_number = 3;
    // Content ID
    string content_id = 4;

    enum TestType {
        UNKNOWN = 0;
        ANDROIDJUNIT = 1;
        JAVAHOST = 2;
        GTEST = 3;
        LIBCORE = 4;
        DALVIK = 5;
        DEQP = 6;
    }

    message Module {
        string name = 1;
        string config_file = 2;
        TestType test_type = 3;
        string test_class = 4;
        repeated ApiPackage packages = 5;
    }
    repeated Module modules = 5;
}

message Service {
    string name = 1;
    string file = 2;
    repeated string arguments = 3;
    string clazz = 4;
    string user = 5;
    string group = 6;
    string writepid = 7;
    repeated string options = 8;
}

message Api {
    string name = 1;
    string version = 2;
    // map of Package Name & Package Message
    map<string, ApiPackage> packages = 3;
}

message UsesFeature {
    string name = 1;
    string required = 2;
}

message UsesLibrary {
    string name = 1;
    string required = 2;
}

message AppInfo {
    string package_name = 1;
    string version_code = 2;
    string version_name = 3;
    string sdk_version = 4;
    string target_sdk_version = 5;
    repeated UsesFeature uses_features = 6;
    repeated UsesLibrary uses_libraries = 7;
    repeated string native_code = 8;
    repeated string uses_permissions = 9;
    repeated string activities = 10;
    repeated string services = 11;
    repeated string providers = 12;
    map<string, string> properties = 13;
    repeated ApiPackage external_api_packages = 14;
    repeated ApiPackage internal_api_packages = 15;
    PackageFileContent package_file_content = 16;
    string package_signature = 17;
}

message ImageSection {
    uint32 offset = 1;
    uint32 size = 2;
}

// art/runtime/image.h
message ArtInfo {
    bool valid = 1;
    // skip magic_[4]
    string version = 2;
    uint32 image_begin = 3;
    uint32 image_size = 4;
    uint32 oat_checksum = 5;
    uint32 oat_file_begin = 6;
    uint32 oat_data_begin = 7;
    uint32 oat_data_end = 8;
    uint32 oat_file_end = 9;

    // app image headers only
    uint32 boot_image_begin = 10;
    uint32 boot_image_size = 11;
    uint32 boot_oat_begin = 12;
    uint32 boot_oat_size = 13;

    int32 patch_delta = 14;
    uint32 image_roots = 15;
    uint32 pointer_size = 16;
    uint32 compile_pic = 17;
    uint32 is_pic = 18;

    repeated ImageSection image_sections = 19;
    repeated uint64 image_methods = 20;

    uint32 storage_mode = 21;
    uint32 data_size = 22;
}

// art/dex2oat/linker/oat_writer.cc OatDexFile
message OatDexInfo {
    string dex_file_location_data = 1;
    // The checksum of the dex file.
    uint32 dex_file_location_checksum = 2;
    // Offset of the dex file in the vdex file.
    uint32 dex_file_offset = 3;
    // The lookup table offset in the oat file. Set in WriteTypeLookupTables.
    uint32 lookup_table_offset = 4;
    // Class and BSS offsets set in PrepareLayout.
    uint32 class_offsets_offset = 5;
    uint32 method_bss_mapping_offset = 6;
    uint32 type_bss_mapping_offset = 7;
    uint32 string_bss_mapping_offset = 8;
    // Offset of dex sections that will have different runtime madvise states.
    uint32 dex_sections_layout_offset = 9;
}

// art/runtime/oat.h
message OatInfo {
    // skip magic_[4]
    string version = 1;
    uint32 adler32_checksum = 2;
    // art/libartbase/arch/instruction_set.h

    uint32 instruction_set = 3;
    uint32 instruction_set_features_bitmap = 4;
    uint32 dex_file_count = 5;
    uint32 oat_dex_files_offset = 6;
    uint32 executable_offset = 7;
    uint32 interpreter_to_interpreter_bridge_offset = 8;
    uint32 interpreter_to_compiled_code_bridge_offset = 9;
    uint32 jni_dlsym_lookup_offset = 10;
    uint32 quick_generic_jni_trampoline_offset = 11;
    uint32 quick_imt_conflict_trampoline_offset = 12;
    uint32 quick_resolution_trampoline_offset = 13;
    uint32 quick_to_interpreter_bridge_offset = 14;

    // for backward compatibility, removed from version 162, see aosp/e0669326c0282b5b645aba75160425eef9d57617
    uint32 image_patch_delta = 15;

    uint32 image_file_location_oat_checksum = 16;
    // for backward compatibility, removed from version 162, see aosp/e0669326c0282b5b645aba75160425eef9d57617
    uint32 image_file_location_oat_data_begin = 17;

    uint32 key_value_store_size = 18;

    // int8_t key_value_store_[0];
    map<string, string> key_value_store = 19;
    repeated OatDexInfo oat_dex_info = 20;
    bool valid = 21;
    int32 bits = 22;
    string architecture = 23;
}

message DexSectionHeader {
    uint32 dex_size = 1;
    uint32 dex_shared_data_size = 2;
    uint32 quickening_info_size = 3;
}

// art/runtime/vdex_file.h
message VdexInfo {
    bool valid = 1;

    // skip magic_[4]
    string verifier_deps_version = 2;
    string dex_section_version = 3;
    uint32 number_of_dex_files = 4;
    uint32 verifier_deps_size = 5;
    repeated uint32 checksums = 6;
    repeated DexSectionHeader dex_section_headers = 7;
}

message Permission {
    string name = 1;
    repeated Element elements = 2;
}

message PermissionList {
    string name = 1;
    repeated Permission permissions = 2;
}

message PackageFileContent {
    map<string, Entry> entries = 1;
}

// An entry in a release
message Entry {
    // Name
    string name = 1;

    enum EntryType {
        FOLDER = 0;
        FILE = 1;
        TEST_MODULE_CONFIG = 2;
        JAR = 3;
        APK = 4;
        EXE = 5;
        SO = 6;
        OAT = 7;
        ODEX = 8;
        VDEX = 9;
        TEST_SUITE_TRADEFED = 10;
        BUILD_PROP = 11;
        SYMBOLIC_LINK = 12;
        RC = 13;
        ART = 14;
        XML = 15;
        IMG = 16;
    }
    // Type
    EntryType type = 2;

    // Size
    int64 size = 3;
    // Content ID
    string content_id = 4;
    // code_id
    string code_id = 5;
    // Parent folder
    string abi_architecture = 6;
    int32 abi_bits = 7;
    string parent_folder = 8;
    // Relative path
    string relative_path = 9;

    repeated string dependencies = 10;
    repeated string dynamic_loading_dependencies = 11;

    // file type specified info
    AppInfo app_info = 12;
    ArtInfo art_info = 13;
    OatInfo oat_info = 14;
    VdexInfo vdex_info = 15;
    // TestModule.config message
    TestModuleConfig test_module_config = 16;
    // Native services
    repeated Service services = 17;
    // Device permissions
    map<string, PermissionList> device_permissions = 18;
    // property map(key,value)
    map<string, string> properties = 19;
}

enum ReleaseType {
    DEVICE_BUILD = 0;
    TEST_SUITE = 1;
    APP_DISTRIBUTION_PACKAGE = 2;
}

message ReleaseContent {
    // Name
    string name = 1;
    // Version
    string version = 2;
    // Build Number
    string build_number = 3;
    // Full name
    string fullname = 4;
    // release uid e.g. Build Fingerprint
    string release_id = 5;
    // Content id
    string content_id = 6;
    // Size in byte
    int64 size = 7;
    ReleaseType release_type = 8;
    // property map(key,value)
    map<string, string> properties = 9;
    // File Entry map(relative_path, entry)
    map<string, Entry> entries = 10;

    // Test Suite specific
    string test_suite_tradefed = 11;
    string target_arch = 12;
    repeated string known_failures = 13;
}
// [END messages]