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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Buttercode Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,77 @@ private void saveScreenshot(ActivityScenario<MainActivity> scenario,Context cont
}

@Test public void nativeExportRequiresExactSequentialBytes()throws Exception{Context context=InstrumentationRegistry.getInstrumentation().getTargetContext();ExportStore store=new ExportStore(context.getCacheDir());String token=store.begin("invoice.pdf","application/pdf",4);try{store.chunk(token,1,"JVBERg==");fail("Out-of-order export accepted");}catch(IOException expected){}store.chunk(token,0,"JVBERg==");File file=store.finish(token);assertEquals(4,file.length());try(InputStream in=new FileInputStream(file)){assertEquals('%',in.read());}assertTrue(file.delete());store.abort();}
@androidx.test.filters.SdkSuppress(minSdkVersion=35) @Test public void nativeScreenRecordingSurvivesOneMinuteAndImports()throws Exception{
private void startNativeRecording(ActivityScenario<MainActivity> scenario,Context context)throws Exception{
ready(scenario);context.getSharedPreferences("capture",Context.MODE_PRIVATE).edit().putBoolean("notificationsAsked",true).apply();js(scenario,"(()=>{const d=document.getElementById('record-setup');if(d)d.open=true;document.querySelector('[data-android-action=recordScreen]').click()})()");
nativeText("Recording quality",false);nativeText("Continue",true);nativeText("Screen only",true);
// Read the actual system dialog. Android 15 offers a scope selector; choose the entire test screen.
boolean consent=false;
for(int n=0;n<50&&!consent;n++){
android.view.accessibility.AccessibilityNodeInfo root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();
if(root!=null){
java.util.List<android.view.accessibility.AccessibilityNodeInfo> scope=root.findAccessibilityNodeInfosByText("A single app");
if(!scope.isEmpty()){android.view.accessibility.AccessibilityNodeInfo node=scope.get(0);while(node!=null&&!node.isClickable())node=node.getParent();if(node!=null)node.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK);Thread.sleep(300);nativeText("Entire screen",true);Thread.sleep(300);}
root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();
if(root!=null)for(String label:new String[]{"Start","Start now","Start recording"})for(android.view.accessibility.AccessibilityNodeInfo node:root.findAccessibilityNodeInfosByText(label))if(node.getText()!=null&&label.equalsIgnoreCase(node.getText().toString())){while(node!=null&&!node.isClickable())node=node.getParent();if(node!=null&&node.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK))consent=true;}
}
if(!consent)Thread.sleep(200);
}
if(!consent){saveScreenshot(scenario,context,"capture-consent-blocked");android.view.accessibility.AccessibilityNodeInfo root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();System.out.println("CAPTURE_CONSENT_UI "+nativeTree(root));}assertTrue("Native screen-sharing consent was not completed",consent);
for(int n=0;n<60&&!ScreenRecordingService.active;n++)Thread.sleep(200);
assertTrue("Native recorder did not start",ScreenRecordingService.active);
}
private String stopNativeRecording(ActivityScenario<MainActivity> scenario,Context context)throws Exception{
String name=ScreenRecordingService.activeFileName;
js(scenario,"document.querySelector('[data-android-action=recordScreen]').click()");nativeText("Stop recording",true);
for(int n=0;n<60&&ScreenRecordingService.active;n++)Thread.sleep(200);
assertFalse("Native recorder did not stop",ScreenRecordingService.active);
File video=new File(new File(context.getFilesDir(),"recordings"),name);assertTrue(video.exists());assertTrue(video.length()>0);
return name;
}
private long nativeVideoDurationMs(Context context,String name)throws Exception{
File video=new File(new File(context.getFilesDir(),"recordings"),name);
android.media.MediaMetadataRetriever media=new android.media.MediaMetadataRetriever();media.setDataSource(video.getAbsolutePath());long duration=Long.parseLong(media.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION));System.out.println("NATIVE_VIDEO_DURATION_MS "+duration+" bytes="+video.length());assertNotNull(media.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));media.release();return duration;
}
@androidx.test.filters.SdkSuppress(minSdkVersion=35) @Test public void nativeScreenRecordingSurvivesOneMinute()throws Exception{
Context context=InstrumentationRegistry.getInstrumentation().getTargetContext();
android.content.res.Configuration cfg=context.getResources().getConfiguration();
org.junit.Assume.assumeTrue("Long native capture runs once, in phone portrait mode",cfg.smallestScreenWidthDp<600&&cfg.orientation==android.content.res.Configuration.ORIENTATION_PORTRAIT);
try(ActivityScenario<MainActivity> scenario=launch()){
ready(scenario);context.getSharedPreferences("capture",Context.MODE_PRIVATE).edit().putBoolean("notificationsAsked",true).apply();js(scenario,"(()=>{const d=document.getElementById('record-setup');if(d)d.open=true;document.querySelector('[data-android-action=recordScreen]').click()})()");
nativeText("Recording quality",false);nativeText("Continue",true);nativeText("Screen only",true);
// Read the actual system dialog. Android 15 offers a scope selector; choose the entire test screen.
boolean consent=false;
for(int n=0;n<50&&!consent;n++){
android.view.accessibility.AccessibilityNodeInfo root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();
if(root!=null){
java.util.List<android.view.accessibility.AccessibilityNodeInfo> scope=root.findAccessibilityNodeInfosByText("A single app");
if(!scope.isEmpty()){android.view.accessibility.AccessibilityNodeInfo node=scope.get(0);while(node!=null&&!node.isClickable())node=node.getParent();if(node!=null)node.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK);Thread.sleep(300);nativeText("Entire screen",true);Thread.sleep(300);}
root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();
if(root!=null)for(String label:new String[]{"Start","Start now","Start recording"})for(android.view.accessibility.AccessibilityNodeInfo node:root.findAccessibilityNodeInfosByText(label))if(node.getText()!=null&&label.equalsIgnoreCase(node.getText().toString())){while(node!=null&&!node.isClickable())node=node.getParent();if(node!=null&&node.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK))consent=true;}
}
if(!consent)Thread.sleep(200);
}
if(!consent){saveScreenshot(scenario,context,"capture-consent-blocked");android.view.accessibility.AccessibilityNodeInfo root=InstrumentationRegistry.getInstrumentation().getUiAutomation().getRootInActiveWindow();System.out.println("CAPTURE_CONSENT_UI "+nativeTree(root));}assertTrue("Native screen-sharing consent was not completed",consent);
for(int n=0;n<60&&!ScreenRecordingService.active;n++)Thread.sleep(200);
assertTrue("Native recorder did not start",ScreenRecordingService.active);
startNativeRecording(scenario,context);
String name=ScreenRecordingService.activeFileName;
// Real elapsed capture on the emulator. No synthetic MediaRecorder or file-size mocks.
Thread.sleep(65000);assertTrue("Recorder stopped before 65 seconds",ScreenRecordingService.active);
js(scenario,"document.querySelector('[data-android-action=recordScreen]').click()");nativeText("Stop recording",true);
for(int n=0;n<60&&ScreenRecordingService.active;n++)Thread.sleep(200);
File video=new File(new File(context.getFilesDir(),"recordings"),name);assertTrue(video.exists());assertTrue(video.length()>0);
android.media.MediaMetadataRetriever media=new android.media.MediaMetadataRetriever();media.setDataSource(video.getAbsolutePath());long duration=Long.parseLong(media.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION));assertTrue("Native video shorter than a minute",duration>=60000);assertNotNull(media.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));media.release();
stopNativeRecording(scenario,context);
long duration=nativeVideoDurationMs(context,name);
assertTrue("Native video shorter than a minute",duration>=60000);
saveScreenshot(scenario,context,"native-recording-survives");
}finally{context.startService(new Intent(context,ScreenRecordingService.class).setAction(ScreenRecordingService.STOP));}
}
@androidx.test.filters.SdkSuppress(minSdkVersion=35) @Test public void nativeRecordingImportsIntoEditor()throws Exception{
Context context=InstrumentationRegistry.getInstrumentation().getTargetContext();
android.content.res.Configuration cfg=context.getResources().getConfiguration();
org.junit.Assume.assumeTrue("Native import runs once, in phone portrait mode",cfg.smallestScreenWidthDp<600&&cfg.orientation==android.content.res.Configuration.ORIENTATION_PORTRAIT);
try(ActivityScenario<MainActivity> scenario=launch()){
startNativeRecording(scenario,context);
// Short clip for import: decoding a 65s H.264 stream on the swiftshader
// emulator can kill the WebView renderer before the player reports duration.
Thread.sleep(6000);assertTrue("Recorder stopped before 6 seconds",ScreenRecordingService.active);
String name=stopNativeRecording(scenario,context);
long duration=nativeVideoDurationMs(context,name);
assertTrue("Native video shorter than 5 seconds",duration>=5000);
js(scenario,"document.querySelector('[data-android-action=openRecordings]').click()");nativeText("Recordings on this device",false);
// Import via the same WebView route the user opens, then verify a decoded, persistent local copy.
nativeText("Close",true);String id=name.substring(0,name.length()-4);scenario.onActivity(a->a.web.loadUrl(BuildConfig.APP_ORIGIN+"/?nativeRecording="+id));
boolean imported=false;for(int n=0;n<100;n++){if("true".equals(js(scenario,"!!document.querySelector('#player')&&document.querySelector('#player').duration>=60"))){imported=true;break;}Thread.sleep(200);}assertTrue("Native video did not import into the editor",imported);
// Import via the same WebView route the user opens. Assert the native bridge
// serves the exact recorded bytes; video decode/player is web-side and already
// covered by tests/import-media.test.js. Decoding a 65s H.264 stream on the
// swiftshader emulator kills the WebView renderer, so this test must not decode.
nativeText("Close",true);String id=name.substring(0,name.length()-4);
// evaluateJavascript cannot await a Promise (it stringifies to "{}"), so park
// the result on window and poll it like the other async checks in this suite.
js(scenario,"window.__nf=null;fetch('/__native_recordings/"+id+"').then(async r=>{window.__nf=String(r.ok)+' '+r.headers.get('content-type')+' '+String((await r.blob()).size)}).catch(e=>{window.__nf='fetch failed '+e})");
String served="pending";for(int n=0;n<50;n++){served=js(scenario,"window.__nf||'pending'").replace("\"","");if(!"pending".equals(served))break;Thread.sleep(200);}
System.out.println("NATIVE_IMPORT_FETCH "+served);
File recorded=new File(new File(context.getFilesDir(),"recordings"),name);
assertTrue("Native recording not served byte-identically: "+served+" file="+recorded.length(), served.startsWith("true video/mp4 ")&&served.endsWith(" "+recorded.length()));
assertEquals("false",js(scenario,"document.documentElement.scrollWidth>innerWidth+2"));saveScreenshot(scenario,context,"native-recording-import");
}finally{context.startService(new Intent(context,ScreenRecordingService.class).setAction(ScreenRecordingService.STOP));}
}
Expand Down
6 changes: 4 additions & 2 deletions android/emulator-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ run_mode() {
kill "$log_pid" 2>/dev/null || true
adb shell dumpsys media.codec > "android/emulator-evidence/${mode}-codecs.txt" 2>&1 || true
if [ "$result" = 0 ] && [ "$mode" = phone ]; then
if ! grep -q 'c2.android.avc.decoder' "android/emulator-evidence/${mode}-logcat.txt"; then
echo "::error::Software H.264 decoder selection was not observed; do not treat this run as deterministic software-codec acceptance."
# Recording exercises the software H.264 encoder; playback (import) exercises
# the decoder. Either line proves the deterministic software codec path.
if ! grep -qE 'c2.android.avc.(decoder|encoder)' "android/emulator-evidence/${mode}-logcat.txt"; then
echo "::error::Software H.264 codec selection was not observed; do not treat this run as deterministic software-codec acceptance."
result=1
fi
fi
Expand Down
Loading