@@ -9,10 +9,10 @@ import android.app.AlertDialog
9
9
import android.content.Context
10
10
import android.content.Intent
11
11
import android.net.Uri
12
+ import android.os.Build
12
13
import android.util.AttributeSet
13
14
import android.widget.Toast
14
15
import androidx.preference.Preference
15
- import com.wireguard.android.BuildConfig
16
16
import com.wireguard.android.R
17
17
18
18
class DonatePreference (context : Context , attrs : AttributeSet ? ) : Preference(context, attrs) {
@@ -21,13 +21,28 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont
21
21
override fun getTitle () = context.getString(R .string.donate_title)
22
22
23
23
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" ) {
25
39
AlertDialog .Builder (context)
26
40
.setTitle(R .string.donate_title)
27
41
.setMessage(R .string.donate_google_play_disappointment)
28
42
.show()
29
43
return
30
44
}
45
+
31
46
val intent = Intent (Intent .ACTION_VIEW )
32
47
intent.data = Uri .parse(" https://www.wireguard.com/donations/" )
33
48
try {
0 commit comments