@@ -9,10 +9,10 @@ import android.app.AlertDialog
99import android.content.Context
1010import android.content.Intent
1111import android.net.Uri
12+ import android.os.Build
1213import android.util.AttributeSet
1314import android.widget.Toast
1415import androidx.preference.Preference
15- import com.wireguard.android.BuildConfig
1616import com.wireguard.android.R
1717
1818class 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