Skip to content

Commit 8cfd746

Browse files
committed
Merge remote-tracking branch 'origin/main' into atavism/7.9.8
2 parents 3037e9b + 3e95708 commit 8cfd746

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+330
-651
lines changed

.github/workflows/build-android.yml

+4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ jobs:
9393
env:
9494
ANDROID_INTERSTITIAL_AD_ID: ${{ secrets.INTERSTITIAL_AD_UNIT_ID }}
9595
IOS_INTERSTITIAL_AD_ID: ${{ secrets.INTERSTITIAL_AD_UNIT_ID_IOS }}
96+
TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID: ${{ secrets.TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID }}
97+
TAPSELL_INTERSTITIAL_ZONE_ID: ${{ secrets.TAPSELL_INTERSTITIAL_ZONE_ID }}
9698
run: |
9799
touch app.env
98100
echo "Android_interstitialAd=$ANDROID_INTERSTITIAL_AD_ID" > app.env
99101
echo "IOS_interstitialAd=$IOS_INTERSTITIAL_AD_ID" >> app.env
102+
echo "VideoInterstitialZoneId=$TAPSELL_VIDEO_INTERSTITIAL_ZONE_ID" >> app.env
103+
echo "InterstitialZoneId=$TAPSELL_INTERSTITIAL_ZONE_ID" >> app.env
100104
101105
102106
- name: Clean packages to save disk space

.github/workflows/build-darwin.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ jobs:
131131
make package-darwin
132132
env:
133133
VERSION: "${{ env.version }}"
134-
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERT }}
135-
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERT_PASS }}
134+
MACOS_CERTIFICATE: ${{ secrets.MACOS_BNS_CERT }}
135+
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_BNS_CERT_PASS }}
136136

137137
- name: Install s3cmd
138138
run: pip install s3cmd

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ tag: require-version
230230
git push
231231

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

236236
guard-%:

android/app/src/main/AndroidManifest.xml

+10-4
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
android:name="org.getlantern.lantern.LanternApp"
3535
android:allowBackup="false"
3636
android:hardwareAccelerated="true"
37-
android:resizeableActivity="false"
3837
android:icon="@drawable/app_icon"
3938
android:label="@string/app_name"
39+
android:largeHeap="true"
4040
android:networkSecurityConfig="@xml/network_security_config"
4141
android:persistent="true"
4242
android:requestLegacyExternalStorage="true"
43+
android:resizeableActivity="false"
4344
android:theme="@style/AppTheme"
44-
android:largeHeap="true"
4545
tools:replace="allowBackup, label"
4646
tools:targetApi="n">
4747

@@ -88,14 +88,20 @@
8888
</intent-filter>
8989
</activity>
9090

91+
92+
<activity
93+
android:name=".activity.WebViewActivity"
94+
android:exported="false" />
95+
9196
<service
9297
android:name=".service.LanternService"
9398
android:enabled="true"
9499
android:exported="false"
95100
android:stopWithTask="false" />
96101

97-
<receiver android:name=".model.DeclineCallBroadcastReceiver"
98-
android:exported="false"/>
102+
<receiver
103+
android:name=".model.DeclineCallBroadcastReceiver"
104+
android:exported="false" />
99105

100106
<receiver
101107
android:name="org.getlantern.lantern.notification.NotificationReceiver"

android/app/src/main/kotlin/io/lantern/apps/AppData.kt

+21-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import android.content.pm.ApplicationInfo
44
import android.content.pm.PackageManager
55
import android.graphics.Bitmap
66
import android.graphics.Canvas
7+
import android.graphics.drawable.BitmapDrawable
78
import android.graphics.drawable.Drawable
9+
import org.getlantern.mobilesdk.Logger
810
import java.io.ByteArrayOutputStream
911

