Skip to content

Commit f0beb66

Browse files
authored
Merge pull request #10790 from TeamNewPipe/update-check-consent
Ask for consent before checking for updates
2 parents 10c57b1 + 9240268 commit f0beb66

63 files changed

Lines changed: 129 additions & 73 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
public class App extends Application {
6161
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
6262
private static final String TAG = App.class.toString();
63+
64+
private boolean isFirstRun = false;
6365
private static App app;
6466

6567
@NonNull
@@ -85,7 +87,13 @@ public void onCreate() {
8587
return;
8688
}
8789

88-
// Initialize settings first because others inits can use its values
90+
// check if the last used preference version is set
91+
// to determine whether this is the first app run
92+
final int lastUsedPrefVersion = PreferenceManager.getDefaultSharedPreferences(this)
93+
.getInt(getString(R.string.last_used_preferences_version), -1);
94+
isFirstRun = lastUsedPrefVersion == -1;
95+
96+
// Initialize settings first because other initializations can use its values
8997
NewPipeSettings.initSettings(this);
9098

9199
NewPipe.init(getDownloader(),
@@ -255,4 +263,7 @@ protected boolean isDisposedRxExceptionsReported() {
255263
return false;
256264
}
257265

266+
public boolean isFirstRun() {
267+
return isFirstRun;
268+
}
258269
}

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@
7979
import org.schabi.newpipe.player.event.OnKeyDownListener;
8080
import org.schabi.newpipe.player.helper.PlayerHolder;
8181
import org.schabi.newpipe.player.playqueue.PlayQueue;
82+
import org.schabi.newpipe.settings.UpdateSettingsFragment;
8283
import org.schabi.newpipe.util.Constants;
8384
import org.schabi.newpipe.util.DeviceUtils;
8485
import org.schabi.newpipe.util.KioskTranslator;
8586
import org.schabi.newpipe.util.Localization;
8687
import org.schabi.newpipe.util.NavigationHelper;
8788
import org.schabi.newpipe.util.PeertubeHelper;
8889
import org.schabi.newpipe.util.PermissionHelper;
90+
import org.schabi.newpipe.util.ReleaseVersionUtil;
8991
import org.schabi.newpipe.util.SerializedCache;
9092
import org.schabi.newpipe.util.ServiceHelper;
9193
import org.schabi.newpipe.util.StateSaver;
@@ -167,6 +169,11 @@ protected void onCreate(final Bundle savedInstanceState) {
167169
// if this is enabled by the user.
168170
NotificationWorker.initialize(this);
169171
}
172+
if (!UpdateSettingsFragment.wasUserAskedForConsent(this)
173+
&& !App.getApp().isFirstRun()
174+
&& ReleaseVersionUtil.INSTANCE.isReleaseApk()) {
175+
UpdateSettingsFragment.askForConsentToUpdateChecks(this);
176+
}
170177
}
171178

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

