Skip to content

Commit

Permalink
Stub out Google Mobile Services and Firebase with Open Source library…
Browse files Browse the repository at this point in the history
…, new build flavor 'gms' to use it
  • Loading branch information
tw-hx committed Oct 21, 2024
1 parent 886c1b0 commit b9c936e
Show file tree
Hide file tree
Showing 52 changed files with 925 additions and 12 deletions.
29 changes: 23 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ val selectableVariants = listOf(
"playStagingInstrumentation",
"playStagingRelease",
"websiteProdSpinner",
"websiteFossProdRelease",
"websiteGmsProdRelease",
"websiteProdRelease"
)

Expand Down Expand Up @@ -83,7 +85,7 @@ android {
compileSdkVersion = signalCompileSdkVersion
ndkVersion = signalNdkVersion

flavorDimensions += listOf("distribution", "environment")
flavorDimensions += listOf("distribution", "gms", "environment")
useLibrary("org.apache.http.legacy")
testBuildType = "instrumentation"

Expand Down Expand Up @@ -352,8 +354,10 @@ android {
}

create("website") {
val MAU = if (gradle.startParameter.taskRequests.toString().contains("Foss")) "false" else "true"

dimension = "distribution"
buildConfigField("boolean", "MANAGES_APP_UPDATES", "true")
buildConfigField("boolean", "MANAGES_APP_UPDATES", "${MAU}")
buildConfigField("String", "APK_UPDATE_MANIFEST_URL", "\"https://updates.signal.org/android/latest.json\"")
buildConfigField("String", "BUILD_DISTRIBUTION_TYPE", "\"website\"")
}
Expand All @@ -372,6 +376,17 @@ android {
buildConfigField("String", "BUILD_DISTRIBUTION_TYPE", "\"nightly\"")
}

create("gms") {
dimension = "gms"
isDefault = true
buildConfigField("boolean", "USE_OSM", "false")
}

create("foss") {
dimension = "gms"
buildConfigField("boolean", "USE_OSM", "true")
}

create("prod") {
dimension = "environment"

Expand Down Expand Up @@ -528,13 +543,15 @@ dependencies {
implementation(libs.androidx.asynclayoutinflater)
implementation(libs.androidx.asynclayoutinflater.appcompat)
implementation(libs.androidx.emoji2)
implementation(libs.firebase.messaging) {
"gmsImplementation"(libs.firebase.messaging) {
exclude(group = "com.google.firebase", module = "firebase-core")
exclude(group = "com.google.firebase", module = "firebase-analytics")
exclude(group = "com.google.firebase", module = "firebase-measurement-connector")
}
implementation(libs.google.play.services.maps)
implementation(libs.google.play.services.auth)
"gmsImplementation"(libs.google.play.services.maps)
"gmsImplementation"(libs.google.play.services.auth)
"fossImplementation"(project(":libfakegms"))
"fossImplementation"(libs.osmdroid)
implementation(libs.bundles.media3)
implementation(libs.conscrypt.android)
implementation(libs.signal.aesgcmprovider)
Expand Down Expand Up @@ -571,7 +588,7 @@ dependencies {
implementation(libs.accompanist.permissions)
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.coroutines.play.services)
"gmsImplementation"(libs.kotlinx.coroutines.play.services)
implementation(libs.kotlinx.coroutines.rx3)
implementation(libs.jackson.module.kotlin)
implementation(libs.rxjava3.rxandroid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.android.gms.maps.model.LatLng;

import org.thoughtcrime.securesms.BuildConfig;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.maps.AddressData;
import org.thoughtcrime.securesms.util.JsonUtils;
Expand All @@ -19,7 +20,8 @@

public class SignalPlace {

private static final String URL = "https://maps.google.com/maps";
private static final String GMS_URL = "https://maps.google.com/maps";
private static final String OSM_URL = "https://www.openstreetmap.org/";
private static final String TAG = Log.tag(SignalPlace.class);

@JsonProperty
Expand Down Expand Up @@ -62,10 +64,21 @@ public String getDescription() {
description += (address + "\n");
}

description += Uri.parse(URL)
.buildUpon()
.appendQueryParameter("q", String.format("%s,%s", latitude, longitude))
.build().toString();
if (BuildConfig.USE_OSM) {
// Thanks to https://github.com/sergimn for suggesting place marker
description += Uri.parse(OSM_URL)
.buildUpon()
.appendQueryParameter("mlat", String.format("%s", latitude))
.appendQueryParameter("mlon", String.format("%s", longitude))
.encodedFragment(String.format("map=15/%s/%s", latitude, longitude))
.build().toString();
}
else {
description += Uri.parse(GMS_URL)
.buildUpon()
.appendQueryParameter("q", String.format("%s,%s", latitude, longitude))
.build().toString();
}

return description;
}
Expand Down
3 changes: 3 additions & 0 deletions dependencies.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ dependencyResolutionManagement {
// Can"t use the newest version because it hits some weird NoClassDefFoundException
library("jknack-handlebars", "com.github.jknack:handlebars:4.0.7")

// Signal-FOSS
library("osmdroid", "org.osmdroid:osmdroid-android:6.1.20")

// Mp4Parser
library("mp4parser-isoparser", "org.mp4parser", "isoparser").versionRef("mp4parser")
library("mp4parser-streaming", "org.mp4parser", "streaming").versionRef("mp4parser")
Expand Down
15 changes: 14 additions & 1 deletion donations/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ plugins {

android {
namespace = "org.signal.donations"

flavorDimensions += listOf("gms")
productFlavors {
create("gms") {
dimension = "gms"
isDefault = true
}

create("foss") {
dimension = "gms"
}
}
}

dependencies {
Expand All @@ -18,6 +30,7 @@ dependencies {
exclude(group = "com.google.protobuf", module = "protobuf-java")
}

api(libs.google.play.services.wallet)
"gmsApi"(libs.google.play.services.wallet)
"fossApi"(project(":libfakegms"))
api(libs.square.okhttp3)
}
29 changes: 29 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ https://docs.gradle.org/current/userguide/dependency_verification.html
</trusted-artifacts>
</configuration>
<components>
<!-- Begin Signal-FOSS -->
<component group="org.osmdroid" name="osmdroid-android" version="6.1.20">
<artifact name="osmdroid-android-6.1.20.aar">
<sha256 value="2cbec2a2a1a671a76849897748080079a3158a7a4c8554b86f2c75860f91046a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="androidx.recyclerview" name="recyclerview" version="1.0.0">
<artifact name="recyclerview-1.0.0.aar">
<sha256 value="06956fb1ac014027ca9d2b40469a4b42aa61b4957bb11848e1ff352701ab4548" origin="Generated by Gradle"/>
</artifact>
</component>
<!-- Extra temporary requirements for Signal 5.15.4 FOSS build -->
<component group="org.jetbrains.kotlinx" name="kotlinx-coroutines-reactive" version="1.7.3">
<artifact name="kotlinx-coroutines-reactive-1.7.3.jar">
<sha256 value="dc6d2add2e9a2d6574bc6f4e80ed0d397e6ca5c27196dfc6ab82322d712d71be" origin="Generated by Gradle"/>
</artifact>
<artifact name="kotlinx-coroutines-reactive-1.7.3.module">
<sha256 value="7dbb40abc7290719872c2a0fc9a6366db7201dfb1b81459a8eec4ae648ca3b10" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-coroutines-rx3" version="1.7.3">
<artifact name="kotlinx-coroutines-rx3-1.7.3.jar">
<sha256 value="b0ce6b6d4c7a708a12bd9dd369f179c29cdc22b187f1c5f7d1fc6c9852125cb2" origin="Generated by Gradle"/>
</artifact>
<artifact name="kotlinx-coroutines-rx3-1.7.3.module">
<sha256 value="16ca94bc01f5038a8753de8495d146f5e6757a04c9246f70a8ba4df1bad0be15" origin="Generated by Gradle"/>
</artifact>
</component>
<!-- End Signal-FOSS -->
<component group="androidx.activity" name="activity" version="1.2.3">
<artifact name="activity-1.2.3.aar">
<sha256 value="1dce0705c334a6b2ef03382418dc7586f4e57ee23817267b403ea8cfc36c824e" origin="Generated by Gradle"/>
Expand Down
14 changes: 14 additions & 0 deletions libfakegms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("signal-library")
}

android {
namespace = "com.google.android.gms"
}

dependencies {
implementation(libs.androidx.preference)
implementation(libs.osmdroid)
}
2 changes: 2 additions & 0 deletions libfakegms/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
5 changes: 5 additions & 0 deletions libfakegms/src/main/java/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under GNU GENERAL PUBLIC LICENSE 3.0

Files under com/google/android (c) 2020 Angus Turnbull https://www.twinhelix.com/
Files com/google/android/gms/maps/{GoogleMap.java,MapView.java,SupportMapFragment.java} (c) Fumiaki Yoshimatsu https://github.com/fumiakiy/Signal-Android/tree/fumiakiy/share-location-osm
Files under com/google/firebase (c) Oscar Mira / valldrac https://github.com/mollyim/mollyim-android/tree/master/libfakegms/src/main/java/com/google/firebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.google.android.gms.auth.api.phone;

import android.content.Context;

public final class SmsRetriever {
public static final String EXTRA_SMS_MESSAGE = "com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE";
public static final String EXTRA_STATUS = "com.google.android.gms.auth.api.phone.EXTRA_STATUS";
public static final String SMS_RETRIEVED_ACTION = "com.google.android.gms.auth.api.phone.SMS_RETRIEVED";

public static SmsRetrieverClient getClient(Context context) {
return new SmsRetrieverClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.google.android.gms.auth.api.phone;

import com.google.android.gms.tasks.Task;

public final class SmsRetrieverClient {
public Task startSmsRetriever() {
return new Task();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.google.android.gms.common;

public class ConnectionResult {
public static final int SUCCESS = 0;
public static final int SERVICE_MISSING = 1;
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
public static final int SERVICE_DISABLED = 3;
public static final int SERVICE_INVALID = 9;
public static final int API_UNAVAILABLE = 16;
public static final int SERVICE_MISSING_PERMISSION = 19;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.google.android.gms.common;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

public class GoogleApiAvailability {
public static GoogleApiAvailability getInstance() {
return new GoogleApiAvailability();
}

public int isGooglePlayServicesAvailable(Context context) {
return ConnectionResult.SERVICE_MISSING;
}

public Dialog getErrorDialog(Activity activity, int errorCode, int requestCode) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.google.android.gms.common.api;

public class ApiException extends Exception {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.google.android.gms.common.api;

public class CommonStatusCodes {
public static final int ERROR = 12;
public static final int SUCCESS = 0;
public static final int TIMEOUT = 15;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.google.android.gms.common.api;

public final class Status {
public Status(int statusCode) {
}

public int getStatusCode() {
return CommonStatusCodes.ERROR;
}

public String getStatusMessage() {
return new String();
}

public static final int RESULT_SUCCESS = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.google.android.gms.maps;

import com.google.android.gms.maps.model.LatLng;

public final class CameraUpdate {
public final LatLng latLng;
public final float zoom;

public CameraUpdate(LatLng latLng, float zoom) {
this.latLng = latLng;
this.zoom = zoom;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.google.android.gms.maps;

import com.google.android.gms.maps.model.LatLng;

public final class CameraUpdateFactory {
public static CameraUpdate newLatLngZoom(LatLng latLng, float zoom) {
return new CameraUpdate(latLng, zoom);
}
}
Loading

0 comments on commit b9c936e

Please sign in to comment.