1012
data class AppData(
@@ -17,20 +19,31 @@ data class AppData(
1719
val icon: ByteArray? by lazy {
1820
try {
1921
val icon: Drawable = packageManager.getApplicationIcon(packageName)
20-
val bitmap: Bitmap = Bitmap.createBitmap(
21-
icon.intrinsicWidth,
22-
icon.intrinsicHeight,
23-
Bitmap.Config.ARGB_8888
24-
)
25-
val canvas: Canvas = Canvas(bitmap)
26-
icon.setBounds(0, 0, canvas.width, canvas.height)
27-
icon.draw(canvas)
22+
val bitmap = drawableToBitmap(icon)
2823
val stream = ByteArrayOutputStream()
2924
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
3025
stream.toByteArray()
3126
} catch (e: Exception) {
27+
Logger.e("AppData", "Error converting icon to byte array", e)
3228
e.printStackTrace()
3329
null
3430
}
3531
}
32+
33+
private fun drawableToBitmap(drawable: Drawable): Bitmap {
34+
if (drawable is BitmapDrawable) {
35+
return drawable.bitmap
36+
}
37+
val bitmap = Bitmap.createBitmap(
38+
drawable.intrinsicWidth,
39+
drawable.intrinsicHeight,
40+
Bitmap.Config.ARGB_8888
41+
)
42+
val canvas = Canvas(bitmap)
43+
drawable.setBounds(0, 0, canvas.width, canvas.height)
44+
drawable.draw(canvas)
45+
return bitmap
46+
}
47+
48+
3649
}

android/app/src/main/kotlin/io/lantern/apps/AppsDataProvider.kt

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package io.lantern.apps
33
import android.Manifest
44
import android.content.pm.ApplicationInfo
55
import android.content.pm.PackageManager
6+
import android.graphics.Bitmap
7+
import android.graphics.Canvas
8+
import android.graphics.drawable.BitmapDrawable
9+
import android.graphics.drawable.Drawable
10+
import java.io.ByteArrayOutputStream
611

712
class AppsDataProvider(
813
private val packageManager: PackageManager,
@@ -25,6 +30,7 @@ class AppsDataProvider(
2530
.toList().sortedBy { it.name }
2631
}
2732

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

50+
51+
4452
companion object {
4553
private val TAG = AppsDataProvider::class.java.name
4654
}

android/app/src/main/kotlin/io/lantern/model/SessionModel.kt

+22-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import androidx.core.content.ContextCompat
1212
import androidx.webkit.ProxyConfig
1313
import androidx.webkit.ProxyController
1414
import androidx.webkit.WebViewFeature
15-
import com.google.protobuf.ByteString
1615
import internalsdk.SessionModel
1716
import internalsdk.SessionModelOpts
1817
import io.flutter.embedding.engine.FlutterEngine
@@ -23,14 +22,17 @@ import io.lantern.model.dbadapter.DBAdapter
2322
import kotlinx.coroutines.CoroutineScope
2423
import kotlinx.coroutines.Dispatchers
2524
import kotlinx.coroutines.launch
25+
import kotlinx.serialization.json.add
2626
import kotlinx.serialization.json.buildJsonArray
2727
import kotlinx.serialization.json.buildJsonObject
2828
import kotlinx.serialization.json.put
29+
import kotlinx.serialization.json.putJsonArray
2930
import org.getlantern.lantern.BuildConfig
3031
import org.getlantern.lantern.LanternApp
3132
import org.getlantern.lantern.activity.WebViewActivity
3233
import org.getlantern.lantern.model.InAppBilling
3334
import org.getlantern.lantern.model.Utils
35+
import org.getlantern.lantern.plausible.Plausible
3436
import org.getlantern.lantern.util.AutoUpdater
3537
import org.getlantern.lantern.util.LanternProxySelector
3638
import org.getlantern.lantern.util.PaymentsUtil
@@ -135,6 +137,13 @@ class SessionModel internal constructor(
135137
result.success(LanternApp.getInAppBilling().isPlayStoreAvailable())
136138
}
137139

140+
"trackUserAction" -> {
141+
val props: Map<String, String> = mapOf("title" to call.argument("title")!!)
142+
Plausible.event(
143+
call.argument("name")!!, url = call.argument("url")!!, props = props
144+
)
145+
}
146+
138147
else -> super.doOnMethodCall(call, result)
139148
}
140149
}
@@ -199,7 +208,10 @@ class SessionModel internal constructor(
199208
}
200209

