Skip to content

Commit 185d945

Browse files
committed
ui: distinguish play store installs at runtime
This lets us use the same build for both F-Droid and Play Store. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent a68619c commit 185d945

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

ui/build.gradle

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ android {
4848
}
4949
}
5050
buildTypes {
51-
all {
52-
buildConfigField('boolean', 'IS_GOOGLE_PLAY', (findProperty('build.google_play') == 'true').toString())
53-
}
5451
release {
5552
if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release
5653
minifyEnabled true

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import android.app.AlertDialog
99
import android.content.Context
1010
import android.content.Intent
1111
import android.net.Uri
12+
import android.os.Build
1213
import android.util.AttributeSet
1314
import android.widget.Toast
1415
import androidx.preference.Preference
15-
import com.wireguard.android.BuildConfig
1616
import com.wireguard.android.R
1717

1818
class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
@@ -21,13 +21,28 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont
2121
override fun getTitle() = context.getString(R.string.donate_title)
2222

2323
override fun onClick() {
24-
if (BuildConfig.IS_GOOGLE_PLAY) {
24+
val installer = try {
25+
val packageName = context.packageName
26+
val pm = context.packageManager
27+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
28+
pm.getInstallSourceInfo(packageName).installingPackageName
29+
} else {
30+
@Suppress("DEPRECATION")
31+
pm.getInstallerPackageName(packageName)
32+
}
33+
} catch (_: Throwable) {
34+
""
35+
}
36+
37+
/* Google Play store forbids links to our donation page. */
38+
if (installer == "com.android.vending") {
2539
AlertDialog.Builder(context)
2640
.setTitle(R.string.donate_title)
2741
.setMessage(R.string.donate_google_play_disappointment)
2842
.show()
2943
return
3044
}
45+
3146
val intent = Intent(Intent.ACTION_VIEW)
3247
intent.data = Uri.parse("https://www.wireguard.com/donations/")
3348
try {

0 commit comments

Comments
 (0)