From b2ace0878ca0a8b47d41f66bfb4552da460f49f3 Mon Sep 17 00:00:00 2001 From: Gilbert Gilb's Date: Sun, 1 May 2022 08:33:31 +0200 Subject: [PATCH] bring back upstream code for release APK check Upstream code checks whether the current APK was signed with the release key for various reasons: - in order to show/hide the "Updates" settings menu - in order to make the "Updates" settings menu searchable or not - in order to check/not check for updates at the application start This behavior was removed in NewPipe SponsorBlock fork, but it probably shouldn't have been: - the newer APK installation won't work if the locally installed APK wasn't signed with the same key - `isReleaseApk` function was still invoked in NewPipe SponsorBlock to allow searching "Updates" settings from settings menu. But as the fingerprint wasn't correct (see 25575ea8b22d), the update settings would not be searchable which is a bug - this is a requirement for F-Droid inclusion as they sign their APKs with their own keys (so the updater wouldn't work) and they explicitly forbid auto-updaters by policy (see also https://github.com/polymorphicshade/NewPipe/issues/8) --- app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt | 6 ++++++ .../schabi/newpipe/settings/MainSettingsFragment.java | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt index e9380c7b2a9..b9d1fe8f9c0 100644 --- a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt @@ -20,6 +20,7 @@ import org.schabi.newpipe.extractor.downloader.Response import org.schabi.newpipe.extractor.exceptions.ReCaptchaException import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired +import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk import org.schabi.newpipe.util.Version import java.io.IOException @@ -69,6 +70,11 @@ class NewVersionWorker( @Throws(IOException::class, ReCaptchaException::class) private fun checkNewVersion() { + // Check if the current apk is a github one or not. + if (!isReleaseApk()) { + return + } + val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext) // Check if the last request has happened a certain time ago // to reduce the number of API requests. diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java index a3b131d75f6..3776d78f679 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -9,6 +9,7 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; +import org.schabi.newpipe.util.ReleaseVersionUtil; public class MainSettingsFragment extends BasePreferenceFragment { public static final boolean DEBUG = MainActivity.DEBUG; @@ -21,6 +22,14 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro setHasOptionsMenu(true); // Otherwise onCreateOptionsMenu is not called + // Check if the app is updatable + if (!ReleaseVersionUtil.isReleaseApk()) { + getPreferenceScreen().removePreference( + findPreference(getString(R.string.update_pref_screen_key))); + + defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply(); + } + // Hide debug preferences in RELEASE build variant if (!DEBUG) { getPreferenceScreen().removePreference(