summaryrefslogtreecommitdiffhomepage
path: root/ui/src
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src')
-rw-r--r--ui/src/googleplay/AndroidManifest.xml13
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt4
-rw-r--r--ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt3
-rw-r--r--ui/src/main/java/com/wireguard/android/updater/Updater.kt34
4 files changed, 19 insertions, 35 deletions
diff --git a/ui/src/googleplay/AndroidManifest.xml b/ui/src/googleplay/AndroidManifest.xml
deleted file mode 100644
index f1c05ed6..00000000
--- a/ui/src/googleplay/AndroidManifest.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools">
-
- <uses-permission
- android:name="android.permission.REQUEST_INSTALL_PACKAGES"
- tools:node="remove" />
- <application>
- <receiver
- android:name=".updater.Updater$AppUpdatedReceiver"
- tools:node="remove" />
- </application>
-</manifest>
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..16920923 100644
--- a/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt
+++ b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt
@@ -12,8 +12,8 @@ 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.updater.Updater
import com.wireguard.android.util.ErrorMessages
class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
@@ -23,7 +23,7 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont
override fun onClick() {
/* Google Play Store forbids links to our donation page. */
- if (BuildConfig.IS_GOOGLE_PLAY) {
+ if (Updater.installerIsGooglePlay(context)) {
MaterialAlertDialogBuilder(context)
.setTitle(R.string.donate_title)
.setMessage(R.string.donate_google_play_disappointment)
diff --git a/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt b/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt
index e27e1a5c..7b0c3a60 100644
--- a/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt
+++ b/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt
@@ -88,9 +88,6 @@ object SnackbarUpdateShower {
}
fun attachToActivity(activity: FragmentActivity, view: View, anchor: View?) {
- if (BuildConfig.IS_GOOGLE_PLAY)
- return
-
val snackbar = SwapableSnackbar(activity, view, anchor)
val context = activity.applicationContext
diff --git a/ui/src/main/java/com/wireguard/android/updater/Updater.kt b/ui/src/main/java/com/wireguard/android/updater/Updater.kt
index d6619217..b2f6e52f 100644
--- a/ui/src/main/java/com/wireguard/android/updater/Updater.kt
+++ b/ui/src/main/java/com/wireguard/android/updater/Updater.kt
@@ -53,6 +53,21 @@ object Updater {
private val updaterScope = CoroutineScope(Job() + Dispatchers.IO)
+ private fun installer(context: Context): String = 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) {
+ ""
+ }
+
+ fun installerIsGooglePlay(context: Context): Boolean = installer(context) == "com.android.vending"
+
sealed class Progress {
object Complete : Progress()
class Available(val version: String) : Progress() {
@@ -340,7 +355,7 @@ object Updater {
}
fun monitorForUpdates() {
- if (BuildConfig.IS_GOOGLE_PLAY)
+ if (installerIsGooglePlay(Application.get()))
return
updaterScope.launch {
@@ -382,25 +397,10 @@ object Updater {
class AppUpdatedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
- if (BuildConfig.IS_GOOGLE_PLAY)
- return
-
if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED)
return
- 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) {
- ""
- }
- if (installer != context.packageName)
+ if (installer(context) != context.packageName)
return
/* TODO: does not work because of restrictions placed on broadcast receivers. */