Require explicit Android local game previews

This commit is contained in:
waozi committed 2026-10-22 02:17:19 -03:00
1 parent c100820544
commit 7d3de4ea7e
5 files changed
+101 -10

No files matched your search

+3
View File
@@ -502,6 +502,9 @@ stages its release through Inbe's existing signed publisher; with
App packages workflow never publishes these apps. For a local preview or a
test, `INBE_NODE_APP_FILE=/absolute/path/chess.zib` offers that package as if
the node did; it passes the same interface, identity and resource checks.
On Android debug builds, a single `<name>.zib` in the app's external files
folder is offered only when the launch intent includes `--ez local_node_app true`.
Ordinary launches ignore these files and keep using signed node packages.
## Photos and the account's media library
@@ -0,0 +1,24 @@
package xyz.waozi.inbe;
import android.content.Intent;
import java.io.File;
/** Explicit debug launches can offer one local bundle without installing it. */
public final class LocalNodeApp {
public static final String EXTRA_LOCAL_NODE_APP = "local_node_app";
private LocalNodeApp() {
}
public static File offered(boolean debug, Intent intent, File folder) {
if (!debug || intent == null || !intent.getBooleanExtra(EXTRA_LOCAL_NODE_APP, false)
|| folder == null) {
return null;
}
File[] bundles = folder.listFiles(file -> file.isFile() && file.getName().endsWith(".zib"));
if (bundles == null || bundles.length != 1) {
return null;
}
return bundles[0];
}
}
@@ -1186,16 +1186,17 @@ public class MainActivity extends NativeActivity {
}
/**
* Debug builds only: a single {@code <name>.zib} pushed to this app's
* external files folder is offered like a node app, through the same
* interface, identity and resource checks as a desktop local bundle.
* Local bundles require an explicit debug launch. A leftover file must
* never shadow signed node updates on ordinary launches after an upgrade.
*/
private void offerLocalNodeApp() {
File folder = getExternalFilesDir(null);
File[] bundles = folder == null ? null : folder.listFiles((dir, name) -> name.endsWith(".zib"));
if (bundles == null || bundles.length != 1) return;
File bundle = LocalNodeApp.offered(BuildConfig.DEBUG, getIntent(), getExternalFilesDir(null));
try {
android.system.Os.setenv("INBE_NODE_APP_FILE", bundles[0].getAbsolutePath(), true);
if (bundle == null) {
android.system.Os.unsetenv("INBE_NODE_APP_FILE");
} else {
android.system.Os.setenv("INBE_NODE_APP_FILE", bundle.getAbsolutePath(), true);
}
} catch (android.system.ErrnoException error) {
Log.w("Inbe", "Could not offer the local node app", error);
}
@@ -1205,9 +1206,8 @@ public class MainActivity extends NativeActivity {
protected void onCreate(Bundle savedInstanceState) {
startupStarted = SystemClock.elapsedRealtime();
configureSystemBars();
// Before the native app starts: debug builds may offer one local
// node-app bundle, as desktop builds do with INBE_NODE_APP_FILE.
if (BuildConfig.DEBUG) offerLocalNodeApp();
// Set or clear the local override before the native app starts.
offerLocalNodeApp();
super.onCreate(savedInstanceState);
configureSystemBars();
textInputView = new TextInputView(this, new TextInputView.Listener() {
@@ -0,0 +1,63 @@
import static org.junit.Assert.*;
import android.content.Intent;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import xyz.waozi.inbe.LocalNodeApp;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = {28, 36}, manifest = Config.NONE)
public class LocalNodeAppTest {
@Rule public TemporaryFolder external = new TemporaryFolder();
private Intent requested() {
return new Intent(Intent.ACTION_MAIN).putExtra(LocalNodeApp.EXTRA_LOCAL_NODE_APP, true);
}
@Test public void ordinaryLaunchIgnoresOldArcadeAndPreservesItsFile() throws Exception {
File oldArcade = external.newFile("arcade.zib");
byte[] contents = "old developer campaign".getBytes(StandardCharsets.UTF_8);
Files.write(oldArcade.toPath(), contents);
Intent launcher = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
assertNull(LocalNodeApp.offered(true, launcher, external.getRoot()));
Intent shortcut = new Intent("xyz.waozi.inbe.action.OPEN_APP").putExtra("app_name", "arcade");
assertNull(LocalNodeApp.offered(true, shortcut, external.getRoot()));
assertArrayEquals(contents, Files.readAllBytes(oldArcade.toPath()));
}
@Test public void explicitDebugLaunchCanStillUseOneBundle() throws Exception {
File bundle = external.newFile("arcade.zib");
external.newFile("notes.txt");
external.newFolder("directory.zib");
assertEquals(bundle, LocalNodeApp.offered(true, requested(), external.getRoot()));
}
@Test public void localRequestDoesNotPersistAcrossNormalLaunches() throws Exception {
File bundle = external.newFile("arcade.zib");
assertEquals(bundle, LocalNodeApp.offered(true, requested(), external.getRoot()));
assertNull(LocalNodeApp.offered(true, new Intent(Intent.ACTION_MAIN), external.getRoot()));
assertNull(LocalNodeApp.offered(true, null, external.getRoot()));
}
@Test public void releaseBuildNeverOffersLocalBundles() throws Exception {
external.newFile("arcade.zib");
assertNull(LocalNodeApp.offered(false, requested(), external.getRoot()));
}
@Test public void missingAndAmbiguousBundlesUseNormalPackages() throws Exception {
assertNull(LocalNodeApp.offered(true, requested(), null));
assertNull(LocalNodeApp.offered(true, requested(), external.getRoot()));
external.newFile("arcade.zib");
external.newFile("chess.zib");
assertNull(LocalNodeApp.offered(true, requested(), external.getRoot()));
assertNull(LocalNodeApp.offered(true, requested(), new File(external.getRoot(), "missing")));
}
}
@@ -29,6 +29,7 @@ sourceSets {
}
sourceSets.main.java.include '**/RadioPlayer.java'
sourceSets.main.java.include '**/DocumentExport.java'
sourceSets.main.java.include '**/LocalNodeApp.java'
dependencies {
compileOnly files("${sdk}/platforms/android-36/android.jar")