201210
fun setUserIdAndToken(userId: Long, token: String) {
202-
model.invokeMethod("setUserIdAndToken", Arguments(mapOf("userId" to userId, "token" to token)))
211+
model.invokeMethod(
212+
"setUserIdAndToken",
213+
Arguments(mapOf("userId" to userId, "token" to token))
214+
)
203215
}
204216

205217
fun setUserPro(isPro: Boolean) {
@@ -381,20 +393,26 @@ class SessionModel internal constructor(
381393
// this ends up in memory out of exception
382394
CoroutineScope(Dispatchers.IO).launch {
383395
try {
396+
val start = System.currentTimeMillis()
384397
val appsList = appsDataProvider.listOfApps()
385398
// First add just the app names to get a list quickly
386399
val apps = buildJsonArray {
387400
appsList.forEach { app ->
388401
add(
389402
buildJsonObject {
390-
val byte = ByteString.copyFrom(app.icon)
403+
val byte = app.icon!!
391404
put("packageName", app.packageName)
392405
put("name", app.name)
393-
put("icon", byte.toByteArray().toUByteArray().joinToString(", "))
406+
putJsonArray("icon") {
407+
byte.toUByteArray().forEach { add(it.toInt()) }
408+
}
394409
}
395410
)
396411
}
397412
}
413+
val end = System.currentTimeMillis()
414+
Logger.debug(TAG, "Time taken to get app data: ${end - start} ms")
415+
398416
model.invokeMethod(
399417
"updateAppsData",
400418
Arguments(mapOf("appsList" to apps.toString()))

android/app/src/main/kotlin/org/getlantern/lantern/LanternApp.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ open class LanternApp : Application() {
5757
private lateinit var appContext: Context
5858
private lateinit var inAppBilling: InAppBilling
5959
lateinit var session: SessionModel
60+
val sessionInitialized = ::session.isInitialized
6061
private lateinit var goSession: internalsdk.SessionModel
6162
var messaging: MessagingHolder = MessagingHolder()
6263

@@ -69,9 +70,10 @@ open class LanternApp : Application() {
6970
fun getInAppBilling(): InAppBilling {
7071
return inAppBilling
7172
}
73+
7274
@JvmStatic
73-
fun setInAppBilling(inAppBilling: InAppBilling) {
74-
this.inAppBilling= inAppBilling
75+
fun setInAppBilling(inAppBilling: InAppBilling) {
76+
this.inAppBilling = inAppBilling
7577
}
7678

7779

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

8385
@JvmStatic
84-
fun setGoSession(sessionModel :internalsdk.SessionModel) {
85-
goSession= sessionModel
86+
fun setGoSession(sessionModel: internalsdk.SessionModel) {
87+
goSession = sessionModel
8688
}
8789
}
8890
}

android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt

+20-12
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,8 @@ class MainActivity :
193193
}
194194

195195
override fun onResume() {
196-
val start = System.currentTimeMillis()
197196
super.onResume()
198-
199-
val isServiceRunning = Utils.isServiceRunning(activity, LanternVpnService::class.java)
200-
if (vpnModel.isConnectedToVpn() && !isServiceRunning) {
201-
Logger.d(TAG, "LanternVpnService isn't running, clearing VPN preference")
202-
vpnModel.setVpnOn(false)
203-
} else if (!vpnModel.isConnectedToVpn() && isServiceRunning) {
204-
Logger.d(TAG, "LanternVpnService is running, updating VPN preference")
205-
vpnModel.setVpnOn(true)
206-
}
207-
Logger.debug(TAG, "onResume() finished at ${System.currentTimeMillis() - start}")
197+
checkVPNStatus();
208198
}
209199

210200
override fun onDestroy() {
@@ -233,6 +223,24 @@ class MainActivity :
233223
}
234224
}
235225

226+
private fun checkVPNStatus() {
227+
CoroutineScope(Dispatchers.IO).launch {
228+
val start = System.currentTimeMillis()
229+
val isServiceRunning = withContext(Dispatchers.Main) {
230+
Utils.isServiceRunning(activity, LanternVpnService::class.java)
231+
}
232+
233+
if (vpnModel.isConnectedToVpn() && !isServiceRunning) {
234+
Logger.d(TAG, "LanternVpnService isn't running, clearing VPN preference")
235+
vpnModel.setVpnOn(false)
236+
} else if (!vpnModel.isConnectedToVpn() && isServiceRunning) {
237+
Logger.d(TAG, "LanternVpnService is running, updating VPN preference")
238+
vpnModel.setVpnOn(true)
239+
}
240+
Logger.debug(TAG, "onResume() finished at ${System.currentTimeMillis() - start}")
241+
}
242+
243+
}
236244

237245
private fun startLanternService() {
238246
try {
@@ -279,7 +287,7 @@ class MainActivity :
279287
sendSurveyEvent(it)
280288
}
281289
} catch (e: Exception) {
282-
Logger.error("Survey", "Error fetching loconf", e)
290+
Logger.warn("Survey", "Error fetching loconf", e)
283291
}
284292
}, 2000L)
285293
}

android/app/src/main/kotlin/org/getlantern/lantern/service/LanternService.kt

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ open class LanternService : Service(), Runnable {
4242

4343
override fun onCreate() {
4444
super.onCreate()
45-
val serviceIcon: Int = if (LanternApp.session.chatEnabled()) {
46-
R.drawable.status_chat
47-
} else {
48-
R.drawable.status_plain
49-
}
50-
helper = ServiceHelper(this, serviceIcon, R.string.ready_to_connect)
45+
helper = ServiceHelper(this, R.string.ready_to_connect)
5146
}
5247

5348
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

android/app/src/main/kotlin/org/getlantern/lantern/service/ServiceHelper.kt

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ import java.util.concurrent.atomic.AtomicBoolean
2222

2323
class ServiceHelper(
2424
private val service: Service,
25-
private val defaultIcon: Int?,
2625
private val defaultText: Int
2726
) {
2827
private val foregrounded = AtomicBoolean(false)
2928

3029
fun makeForeground() {
3130
try {
32-
val serviceIcon = defaultIcon
33-
?: if (LanternApp.session.chatEnabled()) {
31+
val serviceIcon = if (LanternApp.sessionInitialized) {
32+
if (LanternApp.session.chatEnabled()) {
3433
R.drawable.status_chat
3534
} else {
3635
R.drawable.status_plain
3736
}
37+
} else {
38+
R.drawable.status_plain
39+
}
3840
if (foregrounded.compareAndSet(false, true)) {
3941
val doIt = {
4042
service.startForeground(
@@ -47,8 +49,18 @@ class ServiceHelper(
4749
}
4850
} catch (e: Exception) {
4951
Logger.debug("ServiceHelper", "Failed to make service foreground", e)
50-
}
52+
if (foregrounded.compareAndSet(false, true)) {
53+
val doIt = {
54+
service.startForeground(
55+
notificationId,
56+
buildNotification(R.drawable.status_plain, defaultText)
57+
)
58+
}
59+
serviceDeque.push(doIt)
60+
doIt()
61+
}
5162

63+
}
5264
}
5365

5466
fun onDestroy() {

0 commit comments

Comments
 (0)