179-
if (prefs.getBoolean(app.getString(R.string.update_app_key), true)) {
186+
if (prefs.getBoolean(app.getString(R.string.update_app_key), false)
187+
&& prefs.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
180188
// Start the worker which is checking all conditions
181189
// and eventually searching for a new version.
182190
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);

app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import androidx.annotation.StringRes;
1212
import androidx.preference.PreferenceManager;
1313

14+
import org.schabi.newpipe.App;
1415
import org.schabi.newpipe.R;
1516
import org.schabi.newpipe.util.DeviceUtils;
1617

@@ -44,14 +45,8 @@ public final class NewPipeSettings {
4445
private NewPipeSettings() { }
4546

4647
public static void initSettings(final Context context) {
47-
// check if the last used preference version is set
48-
// to determine whether this is the first app run
49-
final int lastUsedPrefVersion = PreferenceManager.getDefaultSharedPreferences(context)
50-
.getInt(context.getString(R.string.last_used_preferences_version), -1);
51-
final boolean isFirstRun = lastUsedPrefVersion == -1;
52-
5348
// first run migrations, then setDefaultValues, since the latter requires the correct types
54-
SettingMigrations.runMigrationsIfNeeded(context, isFirstRun);
49+
SettingMigrations.runMigrationsIfNeeded(context);
5550

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

71-
disableMediaTunnelingIfNecessary(context, isFirstRun);
66+
disableMediaTunnelingIfNecessary(context);
7267
}
7368

7469
static void saveDefaultVideoDownloadDirectory(final Context context) {
@@ -146,8 +141,7 @@ public static boolean showRemoteSearchSuggestions(final Context context,
146141
R.string.show_remote_search_suggestions_key);
147142
}
148143

149-
private static void disableMediaTunnelingIfNecessary(@NonNull final Context context,
150-
final boolean isFirstRun) {
144+
private static void disableMediaTunnelingIfNecessary(@NonNull final Context context) {
151145
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
152146
final String disabledTunnelingKey = context.getString(R.string.disable_media_tunneling_key);
153147
final String disabledTunnelingAutomaticallyKey =
@@ -162,7 +156,7 @@ private static void disableMediaTunnelingIfNecessary(@NonNull final Context cont
162156
prefs.getInt(disabledTunnelingAutomaticallyKey, -1) == 0
163157
&& !prefs.getBoolean(disabledTunnelingKey, false);
164158

165-
if (Boolean.TRUE.equals(isFirstRun)
159+
if (App.getApp().isFirstRun()
166160
|| (wasDeviceBlacklistUpdated && !wasMediaTunnelingEnabledByUser)) {
167161
setMediaTunneling(context);
168162
}

app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import androidx.annotation.NonNull;
88
import androidx.preference.PreferenceManager;
99

10+
import org.schabi.newpipe.App;
1011
import org.schabi.newpipe.R;
1112
import org.schabi.newpipe.error.ErrorInfo;
1213
import org.schabi.newpipe.error.ErrorUtil;
@@ -163,15 +164,14 @@ protected void migrate(@NonNull final Context context) {
163164
private static final int VERSION = 6;
164165

165166

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

173173
// no migration to run, already up to date
174-
if (isFirstRun) {
174+
if (App.getApp().isFirstRun()) {
175175
sp.edit().putInt(lastPrefVersionKey, VERSION).apply();
176176
return;
177177
} else if (lastPrefVersion == VERSION) {

app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.schabi.newpipe.settings;
22

3+
import android.app.AlertDialog;
4+
import android.content.Context;
35
import android.os.Bundle;
46
import android.widget.Toast;
57

68
import androidx.preference.Preference;
9+
import androidx.preference.PreferenceManager;
710

811
import org.schabi.newpipe.NewVersionWorker;
912
import org.schabi.newpipe.R;
@@ -36,4 +39,38 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
3639
findPreference(getString(R.string.manual_update_key))
3740
.setOnPreferenceClickListener(manualUpdateClick);
3841
}
42+
43+
public static void askForConsentToUpdateChecks(final Context context) {
44+
new AlertDialog.Builder(context)
45+
.setTitle(context.getString(R.string.check_for_updates))
46+
.setMessage(context.getString(R.string.auto_update_check_description))
47+
.setPositiveButton(context.getString(R.string.yes), (d, w) -> {
48+
d.dismiss();
49+
setAutoUpdateCheckEnabled(context, true);
50+
})
51+
.setNegativeButton(R.string.no, (d, w) -> {
52+
d.dismiss();
53+
// set explicitly to false, since the default is true on previous versions
54+
setAutoUpdateCheckEnabled(context, false);
55+
})
56+
.show();
57+
}
58+
59+
private static void setAutoUpdateCheckEnabled(final Context context, final boolean enabled) {
60+
PreferenceManager.getDefaultSharedPreferences(context)
61+
.edit()
62+
.putBoolean(context.getString(R.string.update_app_key), enabled)
63+
.putBoolean(context.getString(R.string.update_check_consent_key), true)
64+
.apply();
65+
}
66+
67+
/**
68+
* Whether the user was asked for consent to automatically check for app updates.
69+
* @param context
70+
* @return true if the user was asked for consent, false otherwise
71+
*/
72+
public static boolean wasUserAskedForConsent(final Context context) {
73+
return PreferenceManager.getDefaultSharedPreferences(context)
74+
.getBoolean(context.getString(R.string.update_check_consent_key), false);
75+
}
3976
}

app/src/main/res/values-ar-rLY/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<string name="short_billion">بليون</string>
7979
<string name="feed_load_error_account_info">تعذر تحميل موجز \'%s\'.</string>
8080
<string name="question_mark">؟</string>
81-
<string name="manual_update_title">التحقق من وجود تحديثات</string>
81+
<string name="check_for_updates">التحقق من وجود تحديثات</string>
8282
<string name="peertube_instance_url_title">مثيلات خوادم پيرتيوب</string>
8383
<string name="more_than_100_videos">+100 فيديو</string>
8484
<string name="short_thousand">ألف</string>

app/src/main/res/values-ar/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@
700700
<string name="enqueue_next_stream">وضع التالي على قائمة الانتظار</string>
701701
<string name="enqueued_next">تم وضع التالي على قائمة الانتظار</string>
702702
<string name="processing_may_take_a_moment">جاري المعالجة ... قد يستغرق لحظة</string>
703-
<string name="manual_update_title">التحقق من وجود تحديثات</string>
703+
<string name="check_for_updates">التحقق من وجود تحديثات</string>
704704
<string name="manual_update_description">التحقق يدويا من وجود إصدارات جديدة</string>
705705
<string name="checking_updates_toast">جاري التحقق من وجود تحديثات…</string>
706706
<string name="feed_new_items">عناصر تغذية جديدة</string>

app/src/main/res/values-az/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@
448448
<item quantity="one">%s video</item>
449449
<item quantity="other">%s video</item>
450450
</plurals>
451-
<string name="manual_update_title">Yeniləmələri yoxla</string>
451+
<string name="check_for_updates">Yeniləmələri yoxla</string>
452452
<string name="seekbar_preview_thumbnail_title">Axtarış çubuğunun miniatür önizləməsi</string>
453453
<string name="permission_denied">Əməliyyat sistem tərəfindən ləğv edildi</string>
454454
<string name="auto">Avto</string>

app/src/main/res/values-be/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@
670670
<string name="enable_streams_notifications_summary">Апавяшчаць аб новых стрымах з падпісак</string>
671671
<string name="streams_notifications_interval_title">Частата праверкі</string>
672672
<string name="streams_notifications_network_title">Патрабуецца падключэнне да сеткі</string>
673-
<string name="manual_update_title">Праверце наяўнасць абнаўленняў</string>
673+
<string name="check_for_updates">Праверце наяўнасць абнаўленняў</string>
674674
<string name="manual_update_description">Праверце новыя версіі ўручную</string>
675675
<string name="autoplay_summary">Аўтаматычны запуск прайгравання — %s</string>
676676
<string name="card">Картка</string>

app/src/main/res/values-bg/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@
548548
<string name="recaptcha_cookies_cleared">Бисквитките от reCAPTCHA бяха почистени</string>
549549
<string name="checking_updates_toast">Проверяване за актуализации…</string>
550550
<string name="enumeration_comma">,</string>
551-
<string name="manual_update_title">Провери за актуализации</string>
551+
<string name="check_for_updates">Провери за актуализации</string>
552552
<string name="percent">Процент</string>
553553
<string name="unknown_quality">Неизвестно качество</string>
554554
<string name="unknown_format">Неизвестен формат</string>

0 commit comments

Comments
 (0)