Skip to content

Commit

Permalink
Merge branch 'main' into jigar/setup-test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Oct 25, 2024
2 parents 30e5a6c + f7dcc9f commit 7822fb1
Show file tree
Hide file tree
Showing 47 changed files with 369 additions and 675 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ jobs:
java-version: 17
cache: 'gradle'

- name: Clean up disk space
run: |
df -h # Check disk space
sudo apt-get clean
sudo apt-get autoremove
- name: Setup protoc
uses: arduino/setup-protoc@v2
with:
Expand Down Expand Up @@ -99,10 +93,20 @@ 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
run: |
sudo apt-get clean
sudo apt-get autoremove -y
sudo apt-get remove --purge $(dpkg --list | grep '^rc' | awk '{print $2}')
- name: Build Android installers
env:
Expand All @@ -111,6 +115,22 @@ jobs:
VERSION: "${{ env.version }}"
run: make package-android

- name: Clean Go module and build cache
run: |
sudo rm -rf /tmp/*
sudo rm -rf /var/cache/*
sudo apt-get clean
sudo apt-get autoremove -y
sudo apt-get remove --purge $(dpkg --list | grep '^rc' | awk '{print $2}')
go clean -modcache
go clean -cache -testcache
df -h
- name: Delete Gradle cache
run: |
sudo rm -rf $HOME/.gradle/caches
echo "Gradle cache deleted successfully"
- uses: actions/upload-artifact@v4
with:
name: android-apk-build
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
20 changes: 17 additions & 3 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,9 +22,11 @@ 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
Expand Down Expand Up @@ -141,6 +142,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 @@ -390,20 +398,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
Loading

0 comments on commit 7822fb1

Please sign in to comment.