Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #162 - Add build flag to exclude proprietary dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Aug 10, 2020
1 parent f4480df commit 8df86dd
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 65 deletions.
23 changes: 17 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import org.mozilla.fenix.gradle.tasks.LintUnitTestRunner

import static org.gradle.api.tasks.testing.TestResult.ResultType

def useFreeImplementation = project.properties['org.mozilla.fenix.useFreeImplementation'].toBoolean()

android {
compileSdkVersion Config.compileSdkVersion
defaultConfig {
Expand All @@ -31,6 +33,7 @@ android {
resValue "bool", "IS_DEBUG", "false"
buildConfigField "boolean", "USE_RELEASE_VERSIONING", "false"
buildConfigField "String", "AMO_COLLECTION", "\"3204bb44a6ef44d39ee34917f28055\""
buildConfigField "boolean", "USE_FREE_IMPLEMENTATION", useFreeImplementation.toString()
def deepLinkSchemeValue = "fenix-dev"
buildConfigField "String", "DEEP_LINK_SCHEME", "\"$deepLinkSchemeValue\""
manifestPlaceholders = [
Expand Down Expand Up @@ -142,6 +145,13 @@ android {
java.srcDirs = ['src/migration/java', 'src/geckoRelease/java']
manifest.srcFile "src/migration/AndroidManifest.xml"
}
main {
if (useFreeImplementation) {
java.srcDirs += ["src/free"]
} else {
java.srcDirs += ["src/nonFree"]
}
}
}

splits {
Expand Down Expand Up @@ -330,10 +340,6 @@ dependencies {
implementation Deps.androidx_coordinatorlayout

implementation Deps.sentry
implementation Deps.osslicenses_library

implementation Deps.leanplum_core
implementation Deps.leanplum_fcm

implementation Deps.mozilla_concept_engine
implementation Deps.mozilla_concept_menu
Expand Down Expand Up @@ -412,7 +418,6 @@ dependencies {
implementation Deps.mozilla_ui_widgets

implementation Deps.mozilla_lib_crash
implementation Deps.mozilla_lib_push_firebase
implementation Deps.mozilla_lib_dataprotect
debugImplementation Deps.leakcanary

Expand Down Expand Up @@ -441,7 +446,13 @@ dependencies {
implementation Deps.adjust
implementation Deps.installreferrer // Required by Adjust

implementation Deps.google_ads_id // Required for the Google Advertising ID
if (!useFreeImplementation) {
implementation Deps.leanplum_core
implementation Deps.leanplum_fcm
implementation Deps.mozilla_lib_push_firebase
implementation Deps.osslicenses_library
implementation Deps.google_ads_id // Required for the Google Advertising ID
}

androidTestImplementation Deps.uiautomator
// Removed pending AndroidX fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -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.components.metrics

import android.content.Context

interface AdvertisingIDImpl : AdvertisingID {
override fun getAdvertisingID(context: Context): String? {
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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.components.metrics

import android.app.Application
import java.util.UUID

class LeanplumMetricsServiceImpl(
private val application: Application,
private val deviceIdGenerator: () -> String = { UUID.randomUUID().toString() }
) : MetricsService {
override val type = MetricServiceType.Marketing
override fun start() {}
override fun stop() {}
override fun track(event: Event) {}
override fun shouldTrack(event: Event): Boolean {return false;}
}
15 changes: 15 additions & 0 deletions app/src/free/java/org/mozilla/fenix/push/PushServiceImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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.push

import android.content.Context
import mozilla.components.concept.push.PushService

class PushServiceImpl : PushService {
override fun deleteToken() {}
override fun isServiceAvailable(context: Context): Boolean { return false }
override fun start(context: Context) {}
override fun stop() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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.settings.about

import android.content.Context
import android.content.Intent

class OssLicensesMenuImpl : OssLicensesMenu {
override fun getIntent(context: Context?, title: String): Intent {
throw NotImplementedError()
}
}

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
android:exported="false" />

<service
android:name=".push.FirebasePushService"
android:name=".push.PushServiceImpl"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/mozilla/fenix/components/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ReleaseChannel
import org.mozilla.fenix.components.metrics.AdjustMetricsService
import org.mozilla.fenix.components.metrics.GleanMetricsService
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
import org.mozilla.fenix.components.metrics.LeanplumMetricsServiceImpl
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Mockable
Expand Down Expand Up @@ -88,7 +88,7 @@ class Analytics(
MetricController.create(
listOf(
GleanMetricsService(context),
LeanplumMetricsService(context as Application),
LeanplumMetricsServiceImpl(context as Application),
AdjustMetricsService(context)
),
isDataTelemetryEnabled = { context.settings().isTelemetryEnabled },
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/mozilla/fenix/components/Push.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import mozilla.components.feature.push.PushConfig
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.R
import org.mozilla.fenix.push.FirebasePushService
import org.mozilla.fenix.push.PushServiceImpl

/**
* Component group for push services. These components use services that strongly depend on
Expand Down Expand Up @@ -42,5 +42,5 @@ class Push(context: Context, crashReporter: CrashReporter) {
PushConfig(projectId)
}

private val pushService by lazy { FirebasePushService() }
private val pushService by lazy { PushServiceImpl() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ package org.mozilla.fenix.components.metrics
import android.content.Context
import android.util.Base64
import androidx.annotation.VisibleForTesting
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mozilla.components.browser.search.SearchEngine
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore
import org.mozilla.fenix.ext.searchEngineManager
import java.io.IOException
import java.security.NoSuchAlgorithmException
import java.security.spec.InvalidKeySpecException
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec

object MetricsUtils {
interface AdvertisingID {
/**
* Query the Google Advertising API to get the Google Advertising ID.
*
* This is meant to be used off the main thread. The API will throw an
* exception and we will print a log message otherwise.
*
* @return a String containing the Google Advertising ID or null.
*/
fun getAdvertisingID(context: Context): String?
}

object MetricsUtils : AdvertisingIDImpl {
fun createSearchEvent(
engine: SearchEngine,
context: Context,
Expand Down Expand Up @@ -72,38 +80,6 @@ object MetricsUtils {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun getHashingSalt(): String = "org.mozilla.fenix-salt"

/**
* Query the Google Advertising API to get the Google Advertising ID.
*
* This is meant to be used off the main thread. The API will throw an
* exception and we will print a log message otherwise.
*
* @return a String containing the Google Advertising ID or null.
*/
@Suppress("TooGenericExceptionCaught")
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun getAdvertisingID(context: Context): String? {
return try {
AdvertisingIdClient.getAdvertisingIdInfo(context).id
} catch (e: GooglePlayServicesNotAvailableException) {
Logger.debug("ActivationPing - Google Play not installed on the device")
null
} catch (e: GooglePlayServicesRepairableException) {
Logger.debug("ActivationPing - recoverable error connecting to Google Play Services")
null
} catch (e: IllegalStateException) {
// This is unlikely to happen, as this should be running off the main thread.
Logger.debug("ActivationPing - AdvertisingIdClient must be called off the main thread")
null
} catch (e: IOException) {
Logger.debug("ActivationPing - unable to connect to Google Play Services")
null
} catch (e: NullPointerException) {
Logger.debug("ActivationPing - no Google Advertising ID available")
null
}
}

/**
* Produces a hashed version of the Google Advertising ID.
* We want users using more than one of our products to report a different
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.view.ViewGroup
import androidx.core.content.pm.PackageInfoCompat
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import kotlinx.android.synthetic.main.fragment_about.*
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BuildConfig
Expand Down Expand Up @@ -119,7 +118,7 @@ class AboutFragment : Fragment(), AboutPageListener {
private fun populateAboutList(): List<AboutPageItem> {
val context = requireContext()

return listOf(
return listOfNotNull(
AboutPageItem(
AboutItem.ExternalLink(
WHATS_NEW,
Expand Down Expand Up @@ -148,13 +147,9 @@ class AboutFragment : Fragment(), AboutPageListener {
SupportUtils.getSumoURLForTopic(context, SupportUtils.SumoTopic.YOUR_RIGHTS)
), getString(R.string.about_know_your_rights)
),
AboutPageItem(
if (BuildConfig.USE_FREE_IMPLEMENTATION) null else AboutPageItem(
AboutItem.ExternalLink(LICENSING_INFO, ABOUT_LICENSE_URL),
getString(R.string.about_licensing_information)
),
AboutPageItem(
AboutItem.Libraries,
getString(R.string.about_other_open_source_libraries)
)
)
}
Expand All @@ -168,13 +163,10 @@ class AboutFragment : Fragment(), AboutPageListener {
}

private fun openLibrariesPage() {
startActivity(Intent(context, OssLicensesMenuActivity::class.java))
OssLicensesMenuActivity.setActivityTitle(
getString(
R.string.open_source_licenses_title,
appName
)
)
val title = getString(R.string.open_source_licenses_title, appName)
val ossLicensesMenu = OssLicensesMenuImpl()
val intent = ossLicensesMenu.getIntent(context, title)
startActivity(intent)
}

override fun onAboutItemClicked(item: AboutItem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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.settings.about

import android.content.Context
import android.content.Intent

interface OssLicensesMenu {
fun getIntent(context: Context?, title: String): Intent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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.components.metrics

import android.content.Context
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import mozilla.components.support.base.log.logger.Logger
import java.io.IOException

interface AdvertisingIDImpl : AdvertisingID {
@Suppress("TooGenericExceptionCaught")
override fun getAdvertisingID(context: Context): String? {
return try {
AdvertisingIdClient.getAdvertisingIdInfo(context).id
} catch (e: GooglePlayServicesNotAvailableException) {
Logger.debug("ActivationPing - Google Play not installed on the device")
null
} catch (e: GooglePlayServicesRepairableException) {
Logger.debug("ActivationPing - recoverable error connecting to Google Play Services")
null
} catch (e: IllegalStateException) {
// This is unlikely to happen, as this should be running off the main thread.
Logger.debug("ActivationPing - AdvertisingIdClient must be called off the main thread")
null
} catch (e: IOException) {
Logger.debug("ActivationPing - unable to connect to Google Play Services")
null
} catch (e: NullPointerException) {
Logger.debug("ActivationPing - no Google Advertising ID available")
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private val Event.name: String?
else -> null
}

class LeanplumMetricsService(
class LeanplumMetricsServiceImpl(
private val application: Application,
private val deviceIdGenerator: () -> String = { randomUUID().toString() }
) : MetricsService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import mozilla.components.feature.push.AutoPushFeature
* that lets us easily delegate the implementation to that, as well as make invocations when FCM
* receives new messages.
*/
class FirebasePushService : LeanplumPushFirebaseMessagingService(),
class PushServiceImpl : LeanplumPushFirebaseMessagingService(),
PushService by AutoPushService {

override fun onCreate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* 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.settings.about

import android.content.Context
import android.content.Intent
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity

class OssLicensesMenuImpl : OssLicensesMenu {
override fun getIntent(context: Context?, title: String): Intent {
OssLicensesMenuActivity.setActivityTitle(title)
return Intent(context, OssLicensesMenuActivity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import org.mozilla.fenix.R

class LeanplumNotificationCustomizerTest {

private val customizer = LeanplumNotificationCustomizer()
private val customizer =
LeanplumNotificationCustomizer()

@Test
fun `customize adds icon`() {
Expand Down
Loading

0 comments on commit 8df86dd

Please sign in to comment.