Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into atavism/lantern-http-…
Browse files Browse the repository at this point in the history
…client
  • Loading branch information
atavism committed Oct 3, 2023
2 parents 53ba5bf + 305e4fa commit 87bf619
Show file tree
Hide file tree
Showing 41 changed files with 418 additions and 311 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/browerstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ env:

jobs:
build:
runs-on: ubuntu-latest
runs-on:
group: large-runners
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -57,9 +58,10 @@ jobs:
run: make android-lib ANDROID_ARCH=all

- name: Build APK
env:
CI: "true"
run: |
flutter pub get
echo "CI=true" >> $GITHUB_ENV
make do-android-debug ANDROID_ARCH=all
- name: List files in current directory
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:
jobs:

build:
runs-on: ubuntu-latest
runs-on:
group: large-runners
steps:
- uses: actions/checkout@v2
- name: Install libpcap
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ env:
DATADOG_SITE: datadoghq.eu
jobs:
set-version:
runs-on: ubuntu-latest
runs-on:
group: large-runners
outputs:
version: ${{ steps.set-version.outputs.version }}
prefix: ${{ steps.set-version.outputs.prefix }}
Expand Down Expand Up @@ -57,7 +58,8 @@ jobs:
version: ${{ needs.set-version.outputs.version }}
version_file: ${{ needs.set-version.outputs.version_file }}
prefix: ${{ needs.set-version.outputs.prefix }}
runs-on: ubuntu-latest-8-cores
runs-on:
group: large-runners
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -174,7 +176,8 @@ jobs:
s3cmd modify --add-header='content-type':'application/vnd.android.package-archive' "s3://$S3_BUCKET/${{ env.prefix }}.aab"
push-binaries:
runs-on: ubuntu-latest
runs-on:
group: large-runners
needs: [ set-version , build-android ]
env:
version: ${{ needs.set-version.outputs.version }}
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,17 @@ $(MOBILE_TEST_APK) $(MOBILE_TESTS_APK): $(MOBILE_SOURCES) $(MOBILE_ANDROID_LIB)
-b $(MOBILE_DIR)/app/build.gradle \
:app:assembleAutoTestDebug :app:assembleAutoTestDebugAndroidTest

dart-defines-debug:
@DART_DEFINES="$(CIBASE)"; \
printf "$$DART_DEFINES"

do-android-debug: $(MOBILE_SOURCES) $(MOBILE_ANDROID_LIB)
ln -fs $(MOBILE_DIR)/gradle.properties . && \
CI="$$CI" && $(GRADLE) -PlanternVersion=$(DEBUG_VERSION) -PddClientToken=$$DD_CLIENT_TOKEN -PddApplicationID=$$DD_APPLICATION_ID \
@ln -fs $(MOBILE_DIR)/gradle.properties . && \
DART_DEFINES=`make dart-defines-debug` && \
echo "Value of DART_DEFINES is: $$DART_DEFINES" && \
CI="$$CI" && \
echo "Value of CI is: $$CI" && \
$(GRADLE) -Pdart-defines="$$DART_DEFINES" -PlanternVersion=$(DEBUG_VERSION) -PddClientToken=$$DD_CLIENT_TOKEN -PddApplicationID=$$DD_APPLICATION_ID \
-PproServerUrl=$(PRO_SERVER_URL) -PpaymentProvider=$(PAYMENT_PROVIDER) -Pcountry=$(COUNTRY) \
-PplayVersion=$(FORCE_PLAY_VERSION) -PuseStaging=$(STAGING) -PstickyConfig=$(STICKY_CONFIG) \
-PlanternRevisionDate=$(REVISION_DATE) -PandroidArch=$(ANDROID_ARCH) \
Expand Down Expand Up @@ -354,7 +362,7 @@ android-release-install: $(MOBILE_RELEASE_APK)
$(ADB) install -r $(MOBILE_RELEASE_APK)

