Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into atavism/7.9.8
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Oct 23, 2024
2 parents 3037e9b + 3e95708 commit 8cfd746
Show file tree
Hide file tree
Showing 48 changed files with 330 additions and 651 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ jobs:
env:
ANDROID_INTERSTITIAL_AD_ID: ${{ secrets.INTERSTITIAL_AD_UNIT_ID }}
IOS_INTERSTITIAL_AD_ID: ${{ secrets.INTERSTITIAL_AD_UNIT_ID_IOS }}
TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID: ${{ secrets.TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID }}
TAPSELL_INTERSTITIAL_ZONE_ID: ${{ secrets.TAPSELL_INTERSTITIAL_ZONE_ID }}
run: |
touch app.env
echo "Android_interstitialAd=$ANDROID_INTERSTITIAL_AD_ID" > app.env
echo "IOS_interstitialAd=$IOS_INTERSTITIAL_AD_ID" >> app.env
echo "VideoInterstitialZoneId=$TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID" >> app.env
echo "InterstitialZoneId=$TAPSELL_INTERSTITIAL_ZONE_ID" >> app.env
- name: Clean packages to save disk space
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ jobs:
make package-darwin
env:
VERSION: "${{ env.version }}"
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERT }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERT_PASS }}
MACOS_CERTIFICATE: ${{ secrets.MACOS_BNS_CERT }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_BNS_CERT_PASS }}

- name: Install s3cmd
run: pip install s3cmd
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ tag: require-version
git push

define osxcodesign
codesign --options runtime --strict --timestamp --force --deep -s "Developer ID Application: Innovate Labs LLC (4FYC28AXA2)" -v $(1)
codesign --options runtime --strict --timestamp --force --deep -s "Developer ID Application: Brave New Software Project, Inc (ACZRKC3LQ9)" -v $(1)
endef

guard-%:
Expand Down
14 changes: 10 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
android:name="org.getlantern.lantern.LanternApp"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:resizeableActivity="false"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:persistent="true"
android:requestLegacyExternalStorage="true"
android:resizeableActivity="false"
android:theme="@style/AppTheme"
android:largeHeap="true"
tools:replace="allowBackup, label"
tools:targetApi="n">

Expand Down Expand Up @@ -88,14 +88,20 @@
</intent-filter>
</activity>


<activity
android:name=".activity.WebViewActivity"
android:exported="false" />

<service
android:name=".service.LanternService"
android:enabled="true"
android:exported="false"
android:stopWithTask="false" />

<receiver android:name=".model.DeclineCallBroadcastReceiver"
android:exported="false"/>
<receiver
android:name=".model.DeclineCallBroadcastReceiver"
android:exported="false" />

<receiver
android:name="org.getlantern.lantern.notification.NotificationReceiver"
Expand Down
29 changes: 21 additions & 8 deletions android/app/src/main/kotlin/io/lantern/apps/AppData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import org.getlantern.mobilesdk.Logger
import java.io.ByteArrayOutputStream

