diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-05-04 16:45:01 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-05-04 16:45:01 +0200 |
commit | cf4fca8086858319f1b395c9059c67b436222cbb (patch) | |
tree | ddbda52a84b59c779e8bb46f0e8c0b2a3c1d0675 /ui/src/main | |
parent | 318f36a20550260042c3e5a21ba06331c5384f51 (diff) |
gradle: remove runtime detection of play store
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main')
5 files changed, 40 insertions, 30 deletions
diff --git a/ui/src/main/AndroidManifest.xml b/ui/src/main/AndroidManifest.xml index e4103b10..42341226 100644 --- a/ui/src/main/AndroidManifest.xml +++ b/ui/src/main/AndroidManifest.xml @@ -104,6 +104,11 @@ <intent-filter> <action android:name="android.intent.action.ACTION_SHUTDOWN" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> + </intent-filter> + </receiver> + + <receiver android:name=".updater.Updater$AppUpdatedReceiver" android:exported="true"> + <intent-filter> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> diff --git a/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt index 2b9312a0..a859bf71 100644 --- a/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt +++ b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.kt @@ -8,25 +8,13 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.util.Log -import com.wireguard.android.activity.MainActivity import com.wireguard.android.backend.WgQuickBackend -import com.wireguard.android.updater.Updater import com.wireguard.android.util.applicationScope import kotlinx.coroutines.launch class BootShutdownReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val action = intent.action ?: return - - if (Intent.ACTION_MY_PACKAGE_REPLACED == action && Updater.installer() == context.packageName) { - /* TODO: does not work because of restrictions placed on broadcast receivers. */ - val start = Intent(context, MainActivity::class.java) - start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(start) - return - } - applicationScope.launch { if (Application.getBackend() !is WgQuickBackend) return@launch val tunnelManager = Application.getTunnelManager() 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 bf0624bc..59980dcb 100644 --- a/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt @@ -8,13 +8,12 @@ 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.updater.Updater import com.wireguard.android.util.ErrorMessages class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) { @@ -24,7 +23,7 @@ class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(cont override fun onClick() { /* Google Play Store forbids links to our donation page. */ - if (Updater.installerIsGooglePlay()) { + if (BuildConfig.IS_GOOGLE_PLAY) { 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 f7d32abb..d3c1b4f8 100644 --- a/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt +++ b/ui/src/main/java/com/wireguard/android/updater/SnackbarUpdateShower.kt @@ -11,6 +11,7 @@ import androidx.fragment.app.FragmentActivity import androidx.lifecycle.lifecycleScope import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar +import com.wireguard.android.BuildConfig import com.wireguard.android.R import com.wireguard.android.util.ErrorMessages import com.wireguard.android.util.QuantityFormatter @@ -88,6 +89,9 @@ 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 d0bd18a1..aa3256d4 100644 --- a/ui/src/main/java/com/wireguard/android/updater/Updater.kt +++ b/ui/src/main/java/com/wireguard/android/updater/Updater.kt @@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat import androidx.core.content.IntentCompat import com.wireguard.android.Application import com.wireguard.android.BuildConfig +import com.wireguard.android.activity.MainActivity import com.wireguard.android.util.UserKnobs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -360,7 +361,7 @@ object Updater { } fun monitorForUpdates() { - if (installerIsGooglePlay()) + if (BuildConfig.IS_GOOGLE_PLAY) return updaterScope.launch { @@ -400,21 +401,34 @@ object Updater { }.launchIn(Application.getCoroutineScope()) } - fun installer(): String { - val context = Application.get().applicationContext - return 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) ?: "" + 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) { + "" } - } catch (_: Throwable) { - "" + if (installer != context.packageName) + return + + /* TODO: does not work because of restrictions placed on broadcast receivers. */ + val start = Intent(context, MainActivity::class.java) + start.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(start) } } - - fun installerIsGooglePlay(): Boolean = installer() == "com.android.vending" }
\ No newline at end of file |