buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath GRADLE_CLASS_PATH
        classpath PROTOBUF_CLASS_PATH
    }
}

final String FRAMEWORK_PREBUILTS_DIR = "prebuilts"

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion COMPILE_SDK
    buildToolsVersion BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        debug {
            minifyEnabled false
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard.flags'
        }
    }

    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    // The flavor dimensions for build variants (e.g. aospWithQuickstep, aospWithoutQuickstep)
    // See: https://developer.android.com/studio/build/build-variants#flavor-dimensions
    flavorDimensions "app", "recents"

    productFlavors {
        aosp {
            dimension "app"
            applicationId 'com.android.launcher3'
            testApplicationId 'com.android.launcher3.tests'
        }

        l3go {
            dimension "app"
            applicationId 'com.android.launcher3'
            testApplicationId 'com.android.launcher3.tests'
        }

        withQuickstep {
            dimension "recents"

            minSdkVersion 28
        }

        withQuickstepIconRecents {
            dimension "recents"

            minSdkVersion 28
        }

        withoutQuickstep {
            dimension "recents"
        }
    }

    android.variantFilter { variant ->
        // Icon recents is Go only
        if (name.contains("WithQuickstepIconRecents") && !name.contains("l3go")) {
            variant.setIgnore(true)
        }
    }

    sourceSets {
        main {
            res.srcDirs = ['res']
            java.srcDirs = ['src', 'src_plugins']
            manifest.srcFile 'AndroidManifest-common.xml'
            proto {
                srcDir 'protos/'
                srcDir 'proto_overrides/'
            }
        }

        debug {
            manifest.srcFile "AndroidManifest.xml"
        }

        release {
            manifest.srcFile "AndroidManifest.xml"
        }

        androidTest {
            res.srcDirs = ['tests/res']
            java.srcDirs = ['tests/src', 'tests/tapl']
            manifest.srcFile "tests/AndroidManifest-common.xml"
        }

        androidTestDebug {
            manifest.srcFile "tests/AndroidManifest.xml"
        }

        aosp {
            java.srcDirs = ['src_flags', 'src_shortcuts_overrides']
            manifest.srcFile "AndroidManifest.xml"
        }

        l3go {
            res.srcDirs = ['go/res']
            java.srcDirs = ['go/src']
            manifest.srcFile "go/AndroidManifest.xml"
        }

        withoutQuickstep {
            java.srcDirs = ['src_ui_overrides']
        }

        withQuickstep {
            res.srcDirs = ['quickstep/res', 'quickstep/recents_ui_overrides/res']
            java.srcDirs = ['quickstep/src', 'quickstep/recents_ui_overrides/src']
            manifest.srcFile "quickstep/AndroidManifest.xml"
        }

        withQuickstepIconRecents {
            res.srcDirs = ['quickstep/res', 'go/quickstep/res']
            java.srcDirs = ['quickstep/src', 'go/quickstep/src']
            manifest.srcFile "quickstep/AndroidManifest.xml"
        }
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs.add("-Xbootclasspath/p:${FRAMEWORK_PREBUILTS_DIR}/libs/framework.jar")
        }
    }
}

dependencies {
    implementation "androidx.dynamicanimation:dynamicanimation:${ANDROID_X_VERSION}"
    implementation "androidx.recyclerview:recyclerview:${ANDROID_X_VERSION}"
    implementation "androidx.preference:preference:${ANDROID_X_VERSION}"
    implementation project(':IconLoader')
    implementation fileTree(dir: "${FRAMEWORK_PREBUILTS_DIR}/libs", include: 'launcher_protos.jar')

    // Recents lib dependency
    withQuickstepImplementation fileTree(dir: "${FRAMEWORK_PREBUILTS_DIR}/quickstep/libs", include: 'sysui_shared.jar')

    // Recents lib dependency for Go
    withQuickstepIconRecentsImplementation fileTree(dir: "${FRAMEWORK_PREBUILTS_DIR}/quickstep/libs", include: 'sysui_shared.jar')

    // Required for AOSP to compile. This is already included in the sysui_shared.jar
    withoutQuickstepImplementation fileTree(dir: "${FRAMEWORK_PREBUILTS_DIR}/libs", include: 'plugin_core.jar')

    testImplementation 'junit:junit:4.12'
    androidTestImplementation "org.mockito:mockito-core:1.9.5"
    androidTestImplementation 'com.google.dexmaker:dexmaker:1.2'
    androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.0'
    androidTestImplementation 'com.android.support.test:rules:1.0.0'
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    androidTestImplementation "androidx.annotation:annotation:${ANDROID_X_VERSION}"
}

protobuf {
    // Configure the protoc executable
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'

        generateProtoTasks {
            all().each { task ->
                task.builtins {
                    remove java
                    javanano {
                        option "java_package=launcher_log_extension.proto|com.android.launcher3.userevent.nano"
                        option "java_package=launcher_log.proto|com.android.launcher3.userevent.nano"
                        option "java_package=launcher_dump.proto|com.android.launcher3.model.nano"
                        option "enum_style=java"
                    }
                }
            }
        }
    }
}

apply from: 'shade/shade.gradle'
