// Copyright (C) 2024 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_applicable_licenses: ["Android-Apache-2.0"],
}

apex_key {
    name: "com.android.uprobestats.key",
    public_key: "com.android.uprobestats.avbpubkey",
    private_key: "com.android.uprobestats.pem",
}

android_app_certificate {
    name: "com.android.uprobestats.certificate",
    certificate: "com.android.uprobestats",
}

prebuilt_etc {
    name: "com.android.uprobestats.init.rc",
    src: "UprobeStats-mainline.rc",
    filename: "init.rc",
    installable: false,
}

apex {
    // This apex will be enabled using release_uprobestats_module flag
    enabled: select(release_flag("RELEASE_UPROBESTATS_MODULE"), {
        true: true,
        false: false,
    }),

    name: "com.android.uprobestats",
    binaries: select(release_flag("RELEASE_UPROBESTATS_RUST"), {
        true: [
            "uprobestats_rs",
            "uprobestatsbpfload",
        ],
        false: [
            "uprobestats",
            "uprobestatsbpfload",
        ],
    }),

    prebuilts: [
        "com.android.uprobestats.init.rc",
    ],

    bpfs: [
        "BitmapAllocation.o",
        "GenericInstrumentation.o",
        "ProcessManagement.o",
        "DisruptiveApp.o",
        "Binder.o",
    ],

    native_shared_libs: [
        "libuprobestats_client",
    ],
    manifest: "manifest.json",
    file_contexts: ":com.android.uprobestats-file_contexts",
    key: "com.android.uprobestats.key",
    certificate: ":com.android.uprobestats.certificate",
    defaults: ["b-launched-apex-module"],
    licenses: [
        "Android-Apache-2.0",
        "opensourcerequest",
    ],
    systemserverclasspath_fragments: select(release_flag("RELEASE_UPROBESTATS_SERVICE"), {
        true: ["com.android.uprobestats-systemserverclasspath-fragment"],
        false: [],
    }),
}

systemserverclasspath_fragment {
    enabled: select(release_flag("RELEASE_UPROBESTATS_SERVICE"), {
        true: true,
        false: false,
    }),
    name: "com.android.uprobestats-systemserverclasspath-fragment",
    standalone_contents: ["service-uprobestats"],
    apex_available: ["com.android.uprobestats"],
}
