Skip to content

Commit

Permalink
ui: distinguish play store installs at runtime
Browse files Browse the repository at this point in the history
This lets us use the same build for both F-Droid and Play Store.

Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Apr 4, 2023
1 parent a68619c commit 185d945
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 0 additions & 3 deletions ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ android {
}
}
buildTypes {
all {
buildConfigField('boolean', 'IS_GOOGLE_PLAY', (findProperty('build.google_play') == 'true').toString())
}
release {
if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release
minifyEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import android.app.AlertDialog
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.wireguard.android.BuildConfig
import com.wireguard.android.R

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

override fun onClick() {
if (BuildConfig.IS_GOOGLE_PLAY) {
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 (installer == "com.android.vending") {
AlertDialog.Builder(context)
.setTitle(R.string.donate_title)
.setMessage(R.string.donate_google_play_disappointment)
.show()
return
}

val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://www.wireguard.com/donations/")
try {
Expand Down

0 comments on commit 185d945

Please sign in to comment.