# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# This file is included at the top of all native android mozconfigs
if [ -z "$NO_NDK" ]; then
  . "$topsrcdir/build/mozconfig.stylo"
fi

MOZ_AUTOMATION_L10N_CHECK=0
. "$topsrcdir/build/mozconfig.common"

# For Android builds in TaskCluster, the system image is Debian, and
# we use the Java JRE/JDK from the system.  We use a custom clang for
# the host compiler.
HOST_CC="$topsrcdir/clang/bin/clang"
HOST_CXX="$topsrcdir/clang/bin/clang++"

# Build Fennec
ac_add_options --enable-application=mobile/android
ac_add_options --with-android-sdk="$topsrcdir/android-sdk-linux"

ac_add_options --with-gradle="$topsrcdir/android-gradle-dependencies/gradle-dist/bin/gradle"
export GRADLE_MAVEN_REPOSITORIES="file://$topsrcdir/android-gradle-dependencies/google","file://$topsrcdir/android-gradle-dependencies/jcenter"

if [ -z "$NO_NDK" ]; then
    # We use our own clang instead of the NDK's clang.
    CC="$topsrcdir/clang/bin/clang"
    CXX="$topsrcdir/clang/bin/clang++"
    ac_add_options --with-android-ndk="$topsrcdir/android-ndk"
fi

ac_add_options --enable-update-channel=${MOZ_UPDATE_CHANNEL}

ac_add_options --with-google-api-keyfile=/builds/gapi.data
ac_add_options --with-mozilla-api-keyfile=/builds/mozilla-fennec-geoloc-api.key

ac_add_options --enable-marionette

# MOZ_INSTALL_TRACKING does not guarantee MOZ_UPDATE_CHANNEL will be set so we
# provide a default state. Currently, the default state provides a default
# keyfile because an assertion will be thrown if MOZ_INSTALL_TRACKING is
# specified but a keyfile is not. This assertion can catch if we misconfigure a
# release or beta build and it does not have a valid keyfile.
#
# However, by providing a default keyfile, if we misconfigure beta or release,
# the default keyfile may be used instead and the assertion won't catch the
# error.  Therefore, it would be ideal to have MOZ_INSTALL_TRACKING guarantee
# MOZ_UPDATE_CHANNEL was set so we can remove the default case. This may occur
# when release promotion is implemented on Android.
#
# In all cases, we don't upload Adjust pings in automation.
if test "$MOZ_UPDATE_CHANNEL" = "release" ; then
    ac_add_options --with-adjust-sdk-keyfile=/builds/adjust-sdk.token
elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
    ac_add_options --with-adjust-sdk-keyfile=/builds/adjust-sdk-beta.token
else
    ac_add_options --with-adjust-sdk-keyfile="$topsrcdir/mobile/android/base/adjust-sdk-sandbox.token"
fi

# MOZ_ANDROID_MMA depends on --with-leanplum-sdk-keyfile, and there's no default
# keyfile set, so if we misconfigure beta or release, the builds will fail (at
# configure time).
if test "$MOZ_UPDATE_CHANNEL" = "release" ; then
    ac_add_options --with-leanplum-sdk-keyfile=/builds/leanplum-sdk-release.token
elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
    ac_add_options --with-leanplum-sdk-keyfile=/builds/leanplum-sdk-beta.token
elif test "$MOZ_UPDATE_CHANNEL" = "nightly" ; then
    ac_add_options --with-leanplum-sdk-keyfile=/builds/leanplum-sdk-nightly.token
else
    ac_add_options --with-leanplum-sdk-keyfile="$topsrcdir/mobile/android/base/leanplum-sdk-sandbox.token"
fi

# MOZ_ANDROID_POCKET depends on --with-pocket-api-keyfile, and will
# fail if MOZ_ANDROID_POCKET is specified but a keyfile is not. There's no default
# keyfile set, so if we misconfigure beta or release or nightly, the builds will
# fail (at configure time).
# Otherwise, Pocket is not a critical component so it can be built with a dummy key.
if test "$MOZ_UPDATE_CHANNEL" = "release" ; then
    ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-release.token
elif test "$MOZ_UPDATE_CHANNEL" = "beta" ; then
    ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-beta.token
elif test "$MOZ_UPDATE_CHANNEL" = "nightly" ; then
    ac_add_options --with-pocket-api-keyfile=/builds/pocket-api-nightly.token
else
    ac_add_options --with-pocket-api-keyfile="$topsrcdir/mobile/android/base/pocket-api-sandbox.token"
fi

# Package js shell.
export MOZ_PACKAGE_JSSHELL=1

. "$topsrcdir/build/unix/mozconfig.stdcxx"

JS_BINARY="$topsrcdir/mobile/android/config/js_wrapper.sh"
