// 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.

package {
    default_team: "trendy_team_android_media_audio_framework",
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_av_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_av_license"],
}

//##################################################################################################
// Legacy tools for audio policy engine criterion type configuration file
//
python_binary_host {
    name: "buildPolicyCriterionTypes",
    main: "buildPolicyCriterionTypes.py",
    srcs: [
        "buildPolicyCriterionTypes.py",
    ],
}

genrule_defaults {
    name: "buildpolicycriteriontypesrule",
    tools: ["buildPolicyCriterionTypes"],
    cmd: "cp $(locations :audio_policy_configuration_files) $(genDir)/. && " +
        "cp $(location :audio_policy_configuration_top_file) $(genDir)/audio_policy_configuration.xml && " +
        "$(location buildPolicyCriterionTypes) " +
        " --androidaudiobaseheader $(location :libaudio_system_audio_base) " +
        " --androidaudiocommonbaseheader $(location :libaudio_system_audio_common_base) " +
        "--audiopolicyconfigurationfile $(genDir)/audio_policy_configuration.xml " +
        "--criteriontypes $(location :audio_policy_engine_criterion_types_template) " +
        "--outputfile $(out)",
    srcs: [
        // The commented inputs must be provided to use this genrule_defaults
        // @todo uncomment if 1428659 is merged":android_audio_base_header_file",
        ":audio_policy_engine_criterion_types_template",
        ":libaudio_system_audio_base",
        ":libaudio_system_audio_common_base",
        // ":audio_policy_configuration_top_file",
        // ":audio_policy_configuration_files",
    ],
    out: ["audio_policy_engine_criterion_types.xml"],
}

//##################################################################################################
// Tools for audio policy engine criterion type configuration file
//
python_binary_host {
    name: "capBuildPolicyCriterionTypes",
    main: "capBuildPolicyCriterionTypes.py",
    srcs: [
        "capBuildPolicyCriterionTypes.py",
    ],
}

genrule_defaults {
    name: "capbuildpolicycriteriontypesrule",
    tools: ["capBuildPolicyCriterionTypes"],
    cmd: "cp $(locations :audio_policy_configuration_files) $(genDir)/. && " +
        "cp $(location :audio_policy_configuration_top_file) $(genDir)/audio_policy_configuration.xml && " +
        "$(location capBuildPolicyCriterionTypes) " +
        " --androidaudiobaseheader $(location :libaudio_system_audio_base) " +
        " --androidaudiocommonbaseheader $(location :libaudio_system_audio_common_base) " +
        "--audiopolicyconfigurationfile $(genDir)/audio_policy_configuration.xml " +
        "--criteriontypes $(location :audio_policy_engine_aidl_criterion_types_template) " +
        "--outputfile $(out)",
    srcs: [
        // The commented inputs must be provided to use this genrule_defaults
        // @todo uncomment if 1428659 is merged":android_audio_base_header_file",
        ":audio_policy_engine_aidl_criterion_types_template",
        ":libaudio_system_audio_base",
        ":libaudio_system_audio_common_base",
        // ":audio_policy_configuration_top_file",
        // ":audio_policy_configuration_files",
    ],
    out: ["audio_policy_engine_criterion_types.xml"],
}

//##################################################################################################
// Tools for audio policy engine parameter framework configurable domains
//
python_binary_host {
    name: "domainGeneratorPolicy",
    main: "domainGeneratorPolicy.py",
    srcs: [
        "domainGeneratorPolicy.py",
    ],
    libs: [
        "EddParser.py",
        "PFWScriptGenerator.py",
        "hostConfig.py",
    ],
    required: [
        "domainGeneratorConnector",
    ],
}

genrule_defaults {
    name: "domaingeneratorpolicyrule",
    tools: [
        "domainGeneratorConnector",
        "domainGeneratorPolicy",
    ],
    cmd: "mkdir -p $(genDir)/Structure/Policy && " +
        "cp $(locations :audio_policy_pfw_structure_files) $(genDir)/Structure/Policy && " +
        "cp $(location :audio_policy_pfw_toplevel) $(genDir)/top_level && " +
        "sed -i -e 's|TuningAllowed=\"false\"|TuningAllowed=\"true\" ServerPort=\"unix:///dev/socket/audioserver/policy_debug\"|g' $(genDir)/top_level &&" +
        "$(location domainGeneratorPolicy) " +
        "--validate " +
        "--domain-generator-tool $(location domainGeneratorConnector) " +
        "--toplevel-config $(genDir)/top_level " +
        "--criteria $(location :audio_policy_engine_criteria) " +
        "--criteriontypes $(location :audio_policy_engine_criterion_types) " +
        "--add-edds $(locations :edd_files) " +
        "--schemas-dir external/parameter-framework/upstream/schemas " +
        " > $(out)",
    srcs: [
        // The commented inputs must be provided to use this genrule_defaults
        // ":audio_policy_pfw_toplevel",
        // ":audio_policy_pfw_structure_files",
        ":audio_policy_engine_criteria",
        // ":audio_policy_engine_criterion_types",
        // ":edd_files",
        ":parameter_frameworks_configuration_schemas",
    ],
    out: ["PolicyConfigurableDomains.xml"],
}

//##################################################################################################
// Legacy tools for policy parameter-framework product strategies structure file generation
//
python_binary_host {
    name: "buildStrategiesStructureFile",
    main: "buildStrategiesStructureFile.py",
    srcs: [
        "buildStrategiesStructureFile.py",
    ],
}

genrule_defaults {
    name: "buildstrategiesstructurerule",
    tools: ["buildStrategiesStructureFile"],
    cmd: "cp $(locations :audio_policy_engine_configuration_files) $(genDir) && ls -l $(genDir) &&" +
        "$(location buildStrategiesStructureFile) " +
        "--audiopolicyengineconfigurationfile $(genDir)/audio_policy_engine_configuration.xml " +
        "--productstrategiesstructurefile $(location :product_strategies_structure_template) " +
        "--outputfile $(out)",
    srcs: [
        // The commented inputs must be provided to use this genrule_defaults
        // ":audio_policy_engine_configuration_files",
        ":product_strategies_structure_template",
    ],
    out: ["ProductStrategies.xml"],
}

//##################################################################################################
// Tools for policy parameter-framework common type structure file generation
//
python_binary_host {
    name: "buildCommonTypesStructureFile",
    main: "buildCommonTypesStructureFile.py",
    srcs: [
        "buildCommonTypesStructureFile.py",
    ],
}

genrule_defaults {
    name: "buildcommontypesstructurerule",
    tools: ["buildCommonTypesStructureFile"],
    cmd: "$(location buildCommonTypesStructureFile) " +
        "--androidaudiobaseheader $(location :libaudio_system_audio_base) " +
        "--commontypesstructure $(location :common_types_structure_template) " +
        "--outputfile $(out)",
    srcs: [
        ":common_types_structure_template",
        ":libaudio_system_audio_base",
    ],
}