package-android: pubget require-version
@ANDROID_ARCH=all make android-release && \
@ANDROID_ARCH=arm32 make android-release && \
ANDROID_ARCH=all make android-bundle && \
echo "-> $(MOBILE_RELEASE_APK)"

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ All those dependencies must be in your PATH
* [Android Studio](https://developer.android.com/studio)
* [Git](https://git-scm.com/downloads)
* [Android NDK](#steps-to-run-the-project)
* NDK should be version 22.x, for example 22.1.7171670. Newer versions of the NDK don't work with the current release of gomobile.
* NDK should be version 26.x, for example 26.0.10792818.
* [Git LFS](https://git-lfs.github.com)
- more information in [Usage](#usage)
* [Flutter (3.10.5)](https://flutter.dev)
* [Flutter (3.13.5)](https://flutter.dev)
* [sentry-cli](https://docs.sentry.io/product/cli/installation/)
- This is used for uploading native debug symbols to Sentry
* [gomobile](https://github.com/golang/go/wiki/Mobile#tools)
* [json-server](https://github.com/typicode/json-server)
* Only necessary for testing Replica
* CMake 3.18.1
* CMake 3.22.1
* You can get this from Android SDK Manager

In the welcome screen choose the "Open an existing Android Studio" option and select the `android` folder.
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (flutterVersionName == null) {
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
ndkVersion "23.0.7599858"
ndkVersion "26.0.10792818"

bundle {
density {
Expand Down Expand Up @@ -139,7 +139,7 @@ android {
externalNativeBuild {
cmake {
path file('cmake/CMakeLists.txt')
version '3.18.1'
version '3.22.1'
}
}

Expand Down
8 changes: 0 additions & 8 deletions android/app/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
# libc++_shared.so is included in the binary
cmake_minimum_required(VERSION 3.10.2)
project("lantern-android")

message("Configuring STL for ${ANDROID_ABI}")
set(lib_path "llvm-libc++")
set(so_base "c++_shared")
configure_file(
"${ANDROID_NDK}/sources/cxx-stl/${lib_path}/libs/${ANDROID_ABI}/lib${so_base}.so"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${so_base}.so"
COPYONLY)
Binary file modified android/app/libs/alipaySdk-15.7.6-20200521195109.aar
Binary file not shown.
3 changes: 0 additions & 3 deletions android/app/libs/liblantern-all.aar

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.lantern.model.BaseModel
import io.lantern.model.Vpn
import org.getlantern.lantern.BuildConfig
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.model.Bandwidth
import org.getlantern.lantern.model.Stats
import org.getlantern.lantern.model.Utils
Expand Down Expand Up @@ -385,6 +386,7 @@ abstract class SessionManager(application: Application) : Session {

override fun setCountry(country: String) {
prefs.edit().putString(GEO_COUNTRY_CODE, country).apply()
Datadog.setCountry(country)
}

private val hasUpdatedStats = AtomicBoolean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import android.os.StrictMode
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDex
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.datadog.FlutterExcludingComponentPredicate
import org.getlantern.lantern.model.InAppBilling
import org.getlantern.lantern.model.LanternHttpClient
import org.getlantern.lantern.model.LanternSessionManager
Expand Down Expand Up @@ -48,7 +46,6 @@ open class LanternApp : Application() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
appContext = applicationContext
session = LanternSessionManager(this)
if (!BuildConfig.DEBUG) Datadog.initialize()

LanternProxySelector(session)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.getlantern.lantern.datadog

import android.util.Log
import com.datadog.android.Datadog as DatadogMain
import com.datadog.android.DatadogSite
import com.datadog.android.core.configuration.BatchSize
import com.datadog.android.core.configuration.Configuration
Expand All @@ -17,13 +16,20 @@ import org.getlantern.lantern.LanternApp
import org.getlantern.mobilesdk.Logger
import java.net.InetSocketAddress
import java.net.Proxy
import java.net.URI
import java.util.concurrent.atomic.AtomicBoolean
import com.datadog.android.Datadog as DatadogMain

object Datadog {
private val tracedHosts = listOf(
"datadoghq.eu",
"127.0.0.1",
)
private val tracedHosts =
listOf(
"datadoghq.eu",
"127.0.0.1",
"iantem.io",
"getlantern.org",
"getiantem.org",
"lantern.io",
)
private val initialized = AtomicBoolean()
private lateinit var datadogConfig: Configuration

Expand All @@ -33,13 +39,14 @@ object Datadog {
DatadogMain.setVerbosity(Log.VERBOSE)
datadogConfig = createDatadogConfiguration()

val datadogCredentials = Credentials(
clientToken = "puba617ab01333a95a25a9d3709f04e1654",
envName = "prod",
rumApplicationId = "f8eabf3c-5db3-4f7e-8e6a-5a72433b46d2",
variant = "release",
serviceName = "lantern-android",
)
val datadogCredentials =
Credentials(
clientToken = "puba617ab01333a95a25a9d3709f04e1654",
envName = "prod",
rumApplicationId = "f8eabf3c-5db3-4f7e-8e6a-5a72433b46d2",
variant = "release",
serviceName = "lantern-android",
)

DatadogMain.initialize(
LanternApp.getAppContext(),
Expand All @@ -52,9 +59,20 @@ object Datadog {
id = LanternApp.getSession().userId().toString(),
)

val monitor = RumMonitor.Builder().build()
GlobalRum.registerIfAbsent(monitor)
GlobalRum.registerIfAbsent {
RumMonitor.Builder().build()
}
val session = LanternApp.getSession()
setCountry(session.countryCode)
initialized.set(true)

// For some reason, sessions don't show up in DataDog RUM until we register a user action
// of some sort. So, here we fire the custom action "started" to get data to start flowing.
GlobalRum.get().addUserAction(RumActionType.CUSTOM, "started", emptyMap())
}

fun setCountry(country: String) {
GlobalRum.addAttribute("lantern.country_code", country)
}

fun addError(
Expand All @@ -68,12 +86,12 @@ object Datadog {

// trackUserAction is used to track specific user actions (such as taps, clicks, and scrolls)
// with RumMonitor
fun trackUserAction(
private fun trackUserAction(
actionType: RumActionType,
name: String,
actionAttributes: Map<String, Any?> = emptyMap(),
) {
GlobalRum.get().addUserAction(actionType, name, actionAttributes)
GlobalRum.get().addUserAction(actionType, name, actionAttributes)
}

// trackUserClick is used to track user clicks with RumMonitor
Expand All @@ -94,6 +112,8 @@ object Datadog {

private fun createDatadogConfiguration(): Configuration {
val session = LanternApp.getSession()
val hTTPAddr = session.hTTPAddr
val uri = URI("http://" + hTTPAddr)
return Configuration.Builder(
logsEnabled = true,
tracesEnabled = true,
Expand All @@ -105,15 +125,16 @@ object Datadog {
Proxy(
Proxy.Type.HTTP,
InetSocketAddress(
session.settings.httpProxyHost,
session.settings.httpProxyPort.toInt(),
"127.0.0.1",
uri.getPort(),
),
),
null,
)
.sampleRumSessions(100f)
.setUploadFrequency(UploadFrequency.FREQUENT)
.useSite(DatadogSite.EU1)
.trackBackgroundRumEvents(true)
.trackInteractions()
.trackLongTasks()
.setFirstPartyHosts(tracedHosts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.androidannotations.annotations.EService
import org.getlantern.lantern.BuildConfig
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.R
import org.getlantern.lantern.datadog.Datadog
import org.getlantern.lantern.model.AccountInitializationStatus
import org.getlantern.lantern.model.LanternHttpClient
import org.getlantern.lantern.model.LanternStatus
Expand Down Expand Up @@ -109,6 +110,8 @@ open class LanternService : Service(), Runnable {
createUser(0)
}

Datadog.initialize()

if (!BuildConfig.PLAY_VERSION && !BuildConfig.DEVELOPMENT_MODE) {
// check if an update is available
autoUpdater.checkForUpdates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,41 +281,40 @@ class PaymentsUtil(private val activity: Activity) {
} ?: "usd"
Logger.d(TAG, "Sending purchase request: provider $provider; plan ID: $planID; currency: $currency")
val session = session
val formBody: FormBody.Builder = FormBody.Builder()
.add("idempotencyKey", System.currentTimeMillis().toString())
.add("provider", provider.toString().lowercase())
.add("email", email)
.add("plan", planID)
.add("currency", currency.lowercase())
.add("deviceName", session.deviceName())
val json: JsonObject = JsonObject()
json.addProperty("idempotencyKey", System.currentTimeMillis().toString())
json.addProperty("provider", provider.toString().lowercase())
json.addProperty("email", email)
json.addProperty("plan", planID)
json.addProperty("currency", currency.lowercase())
json.addProperty("deviceName", session.deviceName())

when (provider) {
PaymentProvider.Stripe -> {
val stripePublicKey = session.stripePubKey()
stripePublicKey?.let { formBody.add("stripePublicKey", stripePublicKey) }
formBody.add("stripeEmail", email)
formBody.add("stripeToken", token)
formBody.add("token", token)
stripePublicKey?.let { json.addProperty("stripePublicKey", stripePublicKey) }
json.addProperty("stripeEmail", email)
json.addProperty("stripeToken", token)
json.addProperty("token", token)
}

PaymentProvider.GooglePlay -> {
formBody.add("token", token)
json.addProperty("token", token)
}

PaymentProvider.ResellerCode -> {
Logger.d(TAG, "Received reseller code purchase request")
val resellerCode = LanternApp.getSession().resellerCode()
resellerCode?.let {
formBody.add("provider", "reseller-code")
formBody.add("resellerCode", resellerCode)
}
json.addProperty("provider", "reseller-code")
json.addProperty("resellerCode", resellerCode!!)
}

else -> {}
}

lanternClient.post(
LanternHttpClient.createProUrl("/purchase"),
formBody.build(),
LanternHttpClient.createJsonBody(json),
object : ProCallback {

override fun onSuccess(response: Response?, result: JsonObject?) {
Expand All @@ -328,6 +327,7 @@ class PaymentsUtil(private val activity: Activity) {
}

override fun onFailure(t: Throwable?, error: ProError?) {
Logger.e(TAG, "Error with purchase request: $error")
Datadog.addError("Error with purchase request: $error", t, mapOf(
"provider" to provider.toString().lowercase(),
"plan" to planID,
Expand Down
4 changes: 2 additions & 2 deletions appium_kotlin/app/src/test/resources/live/live_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"server": "hub-cloud.browserstack.com/wd/hub",
"username": "jigarj_SNsRyw",
"access_key": "dA4yyG26fHbfJxRUYMwr",
"app": "bs://5fb3d71c0a06de7d496ff6fceba612a15e835577",
"app": "bs://ac26c1c990dabab70870c250ec774ec9f63fa350",
"capabilities": {
"automationName": "Flutter",
"setWebContentsDebuggingEnabled": true,
"appium:noReset": true,
"appium:logLevel": true,
"enablePerformanceLogging": true,
"bstack:options": {
"appiumVersion": "2.0.0",
"appiumVersion": "2.0.1",
"networkLogs": true,
"projectName": "Lantern",
"buildName": "Lantern-APK",
Expand Down
Loading

0 comments on commit 87bf619

Please sign in to comment.