Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -6,8 +6,8 @@
* Description : ADFA-5094 (ADR-5094). Enqueues the catalog refresh: a weekly,
* network-constrained periodic job, plus an opportunistic one-shot
* (e.g. when the picker opens). The worker's own TTL gate keeps the
* one-shot cheap. Unique per catalog, KEEP so relaunches don't
* reset the schedule.
* one-shot cheap. Unique per catalog, so relaunches don't reset the
* schedule. Automatic refreshes run on Wi-Fi only (K2GO-580).
* ============================================================================
*/
package org.appdevforall.k2go.catalog.data;
Expand Down Expand Up @@ -49,42 +49,27 @@ private static Constraints constraints(NetworkType netType) {
.build();
}

/** Weekly periodic refresh over any connection. Safe to call on every launch. */
public static void scheduleWeekly(Context ctx, String name, String manifestUrl, String basename) {
scheduleWeekly(ctx, name, manifestUrl, basename, NetworkType.CONNECTED);
}
// K2GO-580: automatic refreshes run only on an unmetered network (Wi-Fi), never on the user's
// mobile data; the catalog bundled in the APK is the floor until then. A user-started download
// that hits a 404 still self-heals over any connection (forceRefresh).

/**
* Weekly periodic refresh, enqueued once per catalog (KEEP). Safe to call on every launch.
* {@code netType} lets a large asset ask for {@link NetworkType#UNMETERED} so it refreshes only
* on Wi-Fi and never spends the user's mobile data (ADFA-5094: the tree bundle is ~16 MB).
*/
public static void scheduleWeekly(Context ctx, String name, String manifestUrl, String basename,
NetworkType netType) {
/** Weekly periodic refresh, one per catalog. Safe to call on every launch. UPDATE (not KEEP) so an
* install that already holds the old any-network job gets the Wi-Fi constraint, schedule kept. */
public static void scheduleWeekly(Context ctx, String name, String manifestUrl, String basename) {
PeriodicWorkRequest req = new PeriodicWorkRequest.Builder(
CatalogRefreshWorker.class, 7, TimeUnit.DAYS)
.setConstraints(constraints(netType))
.setConstraints(constraints(NetworkType.UNMETERED))
.setInputData(input(name, manifestUrl, basename))
.build();
WorkManager.getInstance(ctx.getApplicationContext())
.enqueueUniquePeriodicWork("catalog-refresh-" + name,
ExistingPeriodicWorkPolicy.KEEP, req);
ExistingPeriodicWorkPolicy.UPDATE, req);
}

/** Opportunistic one-shot over any connection; the worker's TTL gate no-ops it when fresh. */
/** Opportunistic one-shot; the worker's TTL gate no-ops it when still fresh. */
public static void refreshNow(Context ctx, String name, String manifestUrl, String basename) {
refreshNow(ctx, name, manifestUrl, basename, NetworkType.CONNECTED);
}

/**
* Opportunistic one-shot; the worker's TTL gate no-ops it when still fresh. {@code netType}
* constrains which connection may trigger it — {@link NetworkType#UNMETERED} keeps a large
* asset off mobile data (ADFA-5094).
*/
public static void refreshNow(Context ctx, String name, String manifestUrl, String basename,
NetworkType netType) {
OneTimeWorkRequest req = new OneTimeWorkRequest.Builder(CatalogRefreshWorker.class)
.setConstraints(constraints(netType))
.setConstraints(constraints(NetworkType.UNMETERED))
.setInputData(input(name, manifestUrl, basename))
.build();
WorkManager.getInstance(ctx.getApplicationContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ public CatalogRepositoryImpl(Context context) {
context, CATALOG, MANIFEST_URL, BASENAME);
org.appdevforall.k2go.catalog.data.CatalogRefreshScheduler.refreshNow(
context, CATALOG, MANIFEST_URL, BASENAME);
// The tree bundle refreshes on the same cadence, but only on Wi-Fi (UNMETERED): it is ~16 MB
// against the catalog's ~83 KB, and the APK asset is a working floor, so a metered pull is
// not worth the user's mobile data.
// The tree bundle refreshes on the same cadence (Wi-Fi only, like every catalog: K2GO-580).
org.appdevforall.k2go.catalog.data.CatalogRefreshScheduler.scheduleWeekly(
context, TREE_CATALOG, TREE_MANIFEST_URL, TREE_BASENAME,
androidx.work.NetworkType.UNMETERED);
context, TREE_CATALOG, TREE_MANIFEST_URL, TREE_BASENAME);
org.appdevforall.k2go.catalog.data.CatalogRefreshScheduler.refreshNow(
context, TREE_CATALOG, TREE_MANIFEST_URL, TREE_BASENAME,
androidx.work.NetworkType.UNMETERED);
context, TREE_CATALOG, TREE_MANIFEST_URL, TREE_BASENAME);
}

/** K2GO-476: box, then Studio with the bundle's folder sizes filled in, then the bundle. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static void start(@NonNull Application app) {
started = true;
ensureChannel(app);
last = AndroidNetworkClassifier.classify(app);
// K2GO-580: a notice left by a process the system killed is stale once we start off mobile data.
if (last != NetworkClass.METERED) clearNotice(app);
// observeForever keeps NetworkStateLiveData active for the process lifetime,
// which is exactly the scope we want; no separate registration.
NetworkStateLiveData.get(app).observeForever(token -> onNetworkChanged(app));
Expand All @@ -62,12 +64,18 @@ private static void onNetworkChanged(@NonNull Application app) {
last = next;
if (next != NetworkClass.METERED) {
SessionMeteredConsentStore.get().clear();
clearNotice(app); // K2GO-580: the notice is true only while on mobile data
}
if (NetworkTransition.shouldWarn(previous, next)) {
notifyMetered(app);
}
}

/** Removes the mobile data notice (K2GO-580): off mobile data, at start, and when K2Go turns off. */
public static void clearNotice(@NonNull Context ctx) {
NotificationManagerCompat.from(ctx).cancel(NOTIF_ID);
}

private static void notifyMetered(@NonNull Context ctx) {
NotificationCompat.Builder b = new NotificationCompat.Builder(ctx, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_warning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ public void turnOffK2Go() {
// autonomous and outlives the process, so tear it down now (concurrent with the box stop) and
// confirm it before exit (finishAndExit waits on this). Fires at once when no hotspot is up.
LocalHotspotManager.get().stop(() -> hotspotTornDown = true);
org.appdevforall.k2go.networkpolicy.presentation.MeteredNetworkObserver.clearNotice(this); // K2GO-580
// ADFA-4834: minimal shutdown feedback — a status line + the service currently stopping,
// shown over the exit animation and kept until the environment is really stopped, so we
// never bounce back to the Library mid-shutdown. Works with or without the Lottie.
Expand Down
Loading