Skip to content

Commit

Permalink
Merge pull request #10790 from TeamNewPipe/update-check-consent
Browse files Browse the repository at this point in the history
Ask for consent before checking for updates
  • Loading branch information
Stypox authored Mar 29, 2024
2 parents 10c57b1 + 9240268 commit f0beb66
Show file tree
Hide file tree
Showing 63 changed files with 129 additions and 73 deletions.
13 changes: 12 additions & 1 deletion app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
public class App extends Application {
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
private static final String TAG = App.class.toString();

private boolean isFirstRun = false;
private static App app;

@NonNull
Expand All @@ -85,7 +87,13 @@ public void onCreate() {
return;
}

// Initialize settings first because others inits can use its values
// check if the last used preference version is set
// to determine whether this is the first app run
final int lastUsedPrefVersion = PreferenceManager.getDefaultSharedPreferences(this)
.getInt(getString(R.string.last_used_preferences_version), -1);
isFirstRun = lastUsedPrefVersion == -1;

// Initialize settings first because other initializations can use its values
NewPipeSettings.initSettings(this);

NewPipe.init(getDownloader(),
Expand Down Expand Up @@ -255,4 +263,7 @@ protected boolean isDisposedRxExceptionsReported() {
return false;
}

public boolean isFirstRun() {
return isFirstRun;
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@
import org.schabi.newpipe.player.event.OnKeyDownListener;
import org.schabi.newpipe.player.helper.PlayerHolder;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.settings.UpdateSettingsFragment;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PeertubeHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ReleaseVersionUtil;
import org.schabi.newpipe.util.SerializedCache;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.StateSaver;
Expand Down Expand Up @@ -167,6 +169,11 @@ protected void onCreate(final Bundle savedInstanceState) {
// if this is enabled by the user.
NotificationWorker.initialize(this);
}
if (!UpdateSettingsFragment.wasUserAskedForConsent(this)
&& !App.getApp().isFirstRun()
&& ReleaseVersionUtil.INSTANCE.isReleaseApk()) {
UpdateSettingsFragment.askForConsentToUpdateChecks(this);
}
}

@Override
Expand All @@ -176,7 +183,8 @@ protected void onPostCreate(final Bundle savedInstanceState) {
final App app = App.getApp();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);

if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
if (prefs.getBoolean(app.getString(R.string.update_app_key), false)
&& prefs.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
// Start the worker which is checking all conditions
// and eventually searching for a new version.
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
Expand Down
16 changes: 5 additions & 11 deletions app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.StringRes;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.App;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.DeviceUtils;

Expand Down Expand Up @@ -44,14 +45,8 @@ public final class NewPipeSettings {
private NewPipeSettings() { }

public static void initSettings(final Context context) {
// check if the last used preference version is set
// to determine whether this is the first app run
final int lastUsedPrefVersion = PreferenceManager.getDefaultSharedPreferences(context)
.getInt(context.getString(R.string.last_used_preferences_version), -1);
final boolean isFirstRun = lastUsedPrefVersion == -1;

// first run migrations, then setDefaultValues, since the latter requires the correct types
SettingMigrations.runMigrationsIfNeeded(context, isFirstRun);
SettingMigrations.runMigrationsIfNeeded(context);

// readAgain is true so that if new settings are added their default value is set
PreferenceManager.setDefaultValues(context, R.xml.main_settings, true);
Expand All @@ -68,7 +63,7 @@ public static void initSettings(final Context context) {
saveDefaultVideoDownloadDirectory(context);
saveDefaultAudioDownloadDirectory(context);

disableMediaTunnelingIfNecessary(context, isFirstRun);
disableMediaTunnelingIfNecessary(context);
}

static void saveDefaultVideoDownloadDirectory(final Context context) {
Expand Down Expand Up @@ -146,8 +141,7 @@ public static boolean showRemoteSearchSuggestions(final Context context,
R.string.show_remote_search_suggestions_key);
}

private static void disableMediaTunnelingIfNecessary(@NonNull final Context context,
final boolean isFirstRun) {
private static void disableMediaTunnelingIfNecessary(@NonNull final Context context) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String disabledTunnelingKey = context.getString(R.string.disable_media_tunneling_key);
final String disabledTunnelingAutomaticallyKey =
Expand All @@ -162,7 +156,7 @@ private static void disableMediaTunnelingIfNecessary(@NonNull final Context cont
prefs.getInt(disabledTunnelingAutomaticallyKey, -1) == 0
&& !prefs.getBoolean(disabledTunnelingKey, false);

if (Boolean.TRUE.equals(isFirstRun)
if (App.getApp().isFirstRun()
|| (wasDeviceBlacklistUpdated && !wasMediaTunnelingEnabledByUser)) {
setMediaTunneling(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.App;
import org.schabi.newpipe.R;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.ErrorUtil;
Expand Down Expand Up @@ -163,15 +164,14 @@ protected void migrate(@NonNull final Context context) {
private static final int VERSION = 6;


public static void runMigrationsIfNeeded(@NonNull final Context context,
final boolean isFirstRun) {
public static void runMigrationsIfNeeded(@NonNull final Context context) {
// setup migrations and check if there is something to do
sp = PreferenceManager.getDefaultSharedPreferences(context);
final String lastPrefVersionKey = context.getString(R.string.last_used_preferences_version);
final int lastPrefVersion = sp.getInt(lastPrefVersionKey, 0);

// no migration to run, already up to date
if (isFirstRun) {
if (App.getApp().isFirstRun()) {
sp.edit().putInt(lastPrefVersionKey, VERSION).apply();
return;
} else if (lastPrefVersion == VERSION) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.schabi.newpipe.settings;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

import androidx.preference.Preference;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.NewVersionWorker;
import org.schabi.newpipe.R;
Expand Down Expand Up @@ -36,4 +39,38 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
findPreference(getString(R.string.manual_update_key))
.setOnPreferenceClickListener(manualUpdateClick);
}

public static void askForConsentToUpdateChecks(final Context context) {
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.check_for_updates))
.setMessage(context.getString(R.string.auto_update_check_description))
.setPositiveButton(context.getString(R.string.yes), (d, w) -> {
d.dismiss();
setAutoUpdateCheckEnabled(context, true);
})
.setNegativeButton(R.string.no, (d, w) -> {
d.dismiss();
// set explicitly to false, since the default is true on previous versions
setAutoUpdateCheckEnabled(context, false);
})
.show();
}

private static void setAutoUpdateCheckEnabled(final Context context, final boolean enabled) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean(context.getString(R.string.update_app_key), enabled)
.putBoolean(context.getString(R.string.update_check_consent_key), true)
.apply();
}

/**
* Whether the user was asked for consent to automatically check for app updates.
* @param context
* @return true if the user was asked for consent, false otherwise
*/
public static boolean wasUserAskedForConsent(final Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.update_check_consent_key), false);
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-ar-rLY/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<string name="short_billion">بليون</string>
<string name="feed_load_error_account_info">تعذر تحميل موجز \'%s\'.</string>
<string name="question_mark">؟</string>
<string name="manual_update_title">التحقق من وجود تحديثات</string>
<string name="check_for_updates">التحقق من وجود تحديثات</string>
<string name="peertube_instance_url_title">مثيلات خوادم پيرتيوب</string>
<string name="more_than_100_videos">+100 فيديو</string>
<string name="short_thousand">ألف</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@
<string name="enqueue_next_stream">وضع التالي على قائمة الانتظار</string>
<string name="enqueued_next">تم وضع التالي على قائمة الانتظار</string>
<string name="processing_may_take_a_moment">جاري المعالجة ... قد يستغرق لحظة</string>
<string name="manual_update_title">التحقق من وجود تحديثات</string>
<string name="check_for_updates">التحقق من وجود تحديثات</string>
<string name="manual_update_description">التحقق يدويا من وجود إصدارات جديدة</string>
<string name="checking_updates_toast">جاري التحقق من وجود تحديثات…</string>
<string name="feed_new_items">عناصر تغذية جديدة</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
<item quantity="one">%s video</item>
<item quantity="other">%s video</item>
</plurals>
<string name="manual_update_title">Yeniləmələri yoxla</string>
<string name="check_for_updates">Yeniləmələri yoxla</string>
<string name="seekbar_preview_thumbnail_title">Axtarış çubuğunun miniatür önizləməsi</string>
<string name="permission_denied">Əməliyyat sistem tərəfindən ləğv edildi</string>
<string name="auto">Avto</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
<string name="enable_streams_notifications_summary">Апавяшчаць аб новых стрымах з падпісак</string>
<string name="streams_notifications_interval_title">Частата праверкі</string>
<string name="streams_notifications_network_title">Патрабуецца падключэнне да сеткі</string>
<string name="manual_update_title">Праверце наяўнасць абнаўленняў</string>
<string name="check_for_updates">Праверце наяўнасць абнаўленняў</string>
<string name="manual_update_description">Праверце новыя версіі ўручную</string>
<string name="autoplay_summary">Аўтаматычны запуск прайгравання — %s</string>
<string name="card">Картка</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
<string name="recaptcha_cookies_cleared">Бисквитките от reCAPTCHA бяха почистени</string>
<string name="checking_updates_toast">Проверяване за актуализации…</string>
<string name="enumeration_comma">,</string>
<string name="manual_update_title">Провери за актуализации</string>
<string name="check_for_updates">Провери за актуализации</string>
<string name="percent">Процент</string>
<string name="unknown_quality">Неизвестно качество</string>
<string name="unknown_format">Неизвестен формат</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bn-rBD/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
<string name="default_content_country_title">কনটেন্টের জন্য পূর্বনির্ধারিত দেশ</string>
<string name="external_player_unsupported_link_type">বাইরের প্লেয়ারসমূহ এ ধরনের লিঙ্কসমূহ সমর্থন করে না</string>
<string name="msg_calculating_hash">হ্যাশ হিসাব করা হচ্ছে</string>
<string name="manual_update_title">আপডেট চেক করো</string>
<string name="check_for_updates">আপডেট চেক করো</string>
<plurals name="watching">
<item quantity="one">%s জন দেখছে</item>
<item quantity="other">%s জন দেখছে</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@
<string name="detail_pinned_comment_view_description">পিনকৃত মন্তব্য</string>
<string name="notifications">বিজ্ঞপ্তি</string>
<string name="checking_updates_toast">হালনাগাদ দেখা হচ্ছে …</string>
<string name="manual_update_title">হালনাগাদ আছে কিনা দেখো</string>
<string name="check_for_updates">হালনাগাদ আছে কিনা দেখো</string>
<string name="start_main_player_fullscreen_title">মূল প্লেয়ার ফুল স্ক্রীন এ শুরু করুন</string>
<string name="feed_new_items">ধারার নতুন ভুক্তি</string>
<string name="error_report_channel_name">ত্রুটি প্রতিবেদন এর বিজ্ঞপ্তি</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@
<string name="start_main_player_fullscreen_summary">Si la rotació automàtica està bloquejada, no inicieu vídeos al mini reproductor, sinó que aneu directament al mode de pantalla completa. Podeu accedir igualment al mini reproductor sortint de pantalla completa</string>
<string name="error_report_channel_name">Notificació d\'informe d\'error</string>
<string name="crash_the_player">Tancar abruptament el reproductor</string>
<string name="manual_update_title">Comprovar si hi ha actualitzacions</string>
<string name="check_for_updates">Comprovar si hi ha actualitzacions</string>
<string name="manual_update_description">Comprovar manualment si hi ha noves versions</string>
<plurals name="download_finished_notification">
<item quantity="one">Baixada finalitzada</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ckb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@
<string name="error_report_notification_title">نیوپایپ تووشی کێشەیەک بوو ، کرتە بکە بۆ سکاڵاکردن</string>
<string name="show_crash_the_player_title">پیشاندانی ”کڕاش کردنی لێدەرەکە“</string>
<string name="create_error_notification">سازاندنی پەیامی کێشەیەک</string>
<string name="manual_update_title">پشکنین بۆ نوێکردنەوە</string>
<string name="check_for_updates">پشکنین بۆ نوێکردنەوە</string>
<string name="error_report_channel_name">کێشە لە سکاڵا کردنی پەیام</string>
<string name="error_report_channel_description">پەیامەکانی سکاڵاکردن لە کێشەکان</string>
<string name="feed_new_items">بابەتە نوێیەکانی فیید</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@
<string name="start_main_player_fullscreen_title">Spustit hlavní přehrávač na celé obrazovce</string>
<string name="processing_may_take_a_moment">Zpracovávám... může trvat moment</string>
<string name="manual_update_description">Ručně zkontrolovat zda je k dispozici nová verze</string>
<string name="manual_update_title">Kontrola aktualizací</string>
<string name="check_for_updates">Kontrola aktualizací</string>
<string name="error_report_notification_title">NewPipe narazil na problém, klikněte pro nahlášení</string>
<string name="error_report_notification_toast">Došlo k chybě, více v oznámení</string>
<string name="create_error_notification">Vytvořit oznámení o chybě</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
<string name="checking_updates_toast">Tjekker efter opdateringer…</string>
<string name="recovering">gendanner</string>
<string name="feed_load_error_fast_unknown">\"Hurtig feed\"-tilstand oplyser ikke mere info om dette.</string>
<string name="manual_update_title">Tjek efter opdateringer</string>
<string name="check_for_updates">Tjek efter opdateringer</string>
<string name="remove_watched_popup_title">Fjern sete videoer\?</string>
<string name="disable_media_tunneling_summary">Deaktivér medietunneling, hvis du oplever en sort skærm eller hakken ved videoafspilning.</string>
<string name="error_report_open_github_notice">Tjek venligst, om der allerede findes et problem, der diskuterer dit nedbrud. Når du opretter flere tickets, tager du tid fra os, som vi kunne bruge på at løse den faktiske fejl.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@
<string name="enqueued_next">Als Nächstes eingereiht</string>
<string name="enqueue_next_stream">Als Nächstes in Wiedergabe einreihen</string>
<string name="processing_may_take_a_moment">Verarbeite … Kann einen Moment dauern</string>
<string name="manual_update_title">Nach Aktualisierungen suchen</string>
<string name="check_for_updates">Nach Aktualisierungen suchen</string>
<string name="checking_updates_toast">Suche nach Aktualisierungen …</string>
<string name="manual_update_description">Manuelle Prüfung auf neue Versionen</string>
<string name="feed_new_items">Neue Feed-Elemente</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@
<string name="processing_may_take_a_moment">Επεξεργασία... Μπορεί να πάρει λίγο χρόνο</string>
<string name="checking_updates_toast">Έλεγχος αναβάθμισης…</string>
<string name="manual_update_description">Χειροκίνητος έλεγχος για νέα έκδοση</string>
<string name="manual_update_title">Έλεγχος αναβάθμισης</string>
<string name="check_for_updates">Έλεγχος αναβάθμισης</string>
<string name="feed_new_items">Νέα αντικείμενα τροφοδοσίας</string>
<string name="show_crash_the_player_title">Εμφάνιση «Κατάρρευσης αναπαραγωγέα»</string>
<string name="show_crash_the_player_summary">Εμφανίζει μια επιλογή κατάρρευσης κατά τη χρήση του αναπαραγωγέα</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@
<string name="enqueued_next">Añadido el siguiente vídeo a la cola</string>
<string name="enqueue_next_stream">Añadir el siguiente vídeo a la cola</string>
<string name="processing_may_take_a_moment">Procesando… Podría tomar un momento</string>
<string name="manual_update_title">Buscar actualizaciones</string>
<string name="check_for_updates">Buscar actualizaciones</string>
<string name="manual_update_description">Buscar nuevas versiones manualmente</string>
<string name="checking_updates_toast">Buscando actualizaciones…</string>
<string name="feed_new_items">Nuevos elementos en el muro</string>
Expand Down
Loading

0 comments on commit f0beb66

Please sign in to comment.