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 25575ea8b2), 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)
This commit is contained in:
Gilbert Gilb's 2022-05-01 08:33:31 +02:00
parent 25575ea8b2
commit b2ace0878c
2 changed files with 15 additions and 0 deletions

View file

@ -20,6 +20,7 @@ import org.schabi.newpipe.extractor.downloader.Response
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry
import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired
import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk
import org.schabi.newpipe.util.Version import org.schabi.newpipe.util.Version
import java.io.IOException import java.io.IOException
@ -69,6 +70,11 @@ class NewVersionWorker(
@Throws(IOException::class, ReCaptchaException::class) @Throws(IOException::class, ReCaptchaException::class)
private fun checkNewVersion() { private fun checkNewVersion() {
// Check if the current apk is a github one or not.
if (!isReleaseApk()) {
return
}
val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext) val prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext)
// Check if the last request has happened a certain time ago // Check if the last request has happened a certain time ago
// to reduce the number of API requests. // to reduce the number of API requests.

View file

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.ReleaseVersionUtil;
public class MainSettingsFragment extends BasePreferenceFragment { public class MainSettingsFragment extends BasePreferenceFragment {
public static final boolean DEBUG = MainActivity.DEBUG; public static final boolean DEBUG = MainActivity.DEBUG;
@ -21,6 +22,14 @@ public class MainSettingsFragment extends BasePreferenceFragment {
setHasOptionsMenu(true); // Otherwise onCreateOptionsMenu is not called 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 // Hide debug preferences in RELEASE build variant
if (!DEBUG) { if (!DEBUG) {
getPreferenceScreen().removePreference( getPreferenceScreen().removePreference(