data class AppData(
Expand All @@ -17,20 +19,31 @@ data class AppData(
val icon: ByteArray? by lazy {
try {
val icon: Drawable = packageManager.getApplicationIcon(packageName)
val bitmap: Bitmap = Bitmap.createBitmap(
icon.intrinsicWidth,
icon.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas: Canvas = Canvas(bitmap)
icon.setBounds(0, 0, canvas.width, canvas.height)
icon.draw(canvas)
val bitmap = drawableToBitmap(icon)
val stream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
stream.toByteArray()
} catch (e: Exception) {
Logger.e("AppData", "Error converting icon to byte array", e)
e.printStackTrace()
null
}
}

private fun drawableToBitmap(drawable: Drawable): Bitmap {
if (drawable is BitmapDrawable) {
return drawable.bitmap
}
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package io.lantern.apps
import android.Manifest
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import java.io.ByteArrayOutputStream

class AppsDataProvider(
private val packageManager: PackageManager,
Expand All @@ -25,6 +30,7 @@ class AppsDataProvider(
.toList().sortedBy { it.name }
}


// check whether a particular package has been granted permission to open network sockets
private fun hasInternetPermission(packageName: String): Boolean {
return PackageManager.PERMISSION_GRANTED ==
Expand All @@ -41,6 +47,8 @@ class AppsDataProvider(
return packageName == thisPackageName
}



companion object {
private val TAG = AppsDataProvider::class.java.name
}
Expand Down
26 changes: 22 additions & 4 deletions android/app/src/main/kotlin/io/lantern/model/SessionModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.core.content.ContextCompat
import androidx.webkit.ProxyConfig
import androidx.webkit.ProxyController
import androidx.webkit.WebViewFeature
import com.google.protobuf.ByteString
import internalsdk.SessionModel
import internalsdk.SessionModelOpts
import io.flutter.embedding.engine.FlutterEngine
Expand All @@ -23,14 +22,17 @@ import io.lantern.model.dbadapter.DBAdapter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonArray
import org.getlantern.lantern.BuildConfig
import org.getlantern.lantern.LanternApp
import org.getlantern.lantern.activity.WebViewActivity
import org.getlantern.lantern.model.InAppBilling
import org.getlantern.lantern.model.Utils
import org.getlantern.lantern.plausible.Plausible
import org.getlantern.lantern.util.AutoUpdater
import org.getlantern.lantern.util.LanternProxySelector
import org.getlantern.lantern.util.PaymentsUtil
Expand Down Expand Up @@ -135,6 +137,13 @@ class SessionModel internal constructor(
result.success(LanternApp.getInAppBilling().isPlayStoreAvailable())
}

"trackUserAction" -> {
val props: Map<String, String> = mapOf("title" to call.argument("title")!!)
Plausible.event(
call.argument("name")!!, url = call.argument("url")!!, props = props
)
}

else -> super.doOnMethodCall(call, result)
}
}
Expand Down Expand Up @@ -199,7 +208,10 @@ class SessionModel internal constructor(
}

fun setUserIdAndToken(userId: Long, token: String) {
model.invokeMethod("setUserIdAndToken", Arguments(mapOf("userId" to userId, "token" to token)))
model.invokeMethod(
"setUserIdAndToken",
Arguments(mapOf("userId" to userId, "token" to token))
)
}

fun setUserPro(isPro: Boolean) {
Expand Down Expand Up @@ -381,20 +393,26 @@ class SessionModel internal constructor(
// this ends up in memory out of exception
CoroutineScope(Dispatchers.IO).launch {
try {
val start = System.currentTimeMillis()
val appsList = appsDataProvider.listOfApps()
// First add just the app names to get a list quickly
val apps = buildJsonArray {
appsList.forEach { app ->
add(
buildJsonObject {
val byte = ByteString.copyFrom(app.icon)
val byte = app.icon!!
put("packageName", app.packageName)
put("name", app.name)
put("icon", byte.toByteArray().toUByteArray().joinToString(", "))
putJsonArray("icon") {
byte.toUByteArray().forEach { add(it.toInt()) }
}
}
)
}
}
val end = System.currentTimeMillis()
Logger.debug(TAG, "Time taken to get app data: ${end - start} ms")

model.invokeMethod(
"updateAppsData",
Arguments(mapOf("appsList" to apps.toString()))
Expand Down
10 changes: 6 additions & 4 deletions android/app/src/main/kotlin/org/getlantern/lantern/LanternApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ open class LanternApp : Application() {
private lateinit var appContext: Context
private lateinit var inAppBilling: InAppBilling
lateinit var session: SessionModel
val sessionInitialized = ::session.isInitialized
private lateinit var goSession: internalsdk.SessionModel
var messaging: MessagingHolder = MessagingHolder()

Expand All @@ -69,9 +70,10 @@ open class LanternApp : Application() {
fun getInAppBilling(): InAppBilling {
return inAppBilling
}

@JvmStatic
fun setInAppBilling(inAppBilling: InAppBilling) {
this.inAppBilling= inAppBilling
fun setInAppBilling(inAppBilling: InAppBilling) {
this.inAppBilling = inAppBilling
}


Expand All @@ -81,8 +83,8 @@ open class LanternApp : Application() {
}

@JvmStatic
fun setGoSession(sessionModel :internalsdk.SessionModel) {
goSession= sessionModel
fun setGoSession(sessionModel: internalsdk.SessionModel) {
goSession = sessionModel
}
}
}
32 changes: 20 additions & 12 deletions android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,8 @@ class MainActivity :
}

override fun onResume() {
val start = System.currentTimeMillis()
super.onResume()

val isServiceRunning = Utils.isServiceRunning(activity, LanternVpnService::class.java)
if (vpnModel.isConnectedToVpn() && !isServiceRunning) {
Logger.d(TAG, "LanternVpnService isn't running, clearing VPN preference")
vpnModel.setVpnOn(false)
} else if (!vpnModel.isConnectedToVpn() && isServiceRunning) {
Logger.d(TAG, "LanternVpnService is running, updating VPN preference")
vpnModel.setVpnOn(true)
}
Logger.debug(TAG, "onResume() finished at ${System.currentTimeMillis() - start}")
checkVPNStatus();
}

override fun onDestroy() {
Expand Down Expand Up @@ -233,6 +223,24 @@ class MainActivity :
}
}

private fun checkVPNStatus() {
CoroutineScope(Dispatchers.IO).launch {
val start = System.currentTimeMillis()
val isServiceRunning = withContext(Dispatchers.Main) {
Utils.isServiceRunning(activity, LanternVpnService::class.java)
}

if (vpnModel.isConnectedToVpn() && !isServiceRunning) {
Logger.d(TAG, "LanternVpnService isn't running, clearing VPN preference")
vpnModel.setVpnOn(false)
} else if (!vpnModel.isConnectedToVpn() && isServiceRunning) {
Logger.d(TAG, "LanternVpnService is running, updating VPN preference")
vpnModel.setVpnOn(true)
}
Logger.debug(TAG, "onResume() finished at ${System.currentTimeMillis() - start}")
}

}

private fun startLanternService() {
try {
Expand Down Expand Up @@ -279,7 +287,7 @@ class MainActivity :
sendSurveyEvent(it)
}
} catch (e: Exception) {
Logger.error("Survey", "Error fetching loconf", e)
Logger.warn("Survey", "Error fetching loconf", e)
}
}, 2000L)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ open class LanternService : Service(), Runnable {

override fun onCreate() {
super.onCreate()
val serviceIcon: Int = if (LanternApp.session.chatEnabled()) {
R.drawable.status_chat
} else {
R.drawable.status_plain
}
helper = ServiceHelper(this, serviceIcon, R.string.ready_to_connect)
helper = ServiceHelper(this, R.string.ready_to_connect)
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ import java.util.concurrent.atomic.AtomicBoolean

class ServiceHelper(
private val service: Service,
private val defaultIcon: Int?,
private val defaultText: Int
) {
private val foregrounded = AtomicBoolean(false)

fun makeForeground() {
try {
val serviceIcon = defaultIcon
?: if (LanternApp.session.chatEnabled()) {
val serviceIcon = if (LanternApp.sessionInitialized) {
if (LanternApp.session.chatEnabled()) {
R.drawable.status_chat
} else {
R.drawable.status_plain
}
} else {
R.drawable.status_plain
}
if (foregrounded.compareAndSet(false, true)) {
val doIt = {
service.startForeground(
Expand All @@ -47,8 +49,18 @@ class ServiceHelper(
}
} catch (e: Exception) {
Logger.debug("ServiceHelper", "Failed to make service foreground", e)
}
if (foregrounded.compareAndSet(false, true)) {
val doIt = {
service.startForeground(
notificationId,
buildNotification(R.drawable.status_plain, defaultText)
)
}
serviceDeque.push(doIt)
doIt()
}

}
}

fun onDestroy() {
Expand Down
Loading

0 comments on commit 8cfd746

Please sign in to comment.