diff options
Diffstat (limited to 'ui/src/main/java/com/wireguard')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt index 59980dcb..bb49c7e1 100644 --- a/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt @@ -8,11 +8,11 @@ package com.wireguard.android.preference import android.content.Context import android.content.Intent import android.net.Uri +import android.os.Build import android.util.AttributeSet import android.widget.Toast import androidx.preference.Preference import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.wireguard.android.BuildConfig import com.wireguard.android.R import com.wireguard.android.util.ErrorMessages @@ -22,8 +22,21 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont override fun getTitle() = context.getString(R.string.donate_title) override fun onClick() { + val installer = try { + val packageName = context.packageName + val pm = context.packageManager + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + pm.getInstallSourceInfo(packageName).installingPackageName ?: "" + } else { + @Suppress("DEPRECATION") + pm.getInstallerPackageName(packageName) ?: "" + } + } catch (_: Throwable) { + "" + } + /* Google Play Store forbids links to our donation page. */ - if (BuildConfig.IS_GOOGLE_PLAY) { + if (installer == "com.android.vending") { MaterialAlertDialogBuilder(context) .setTitle(R.string.donate_title) .setMessage(R.string.donate_google_play_disappointment) |