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

For #162 - add feature build flag to disable firebase push service #13857

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ import org.mozilla.fenix.gradle.tasks.LintUnitTestRunner

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

def initBuildFeatures() {
def properties = project.getProperties()
def allBuildFeatures = file('src/features')
.listFiles()
.findAll { f -> f.isDirectory() }
.name

def features = [:]
for (feature in allBuildFeatures) {
def property = "org.mozilla.fenix.enableFeature${feature.capitalize()}"
def isEnabled = (properties."${property}" ?: "true").toBoolean()
features.put feature, isEnabled
println("Feature ${feature}: ${isEnabled ? 'enabled' : 'disabled'}.")
}

return features
}

project.ext.set("buildFeatures", initBuildFeatures())

android {
compileSdkVersion Config.compileSdkVersion
defaultConfig {
Expand All @@ -33,6 +53,13 @@ android {
buildConfigField "String", "AMO_COLLECTION", "\"3204bb44a6ef44d39ee34917f28055\""
def deepLinkSchemeValue = "fenix-dev"
buildConfigField "String", "DEEP_LINK_SCHEME", "\"$deepLinkSchemeValue\""
project.ext.buildFeatures.each { feature, isEnabled ->
def featureToUpper = feature.replaceAll(/\B([A-Z])/, '_\$1').toUpperCase()
def featureKey = "ENABLE_FEATURE_" + featureToUpper
def featureValue = isEnabled.toString()
buildConfigField "boolean", featureKey, featureValue
resValue "bool", featureKey, featureValue
}
manifestPlaceholders = [
"deepLinkScheme": deepLinkSchemeValue
]
Expand Down Expand Up @@ -125,6 +152,15 @@ android {
flavorDimensions "engine"

sourceSets {
main {
project.ext.buildFeatures.each { feature, isEnabled ->
if (isEnabled) {
java.srcDirs += ["src/features/${feature}/impl"]
} else {
java.srcDirs += ["src/features/${feature}/stub"]
}
}
}
androidTest {
resources.srcDirs += ['src/androidTest/resources']
}
Expand All @@ -142,6 +178,13 @@ android {
java.srcDirs = ['src/migration/java', 'src/geckoRelease/java']
manifest.srcFile "src/migration/AndroidManifest.xml"
}
test {
project.ext.buildFeatures.each { feature, isEnabled ->
if (isEnabled) {
java.srcDirs += ["src/features/${feature}/test"]
}
}
}
}

splits {
Expand Down Expand Up @@ -412,7 +455,9 @@ dependencies {
implementation Deps.mozilla_ui_widgets

implementation Deps.mozilla_lib_crash
implementation Deps.mozilla_lib_push_firebase
if (project.ext.buildFeatures['firebase']) {
implementation Deps.mozilla_lib_push_firebase
}
implementation Deps.mozilla_lib_dataprotect
debugImplementation Deps.leakcanary

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.push

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

@SuppressWarnings("EmptyFunctionBlock")
class FirebasePushService : PushService {
override fun deleteToken() {}
override fun isServiceAvailable(context: Context): Boolean { return false }
override fun start(context: Context) {}
override fun stop() {}
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@

<service
android:name=".push.FirebasePushService"
android:enabled="@bool/ENABLE_FEATURE_FIREBASE"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
Expand Down