Skip to content

Commit

Permalink
Fixes #675: Integrate Adjust SDK (for Greenfield flavor)
Browse files Browse the repository at this point in the history
  • Loading branch information
colintheshots committed Mar 1, 2019
1 parent c4fe445 commit b9aee25
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 33 deletions.
1 change: 1 addition & 0 deletions .adjust_token
@@ -0,0 +1 @@
--
95 changes: 64 additions & 31 deletions app/build.gradle
Expand Up @@ -106,19 +106,26 @@ android {
}

android.applicationVariants.all { variant ->

// -------------------------------------------------------------------------------------------------
// Set up kotlin-allopen plugin for writing tests
// -------------------------------------------------------------------------------------------------

boolean hasTest = gradle.startParameter.taskNames.find {it.contains("test") || it.contains("Test")} != null
if (hasTest) {
apply plugin: 'kotlin-allopen'
allOpen {
annotation("org.mozilla.fenix.test.Mockable")
}
}
}

android.applicationVariants.all { variant ->
// -------------------------------------------------------------------------------------------------
// Generate version codes for builds
// -------------------------------------------------------------------------------------------------

def buildType = variant.buildType.name

if (buildType == "release" || buildType == "nightly") {
if (buildType == "release") {
def versionCode = generatedVersionCode

// The Google Play Store does not allow multiple APKs for the same app that all have the
Expand All @@ -144,6 +151,57 @@ android.applicationVariants.all { variant ->
println("Build type: " + buildType)
println("Flavor: " + variant.flavorName)
println("Version code: " + variant.mergedFlavor.versionCode)

// -------------------------------------------------------------------------------------------------
// BuildConfig: Set variables for Sentry, Crash Reporting, and Telemetry
// -------------------------------------------------------------------------------------------------

// Reading sentry token from local file (if it exists). In a release task on taskcluster it will be available.
try {
def token = new File("${rootDir}/.sentry_token").text.trim()
buildConfigField 'String', 'SENTRY_TOKEN', '"' + token + '"'
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'SENTRY_TOKEN', 'null'
}

// Activating crash reporting only if command line parameter was provided (in automation)
if (project.hasProperty("crashReports") && project.property("crashReports") == "true") {
buildConfigField 'boolean', 'CRASH_REPORTING', 'true'
} else {
buildConfigField 'boolean', 'CRASH_REPORTING', 'false'
}

// Activating telemetry only if command line parameter was provided (in automation)
if (project.hasProperty("telemetry") && project.property("telemetry") == "true") {
buildConfigField 'boolean', 'TELEMETRY', 'true'
} else {
buildConfigField 'boolean', 'TELEMETRY', 'false'
}

def buildDate = Config.generateBuildDate()
buildConfigField 'String', 'BUILD_DATE', '"' + buildDate + '"'

// -------------------------------------------------------------------------------------------------
// Adjust: Read token from locale file if it exists (Only release builds)
// -------------------------------------------------------------------------------------------------

def variantName = variant.getName()

print("Adjust token: ")

if (variantName.contains("Release")) {
try {
def token = new File("${rootDir}/.adjust_token").text.trim()
buildConfigField 'String', 'ADJUST_TOKEN', '"' + token + '"'
println "(Added from .adjust_token file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'ADJUST_TOKEN', 'null'
println("X_X")
}
} else {
buildConfigField 'String', 'ADJUST_TOKEN', 'null'
println("--")
}
}

androidExtensions {
Expand Down Expand Up @@ -219,6 +277,9 @@ dependencies {

implementation Deps.autodispose

implementation Deps.adjust
implementation Deps.installreferrer // Required by Adjust

androidTestImplementation Deps.tools_test_runner
androidTestImplementation Deps.tools_espresso_core

Expand All @@ -234,34 +295,6 @@ dependencies {
annotationProcessor Deps.glideAnnotationProcessor
}


android.applicationVariants.all { variant ->
// Reading sentry token from local file (if it exists). In a release task on taskcluster it will be available.
try {
def token = new File("${rootDir}/.sentry_token").text.trim()
buildConfigField 'String', 'SENTRY_TOKEN', '"' + token + '"'
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'SENTRY_TOKEN', 'null'
}

// Activating crash reporting only if command line parameter was provided (in automation)
if (project.hasProperty("crashReports") && project.property("crashReports") == "true") {
buildConfigField 'boolean', 'CRASH_REPORTING', 'true'
} else {
buildConfigField 'boolean', 'CRASH_REPORTING', 'false'
}

// Activating telemetry only if command line parameter was provided (in automation)
if (project.hasProperty("telemetry") && project.property("telemetry") == "true") {
buildConfigField 'boolean', 'TELEMETRY', 'true'
} else {
buildConfigField 'boolean', 'TELEMETRY', 'false'
}

def buildDate = Config.generateBuildDate()
buildConfigField 'String', 'BUILD_DATE', '"' + buildDate + '"'
}

if (project.hasProperty("raptor")) {
android.defaultConfig.manifestPlaceholders.isRaptorEnabled = "true"
}
Expand Down
33 changes: 32 additions & 1 deletion app/proguard-rules.pro
Expand Up @@ -40,4 +40,35 @@
# Mozilla Application Services
####################################################################################################

-keep class mozilla.appservices.FenixMegazord { *; }
-keep class mozilla.appservices.FenixMegazord { *; }

####################################################################################################
# Adjust
####################################################################################################

-keep public class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }
-keep class dalvik.system.VMRuntime {
java.lang.String getRuntime();
}
-keep class android.os.Build {
java.lang.String[] SUPPORTED_ABIS;
java.lang.String CPU_ABI;
}
-keep class android.content.res.Configuration {
android.os.LocaledList getLocales();
java.util.Locale locale;
}
-keep class android.os.LocaleList {
java.util.Locale get(int);
}
13 changes: 13 additions & 0 deletions app/src/debug/java/org/mozilla/fenix/AdjustHelper.kt
@@ -0,0 +1,13 @@
/* 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/. */

package org.mozilla.fenix

import android.content.Context

object AdjustHelper {
fun setupAdjustIfNeeded(context: Context) {
// DEBUG: No Adjust - This class has different implementations for all build types.
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Expand Up @@ -20,6 +20,7 @@ import mozilla.components.support.base.log.Log
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.base.log.sink.AndroidLogSink
import mozilla.components.support.rustlog.RustLog
import org.mozilla.fenix.AdjustHelper.setupAdjustIfNeeded
import org.mozilla.fenix.components.Components
import java.io.File

Expand Down Expand Up @@ -47,6 +48,7 @@ open class FenixApplication : Application() {
setupLeakCanary()
setupGlean(this)
loadExperiments()
setupAdjustIfNeeded(this)
}

protected open fun setupLeakCanary() {
Expand Down
62 changes: 62 additions & 0 deletions app/src/release/java/org/mozilla/fenix/AdjustHelper.kt
@@ -0,0 +1,62 @@
/* 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/. */

package org.mozilla.fenix

import android.app.Activity
import android.app.Application
import android.os.Bundle
import android.text.TextUtils

import com.adjust.sdk.Adjust
import com.adjust.sdk.AdjustConfig
import com.adjust.sdk.LogLevel
import mozilla.components.service.glean.Glean

object AdjustHelper {
fun setupAdjustIfNeeded(application: FenixApplication) {
// RELEASE: Enable Adjust - This class has different implementations for all build types.

if (TextUtils.isEmpty(BuildConfig.ADJUST_TOKEN)) {
throw IllegalStateException("No adjust token defined for release build")
}

if (!Glean.getUploadEnabled()) {
return
}

val config = AdjustConfig(
application,
BuildConfig.ADJUST_TOKEN,
AdjustConfig.ENVIRONMENT_PRODUCTION,
true
)

config.setLogLevel(LogLevel.SUPRESS)

Adjust.onCreate(config)

application.registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())
}

private class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity) {
Adjust.onResume()
}

override fun onActivityPaused(activity: Activity) {
Adjust.onPause()
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle) {}

override fun onActivityStarted(activity: Activity) {}

override fun onActivityStopped(activity: Activity) {}

override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}

override fun onActivityDestroyed(activity: Activity) {}
}
}
3 changes: 2 additions & 1 deletion automation/taskcluster/decision_task_nightly.py
Expand Up @@ -53,7 +53,8 @@ def generate_build_task(apks, is_staging):
checkout +
' && python automation/taskcluster/helper/get-secret.py'
' -s {} -k dsn -f .sentry_token'.format(sentry_secret) +
' && ./gradlew --no-daemon -PcrashReports=true clean test assembleRelease'),
' && python automation/taskcluster/adjust/get-secret.py get-secret.py -s project/mobile/fenix/adjust -k Greenfield -f .adjust_token' if not is_staging else '' +
' && ./gradlew --no-daemon -PcrashReports=true clean test assembleGreenfieldRelease'),
features={
"chainOfTrust": True,
"taskclusterProxy": True
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Expand Up @@ -30,6 +30,8 @@ private object Versions {
const val android_arch_navigation = "1.0.0-rc02"

const val autodispose = "1.1.0"
const val adjust = "4.11.4"
const val installreferrer = "1.0"

const val junit_jupiter = "5.3.2"
const val mockito = "2.23.0"
Expand Down Expand Up @@ -128,6 +130,9 @@ object Deps {
const val autodispose_android_aac = "com.uber.autodispose:autodispose-android-archcomponents:${Versions.autodispose}"
const val autodispose_android_aac_test = "com.uber.autodispose:autodispose-android-archcomponents-test:${Versions.autodispose}"

const val adjust = "com.adjust.sdk:adjust-android:${Versions.adjust}"
const val installreferrer = "com.android.installreferrer:installreferrer:${Versions.installreferrer}"

const val junit_jupiter_api = "org.junit.jupiter:junit-jupiter-api:${Versions.junit_jupiter}"
const val junit_jupiter_params = "org.junit.jupiter:junit-jupiter-params:${Versions.junit_jupiter}"
const val junit_jupiter_engine = "org.junit.jupiter:junit-jupiter-engine:${Versions.junit_jupiter}"
Expand Down

0 comments on commit b9aee25

Please sign in to comment.