Skip to content

Commit

Permalink
track installer package values
Browse files Browse the repository at this point in the history
  • Loading branch information
mopsalarm committed Jul 29, 2023
1 parent d8a2604 commit 2360b28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/pr0gramm/app/services/Track.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Track : InjectorAware {
override val injector by lazy { context.injector }

private val settingsTracker by lazy { instance<SettingsTrackerService>() }
private var installerTracked = false

fun initialize(context: Context) {
this.context = context.applicationContext
Expand Down Expand Up @@ -209,5 +210,15 @@ object Track : InjectorAware {
send("ad_$type")
}

fun installer(name: String?) {
if (!installerTracked) {
installerTracked = true

send("installer") {
putString("package", name.toString())
}
}
}

data class AuthState(val authorized: Boolean, val premium: Boolean)
}
12 changes: 9 additions & 3 deletions app/src/main/java/com/pr0gramm/app/ui/AdService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import java.util.concurrent.TimeUnit

Expand All @@ -54,6 +55,9 @@ class AdService(
return emptyFlow()
}

// we do not show ads currently
return flowOf(AdLoadState.FAILURE)

return channelFlow {
view.adListener = object : TrackingAdListener("b") {
override fun onAdLoaded() {
Expand Down Expand Up @@ -150,20 +154,22 @@ class AdService(
}

fun isSideloaded(): Boolean {
try {
return try {
val name = appContext
.packageManager
.getInstallerPackageName(BuildConfig.APPLICATION_ID)

logger.info { "Installer package is '$name'" }

return name.isNullOrBlank() || name == "com.android.packageinstaller"
Track.installer(name)

name.isNullOrBlank() || name == "com.android.packageinstaller"

} catch (err: Exception) {
logger.warn(err) { "Failed to query for installer package" }

// hm. better be safe and assume not sideloaded
return false
false
}
}

Expand Down

0 comments on commit 2360b28

Please sign in to comment.