Skip to content

Commit 33a8a51

Browse files
committed
gradle: restore play runtime detection
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 40eaa54 commit 33a8a51

File tree

5 files changed

+19
-41
lines changed

5 files changed

+19
-41
lines changed

ui/build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ android {
2626
versionCode = providers.gradleProperty("wireguardVersionCode").get().toInt()
2727
versionName = providers.gradleProperty("wireguardVersionName").get()
2828
buildConfigField("int", "MIN_SDK_VERSION", minSdk.toString())
29-
buildConfigField("boolean", "IS_GOOGLE_PLAY", false.toString())
3029
}
3130
compileOptions {
3231
sourceCompatibility = JavaVersion.VERSION_17
@@ -49,11 +48,6 @@ android {
4948
applicationIdSuffix = ".debug"
5049
versionNameSuffix = "-debug"
5150
}
52-
create("googleplay") {
53-
initWith(getByName("release"))
54-
matchingFallbacks += "release"
55-
buildConfigField("boolean", "IS_GOOGLE_PLAY", true.toString())
56-
}
5751
}
5852
lint {
5953
disable += "LongLogTag"

ui/src/googleplay/AndroidManifest.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import android.util.AttributeSet
1212
import android.widget.Toast
1313
import androidx.preference.Preference
1414
import com.google.android.material.dialog.MaterialAlertDialogBuilder
15-
import com.wireguard.android.BuildConfig
1615
import com.wireguard.android.R
16+
import com.wireguard.android.updater.Updater
1717
import com.wireguard.android.util.ErrorMessages
1818

1919
class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
@@ -23,7 +23,7 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont
2323

2424
override fun onClick() {
2525
/* Google Play Store forbids links to our donation page. */
26-
if (BuildConfig.IS_GOOGLE_PLAY) {
26+
if (Updater.installerIsGooglePlay(context)) {
2727
MaterialAlertDialogBuilder(context)
2828
.setTitle(R.string.donate_title)
2929
.setMessage(R.string.donate_google_play_disappointment)

ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ object SnackbarUpdateShower {
8888
}
8989

9090
fun attachToActivity(activity: FragmentActivity, view: View, anchor: View?) {
91-
if (BuildConfig.IS_GOOGLE_PLAY)
92-
return
93-
9491
val snackbar = SwapableSnackbar(activity, view, anchor)
9592
val context = activity.applicationContext
9693

ui/src/main/java/com/wireguard/android/updater/Updater.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ object Updater {
5353

5454
private val updaterScope = CoroutineScope(Job() + Dispatchers.IO)
5555

56+
private fun installer(context: Context): String = try {
57+
val packageName = context.packageName
58+
val pm = context.packageManager
59+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
60+
pm.getInstallSourceInfo(packageName).installingPackageName ?: ""
61+
} else {
62+
@Suppress("DEPRECATION")
63+
pm.getInstallerPackageName(packageName) ?: ""
64+
}
65+
} catch (_: Throwable) {
66+
""
67+
}
68+
69+
fun installerIsGooglePlay(context: Context): Boolean = installer(context) == "com.android.vending"
70+
5671
sealed class Progress {
5772
object Complete : Progress()
5873
class Available(val version: String) : Progress() {
@@ -340,7 +355,7 @@ object Updater {
340355
}
341356

342357
fun monitorForUpdates() {
343-
if (BuildConfig.IS_GOOGLE_PLAY)
358+
if (installerIsGooglePlay(Application.get()))
344359
return
345360

346361
updaterScope.launch {
@@ -382,25 +397,10 @@ object Updater {
382397

383398
class AppUpdatedReceiver : BroadcastReceiver() {
384399
override fun onReceive(context: Context, intent: Intent) {
385-
if (BuildConfig.IS_GOOGLE_PLAY)
386-
return
387-
388400
if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED)
389401
return
390402

391-
val installer = try {
392-
val packageName = context.packageName
393-
val pm = context.packageManager
394-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
395-
pm.getInstallSourceInfo(packageName).installingPackageName ?: ""
396-
} else {
397-
@Suppress("DEPRECATION")
398-
pm.getInstallerPackageName(packageName) ?: ""
399-
}
400-
} catch (_: Throwable) {
401-
""
402-
}
403-
if (installer != context.packageName)
403+
if (installer(context) != context.packageName)
404404
return
405405

406406
/* TODO: does not work because of restrictions placed on broadcast receivers. */

0 commit comments

Comments
 (0)