Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ba33073
K2GO-588 feat(privacy): with Keep offline, an action that needs the i…
luisguzman-adfa Nov 20, 2026
c453e0e
K2GO-588 feat(catalog): catalogs refresh on their own again when the …
luisguzman-adfa Nov 20, 2026
00d6c74
K2GO-588 feat(privacy): with Keep offline, the box services stay off …
luisguzman-adfa Nov 20, 2026
99d505c
K2GO-588 feat(feedback): with Keep offline, Settings feedback sends n…
luisguzman-adfa Nov 20, 2026
e102faa
K2GO-588 fix(privacy): with Keep offline and no network, nothing is b…
luisguzman-adfa Nov 20, 2026
95aa3b3
K2GO-588 chore(l10n): translate the Keep offline strings to all 33 lo…
luisguzman-adfa Nov 20, 2026
9f753e4
K2GO-588 fix(feedback): the Keep offline warning says why, and the fe…
luisguzman-adfa Nov 20, 2026
8d464df
K2GO-588 fix(ui): a snackbar shows up to 5 lines, so long messages an…
luisguzman-adfa Nov 20, 2026
3515092
K2GO-588 chore(l10n): remove the strings and drawables that K2GO-588 …
luisguzman-adfa Nov 20, 2026
5464263
K2GO-588 chore: merge the updated one privacy choice branch; drop gen…
luisguzman-adfa Nov 22, 2026
343bd0c
K2GO-588 chore: merge the one privacy choice review fixes
luisguzman-adfa Nov 22, 2026
3ec3a21
K2GO-588 fix(privacy): saved orders wait for an allow while kept offline
luisguzman-adfa Nov 22, 2026
299645a
K2GO-588 fix(privacy): Rebuild always asks and stays grey; one feedba…
luisguzman-adfa Nov 22, 2026
961ee56
K2GO-588 fix(privacy): a change of the choice reaches the box and the…
luisguzman-adfa Nov 22, 2026
b5529ae
K2GO-588 chore: merge the gate-open question fix
luisguzman-adfa Nov 22, 2026
04a7e52
K2GO-588 fix(privacy): wizard maps wait for nothing; Keep offline end…
luisguzman-adfa Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* Name : CatalogRefreshScheduler.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : ADFA-5094 (ADR-5094). Enqueues a catalog refresh. K2GO-580: a refresh
* runs only when the user asks (the Get more "Update catalogs" row) or
* when a user-started download hits a 404. Nothing refreshes by itself.
* Description : ADFA-5094 (ADR-5094). Enqueues a catalog refresh: weekly plus a
* TTL-gated check on open, on Wi-Fi only, when the user chose to request
* online content (K2GO-588); and a forced check when a user-started
* download hits a 404 (K2GO-390).
* ============================================================================
*/
package org.appdevforall.k2go.catalog.data;
Expand All @@ -14,21 +15,28 @@

import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;

import org.appdevforall.k2go.delivery.data.OnlineConsent;

import java.util.concurrent.TimeUnit;

public final class CatalogRefreshScheduler {

private CatalogRefreshScheduler() {
}

private static Data input(String name, String manifestUrl, String basename) {
private static Data input(String name, String manifestUrl, String basename, boolean force) {
return new Data.Builder()
.putString(CatalogRefreshWorker.KEY_NAME, name)
.putString(CatalogRefreshWorker.KEY_MANIFEST_URL, manifestUrl)
.putString(CatalogRefreshWorker.KEY_BASENAME, basename)
.putBoolean(CatalogRefreshWorker.KEY_FORCE, force)
.build();
}

Expand All @@ -38,39 +46,45 @@ private static Constraints constraints(NetworkType netType) {
.build();
}

/** Tag on every refresh request, so the Get more row can watch and cancel them as one. */
public static final String TAG = "catalog-refresh";

/**
* K2GO-580: removes the automatic refresh jobs that older builds scheduled (weekly + on open).
* WorkManager keeps them across an app update, so the call sites that used to schedule them
* now cancel them. Idempotent and cheap.
* K2GO-588: keep the automatic refresh in step with the online choice. On: a weekly refresh plus
* an opportunistic TTL-gated check now, both on an unmetered network only (K2GO-580). Off (Keep
* offline): cancel both. Safe to call on every launch. The worker also reads the choice when it
* runs, so a job queued before the user turned it off does not connect.
*/
// ponytail: delete once no supported install predates K2GO-580.
public static void cancelAutomatic(Context ctx, String name) {
public static void syncAutomatic(Context ctx, String name, String manifestUrl, String basename) {
WorkManager wm = WorkManager.getInstance(ctx.getApplicationContext());
wm.cancelUniqueWork("catalog-refresh-" + name);
wm.cancelUniqueWork("catalog-refresh-now-" + name);
}

/** Stops every running or queued refresh (the Get more row's Cancel). */
public static void cancelAll(Context ctx) {
WorkManager.getInstance(ctx.getApplicationContext()).cancelAllWorkByTag(TAG);
if (!OnlineConsent.isEnabled(ctx)) {
wm.cancelUniqueWork("catalog-refresh-" + name);
wm.cancelUniqueWork("catalog-refresh-now-" + name);
return;
}
// UPDATE (not KEEP) so an install that holds an older job gets the current constraint.
wm.enqueueUniquePeriodicWork("catalog-refresh-" + name, ExistingPeriodicWorkPolicy.UPDATE,
new PeriodicWorkRequest.Builder(CatalogRefreshWorker.class, 7, TimeUnit.DAYS)
.setConstraints(constraints(NetworkType.UNMETERED))
.setInputData(input(name, manifestUrl, basename, false))
.build());
wm.enqueueUniqueWork("catalog-refresh-now-" + name, ExistingWorkPolicy.KEEP,
new OneTimeWorkRequest.Builder(CatalogRefreshWorker.class)
.setConstraints(constraints(NetworkType.UNMETERED))
.setInputData(input(name, manifestUrl, basename, false))
.build());
}

/**
* K2GO-390: force an on-demand check that bypasses the worker's TTL gate (for a 404 self-heal --
* the catalog may have rolled to a newer dated file within the TTL window). The ETag conditional
* GET still makes it cheap. Its own unique name (KEEP) coalesces a burst of failures into one run.
* It is part of the download the user started, so it does not depend on the online choice.
*/
public static void forceRefresh(Context ctx, String name, String manifestUrl, String basename) {
// K2GO-390: EXPEDITED so it dispatches promptly -- a 404 self-heal must land before the caller's
// bounded retries give up (falls back to a normal request if the expedited quota is spent).
OneTimeWorkRequest req = new OneTimeWorkRequest.Builder(CatalogRefreshWorker.class)
.setConstraints(constraints(NetworkType.CONNECTED))
.setExpedited(androidx.work.OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.setInputData(input(name, manifestUrl, basename))
.addTag(TAG)
.setInputData(input(name, manifestUrl, basename, true))
.build();
WorkManager.getInstance(ctx.getApplicationContext())
.enqueueUniqueWork("catalog-refresh-force-" + name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ public long lastCheckMs(String catalog) {
return prefs.getLong(key(catalog, "last_check"), 0L);
}

/** K2GO-580: epoch millis of the newest check across every catalog (0 if none was ever checked). */
public long lastCheckAnyMs() {
long max = 0L;
for (java.util.Map.Entry<String, ?> e : prefs.getAll().entrySet()) {
if (e.getKey().endsWith(".last_check") && e.getValue() instanceof Long) {
max = Math.max(max, (Long) e.getValue());
}
}
return max;
}

/** Hash of the catalog currently in use (empty until a pull is applied). */
public String activeHash(String catalog) {
return prefs.getString(key(catalog, "hash"), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public final class CatalogRefreshWorker extends Worker {
public static final String KEY_NAME = "name";
public static final String KEY_MANIFEST_URL = "manifest_url";
public static final String KEY_BASENAME = "basename";
// K2GO-390: bypass the TTL gate for an on-demand check (e.g. a 404 self-heal needs to look now,
// even if the weekly check ran recently). The ETag conditional GET still keeps it cheap.
public static final String KEY_FORCE = "force";

public CatalogRefreshWorker(@NonNull Context context, @NonNull WorkerParameters params) {
super(context, params);
Expand All @@ -54,8 +57,21 @@ public Result doWork() {

CatalogRefreshStore store = new CatalogRefreshStore(ctx);
long now = System.currentTimeMillis();
// K2GO-580: every refresh is asked for (the Get more button or a download 404), so it always
// checks; the old TTL and failure backoff only guarded automatic refreshes.
boolean force = getInputData().getBoolean(KEY_FORCE, false);
// K2GO-588: an automatic run reads the online choice when it runs, so a job queued before the
// user chose Keep offline does not connect. A forced run is part of a download the user started.
if (!force && !org.appdevforall.k2go.networkpolicy.data.NetworkCostAdmission.allowsAutomatic(ctx)) {
return Result.success();
}
if (!force && !CatalogFreshness.dueForCheck(store.lastCheckMs(name), now, CatalogFreshness.DEFAULT_TTL_MS)) {
return Result.success(); // still fresh; do not hit the network
}
// K2GO-476: a pull that failed recently (a bad publish) is not repeated on every open.
long lastFailure = store.lastFailureMs(name);
if (!force && lastFailure > 0
&& !CatalogFreshness.dueForCheck(lastFailure, now, CatalogFreshness.FAILURE_BACKOFF_MS)) {
return Result.success();
}

// K2GO-476: a check counts only once it has an answer. Recording it before the download
// let one failed pull hide behind the TTL for a week.
Expand All @@ -65,9 +81,9 @@ public Result doWork() {
CatalogManifestClient.Result res = client.fetchManifest(manifestUrl,
overlay.exists() ? store.etag(name) : null);
if (res.status == CatalogManifestClient.Status.FAILED) {
// K2GO-580: no retry. A refresh runs only when asked; a delayed retry could land on mobile
// data that nobody approved. The user taps again (or the next 404 asks again).
return Result.failure();
// Automatic: back off and try again (the Wi-Fi constraint still holds). Forced: no retry,
// since a delayed retry could land on mobile data; the next 404 asks again (K2GO-580).
return force ? Result.failure() : Result.retry();
}
if (res.status == CatalogManifestClient.Status.NOT_MODIFIED) {
store.recordChecked(name, now);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@
/**
* K2GO-588: every change of the choice (onboarding, Settings) calls {@link #apply(Context)}, and the
* app start calls {@link #startCrashReports(Context)}. Gates that read the choice on each call
* (network admission, Sentry beforeSend) need nothing here.
* (network admission, saved-order admission, Sentry beforeSend) need nothing here. The app open
* also re-applies Keep offline to the box (PendingRestartsOnOpen), which covers a restore or a clone.
*/
public final class OnlineChoiceEffects {

private static final String TAG = "OnlineChoiceEffects";

private OnlineChoiceEffects() {}

/** Applies the stored choice now: analytics collection, and crash reports on or off. */
/** Applies the stored choice now: analytics, crash reports, the catalog jobs and the box. */
public static void apply(Context ctx) {
Context app = ctx.getApplicationContext();
AnalyticsClient.with(app).applyConsent();
org.appdevforall.k2go.redesign.KiwixCatalog.syncRefresh(app);
org.appdevforall.k2go.kolibri.data.CatalogRepositoryImpl.syncRefresh(app);
if (OnlineConsent.isEnabled(app)) {
startCrashReports(app);
} else if (io.sentry.Sentry.isEnabled()) {
// close() flushes and waits for the transport (seconds): never on the main thread.
new Thread(io.sentry.Sentry::close, "sentry-close").start();
} else {
org.appdevforall.k2go.networkpolicy.data.OnlineAllowance.clear();
if (io.sentry.Sentry.isEnabled()) {
// close() flushes and waits for the transport (seconds): never on the main thread.
new Thread(io.sentry.Sentry::close, "sentry-close").start();
}
org.appdevforall.k2go.privacy.presentation.PendingRestartsOnOpen.keepOfflineNow(app);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public static void installOn(android.app.Activity activity, String screenTag, in
android.view.Gravity.BOTTOM | android.view.Gravity.END);
lp.setMargins(m, m, m, Math.round(bottomMarginDp * d));
root.addView(fab, lp);
org.appdevforall.k2go.networkpolicy.presentation.NetworkPolicyGate.markNeedsInternet(fab);
attach(fab, () -> sendFeedback(activity, screenTag), topExclusionDp, bottomExclusionDp);
}

Expand All @@ -227,6 +228,24 @@ public static void sendFeedback(android.app.Activity activity, String screen) {
public static void sendFeedback(android.app.Activity activity, String screen,
org.appdevforall.k2go.feedback.domain.FeedbackType type,
String message) {
// K2GO-588: the report leaves through an app the user picks (email, chat), which the app does
// not control. With Keep offline, say first that this can connect; Keep offline is primary.
if (!org.appdevforall.k2go.delivery.data.OnlineConsent.isEnabled(activity)) {
new org.appdevforall.k2go.ui.dialog.BrandDialog(activity)
.setTitle(org.appdevforall.k2go.R.string.k2go_feedback_third_party_title)
.setMessage(org.appdevforall.k2go.R.string.k2go_feedback_third_party_msg)
.setPositive(org.appdevforall.k2go.R.string.analytics_enroll_decline, () -> { })
.setNegative(org.appdevforall.k2go.R.string.k2go_feedback_send_anyway,
() -> handOff(activity, screen, type, message))
.show();
return;
}
handOff(activity, screen, type, message);
}

private static void handOff(android.app.Activity activity, String screen,
org.appdevforall.k2go.feedback.domain.FeedbackType type,
String message) {
org.appdevforall.k2go.feedback.data.FeedbackScreenshot.capture(activity, path -> {
if (activity.isFinishing() || activity.isDestroyed()) {
return; // ADFA-4932: activity gone between tap and the async capture callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,23 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState)
EditText message = v.findViewById(R.id.feedback_message);
Button send = v.findViewById(R.id.feedback_send);

// K2GO-588: with Keep offline, this screen sends nothing. The buttons look grey but stay
// tappable, so a tap can say why and where to change it.
final boolean keptOffline =
!org.appdevforall.k2go.delivery.data.OnlineConsent.isEnabled(requireContext());
if (keptOffline) {
send.setAlpha(0.5f);
}

Button forceCrash = v.findViewById(R.id.feedback_force_crash);
if (BuildConfig.DEBUG) {
forceCrash.setVisibility(View.VISIBLE);
if (keptOffline) forceCrash.setAlpha(0.5f);
forceCrash.setOnClickListener(x -> {
if (keptOffline) {
explainKeptOffline(x);
return;
}
throw new RuntimeException("K2Go test crash");
});
}
Expand All @@ -65,6 +78,10 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState)
category.setAdapter(adapter);

send.setOnClickListener(view -> {
if (keptOffline) {
explainKeptOffline(view);
return;
}
String msg = message.getText().toString().trim();
if (msg.isEmpty()) {
Toast.makeText(requireContext(), R.string.feedback_empty_message, Toast.LENGTH_SHORT).show();
Expand All @@ -90,6 +107,11 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState)
});
}

private void explainKeptOffline(View anchor) {
org.appdevforall.k2go.util.Snackbars.make(anchor, getString(R.string.k2go_feedback_kept_offline,
getString(org.appdevforall.k2go.delivery.presentation.OnlineChoiceDialog.choiceLabel()))).show();
}

private static FeedbackType typeFor(int position) {
switch (position) {
case 1:
Expand Down
Loading