Release v0.1.54: scheduled location sessions and paged voice delivery history

This commit is contained in:
Codex
2026-10-19 07:55:36 +08:00
parent ad2614719b
commit 4dc3e2fb9f
28 changed files with 481 additions and 153 deletions
+4 -1
View File
@@ -19,7 +19,10 @@ $env:Path="$jdk\bin;$env:Path"
'@ | Set-Content -LiteralPath "$stage\AndroidManifest.xml" -Encoding utf8
& "$bt\aapt2.exe" link -o "$stage\unsigned.apk" -I $android --manifest "$stage\AndroidManifest.xml"
if($LASTEXITCODE){throw 'Test resource linking failed'}
$sources=@("$source\src\cn\ucvl\zhaodisplay\LocationActivity.java","$source\src\cn\ucvl\zhaodisplay\PhoneLayout.java","$source\src\cn\ucvl\zhaodisplay\PhoneStyle.java","$source\src\cn\ucvl\zhaodisplay\VoicePanel.java","$source\src\cn\ucvl\zhaodisplay\VoiceSurface.java","$source\src\cn\ucvl\zhaodisplay\VoiceChat.java","$source\src\cn\ucvl\zhaodisplay\VoiceGesture.java","$source\src\cn\ucvl\zhaodisplay\LocationCadence.java") + @((Get-ChildItem "$tests\phone-preview" -Filter "*.java").FullName)
$queueSource=Get-Content -LiteralPath "$source\src\cn\ucvl\zhaodisplay\LocationQueue.java" -Raw -Encoding UTF8
$queueSource=$queueSource.Replace('LocationQueue','StoredLocationQueue').Replace('location-outbox.db','storage-check.db')
[IO.File]::WriteAllText("$stage\StoredLocationQueue.java",$queueSource,(New-Object Text.UTF8Encoding($false)))
$sources=@("$stage\StoredLocationQueue.java","$source\src\cn\ucvl\zhaodisplay\LocationService.java","$source\src\cn\ucvl\zhaodisplay\LocationActivity.java","$source\src\cn\ucvl\zhaodisplay\PhoneLayout.java","$source\src\cn\ucvl\zhaodisplay\PhoneStyle.java","$source\src\cn\ucvl\zhaodisplay\VoicePanel.java","$source\src\cn\ucvl\zhaodisplay\VoiceSurface.java","$source\src\cn\ucvl\zhaodisplay\VoiceChat.java","$source\src\cn\ucvl\zhaodisplay\VoiceGesture.java","$source\src\cn\ucvl\zhaodisplay\LocationCadence.java") + @((Get-ChildItem "$tests\phone-preview" -Filter "*.java").FullName)
& "$jdk\bin\javac.exe" -encoding UTF-8 -source 8 -target 8 -cp $android -d "$stage\classes" @sources
if($LASTEXITCODE){throw 'Test Java compile failed'}
& "$jdk\bin\jar.exe" cf "$stage\classes.jar" -C "$stage\classes" .
@@ -10,6 +10,7 @@ final class DisplayApi {
if(action.equals("history")){boolean old=body.optLong("before")>0;JSONArray items=new JSONArray();for(int i=0;i<3;i++)items.put(new JSONObject().put("id","chat-"+i).put("seq",i+1).put("mine",i%2==0).put("senderName",i%2==0?"示例成员的手机":"家庭显示终端").put("at",1792387200+i*60-(old?86400:0)).put("seconds",i+3.6).put("delivery",i==2?"queued":"played").put("archive",i==2?"pending":"cloud"));return new JSONObject().put("items",items).put("before",old?0:12);}
return new JSONObject("{\"enabled\":false,\"allowed\":[],\"candidates\":[{\"id\":\"phone:demo\",\"name\":\"示例家人的手机\"}],\"targets\":[{\"id\":\"display:demo\",\"archiveKey\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}],\"conversations\":[],\"sent\":[],\"inbox\":[]}");
}
if(action.equals("update")||action.equals("stop"))return new JSONObject().put("ok",true);
if(action.equals("list")){JSONObject a=new JSONObject("{\"id\":\"a\",\"name\":\"家人甲(示例)\",\"status\":\"live\"}");a.put("position",new JSONObject().put("latitude",0).put("longitude",0).put("accuracy",25).put("at",System.currentTimeMillis()/1000-120));JSONObject b=new JSONObject("{\"id\":\"b\",\"name\":\"家人乙(示例)\",\"status\":\"scheduled\",\"scheduleReason\":\"sampling\"}");JSONObject c=new JSONObject().put("id","c").put("name","家人丙(示例)").put("position",new JSONObject().put("latitude",0).put("longitude",0).put("accuracy",10).put("at",System.currentTimeMillis()/1000));return new JSONObject().put("items",new JSONArray().put(b).put(a).put(c));}
if(action.equals("settings"))return new JSONObject("{\"receipt\":\"fixture\",\"intervalSeconds\":7200,\"sampleIntervalSeconds\":300,\"historyEnabled\":true,\"historyDefault\":true,\"viewerIds\":[],\"phoneIds\":[\"demo\"],\"displayIds\":[],\"viewers\":[],\"phones\":[{\"id\":\"demo\",\"name\":\"示例家人的手机\"}],\"displays\":[],\"history\":{\"pending\":0,\"archived\":2,\"deleting\":0}}");
throw new ApiError(403);
@@ -1,3 +1,13 @@
package cn.ucvl.zhaodisplay;
/** Test-only empty queue; never touches production storage. */
final class LocationQueue {LocationQueue(android.content.Context c){}static String digest(String s){return "fixture";}long[] stats(String owner){return new long[]{0,0,0,0};}long total(){return 0;}void discard(String owner){}}
import org.json.*;
/** In-memory synthetic queue only. Production encryption and batch checks have separate tests. */
final class LocationQueue {
static final int MAX_INFLIGHT=4;JSONObject remembered;int appended=0;
LocationQueue(android.content.Context c){}static String digest(String s){return "fixture";}static String id(){return java.util.UUID.randomUUID().toString();}
long[] stats(String owner){return new long[]{0,0,0,0};}long total(){return 0;}void discard(String owner){}
void latest(String owner,JSONObject f){remembered=f;}JSONObject latest(String owner){return remembered;}void clearLatest(String owner){remembered=null;}
boolean append(String owner,String session,JSONObject point){appended++;return true;}
boolean hasBatches(String owner){return false;}boolean ready(String owner,long cutoff){return false;}
static class Batch {JSONObject request(){return new JSONObject();}}Batch next(String owner,long cutoff,long now){return null;}
boolean acknowledge(String owner,Batch batch,JSONObject receipt){return false;}
}
@@ -0,0 +1,7 @@
package cn.ucvl.zhaodisplay;
final class LocationSchedule {
static final int SAMPLE=4501,REPORT=4502;
static boolean enabled(android.content.SharedPreferences p){return p.getBoolean("active",false)&&"scheduled".equals(p.getString("sharingMode","scheduled"))&&p.getString("token","").equals(p.getString("sessionToken",""))&&p.getLong("expires",0)>System.currentTimeMillis();}
static void cancel(android.content.Context c){}static void cancelSampling(android.content.Context c){}
static void resume(android.content.Context c){}static void arm(android.content.Context c,int id,long at){}static void retry(android.content.Context c,long delay){}
}
@@ -1,3 +1,60 @@
package cn.ucvl.zhaodisplay;
/** Test-only noncollecting service. There are no location or foreground-service permissions. */
public class LocationService extends android.app.Service {static boolean busy=false;static boolean locationEnabled(android.location.LocationManager m){return false;}public android.os.IBinder onBind(android.content.Intent i){return null;}}
import android.content.*;
import android.location.Location;
import android.os.*;
/** Runs production service control flow, with synthetic fixes and no network/GPS permission. */
final class LocationCycleChecks {
static class Probe extends LocationService {
int listens=0,finishes=0;boolean online=true;
Probe(Context c){attachBaseContext(c);onCreate();}
void notification(String s){}
void bounded(){deadline=SystemClock.elapsedRealtime()+90000;}
void listen(){listens++;capturing=true;captureStarted=System.currentTimeMillis();}
boolean connected(){return online;}
void finishWork(){finishes++;detach();}
void dispose(){destroyed=true;detach();ui.removeCallbacksAndMessages(null);worker.shutdownNow();busy=false;}
}
static void check(boolean value,String message){if(!value)throw new AssertionError(message);}
static void run(Context c,Runnable done){
SharedPreferences p=c.getSharedPreferences("location",0);long now=System.currentTimeMillis();
p.edit().putBoolean("active",true).putString("sharingMode","scheduled").putString("sessionToken","synthetic-token").putString("sessionNonce","test")
.putLong("collectionStarted",now-10000).putLong("expires",now+86400000).putInt("intervalSeconds",7200).putInt("sampleIntervalSeconds",300)
.putLong("nextReportAt",now+7200000).putBoolean("collectHistory",true).putString("collectionId","fake-session").apply();
Probe failure=new Probe(c);failure.restore();failure.deadline=SystemClock.elapsedRealtime()+90000;
p.edit().putLong("nextReportAt",0).putLong("lastLiveAt",0).apply();DisplayApi.offline=true;failure.cycle();
check(p.getBoolean("reportPending",false),"HTTP failure preserves overdue report for retry");DisplayApi.offline=false;failure.dispose();
p.edit().putBoolean("reportPending",false).putLong("nextReportAt",now+7200000).apply();
Probe receipt=new Probe(c);receipt.restore();receipt.deadline=SystemClock.elapsedRealtime()+90000;receipt.cycle();
check(p.getLong("nextReportAt",0)==now+7200000,"receipt retry never advances configured upload cadence");receipt.dispose();
Probe service=new Probe(c);service.onStartCommand(new Intent("SAMPLE").putExtra("session","test"),0,1);
check(service.listens==1&&service.capturing,"scheduled wake starts one sample");
Location fix=new Location("fixture");fix.setLatitude(0);fix.setLongitude(0);fix.setAccuracy(12);fix.setTime(System.currentTimeMillis());fix.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
service.onLocationChanged(fix);check(!service.capturing,"first fix releases listener immediately");
new Handler().postDelayed(()->{
check(service.finishes>0,"scheduled cycle completes");check(p.getBoolean("active",false),"logical sharing survives sample completion");
check(p.getLong("nextSampleAt",0)>System.currentTimeMillis(),"next sample scheduled");
check(p.getLong("nextReportAt",0)==now+7200000,"sampling does not advance upload cadence");
check(service.queue.remembered!=null&&service.queue.appended==1,"fix and history persisted once");
service.dispose();
Probe sync=new Probe(c);sync.onStartCommand(new Intent("SYNC"),0,2);
new Handler().postDelayed(()->{
check(sync.listens==0,"manual sync never starts GPS");check(sync.finishes>0,"sync cycle completes");
sync.dispose();
Probe offline=new Probe(c);offline.online=false;offline.onStartCommand(new Intent("SYNC"),0,3);
new Handler().postDelayed(()->{
check(offline.finishes>0&&!offline.capturing,"offline sync sleeps instead of permanent service");check(p.getBoolean("reportPending",false),"offline work is retained");offline.dispose();
Probe stop=new Probe(c);stop.online=false;stop.onStartCommand(new Intent("STOP"),0,4);
new Handler().postDelayed(()->{
check(!p.getBoolean("active",true)&&p.getBoolean("stopPending",false),"offline stop prevents new sampling immediately");
check(stop.finishes>0&&!stop.capturing,"offline stop service terminates");stop.dispose();
p.edit().putBoolean("active",true).putBoolean("stopPending",false).putString("sessionNonce","new").apply();
Probe realtime=new Probe(c);realtime.active=true;realtime.realtime=true;realtime.capturing=true;realtime.captureStarted=System.currentTimeMillis();realtime.collectionStarted=now-10000;
fix.setTime(System.currentTimeMillis());fix.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());realtime.onLocationChanged(fix);
check(realtime.capturing,"explicit realtime retains listener");
new Handler().postDelayed(()->{realtime.dispose();p.edit().putBoolean("active",false).putBoolean("reportPending",false).apply();done.run();},150);
},200);
},200);
},200);
},250);
}
}
@@ -18,7 +18,7 @@ public class PhonePreviewActivity extends LocationActivity {
// Limit the actual Activity layout to a phone viewport without changing display configuration.
((android.view.ViewGroup)phone.getParent()).removeView(phone);FrameLayout outer=new FrameLayout(this);outer.setBackgroundColor(PhoneStyle.PAPER);
int width="narrow".equals(mode)||"large".equals(mode)?320:390;outer.addView(phone,new FrameLayout.LayoutParams(style.dp(width),style.dp("narrow".equals(mode)?640:844),Gravity.TOP|Gravity.CENTER_HORIZONTAL));previewRoot=phone;setContentView(outer);
new Handler().postDelayed(()->{try{exercise();if(mode.equals("history"))exerciseHistory();else save();}catch(Exception e){throw new RuntimeException(e);}},1800);
new Handler().postDelayed(()->{try{exercise();if(mode.equals("history"))exerciseHistory();else if(mode.equals("cycles"))LocationCycleChecks.run(this,this::save);else if(mode.equals("storage")){QueueStorageChecks.run(this);save();}else save();}catch(Exception e){throw new RuntimeException(e);}},1800);
}
void check(boolean condition,String message){if(!condition)throw new AssertionError(message);}
void exercise()throws Exception{
@@ -34,6 +34,11 @@ public class PhonePreviewActivity extends LocationActivity {
phone.nav.getChildAt(0).performClick();check(phone.tab==0,"family navigation");
check(!prefs.getBoolean("active",false),"navigation never enables sharing");
}
if(mode.equals("modes")){
selectTab(2);sharingMode.setSelection(1);check(samplePeriodSeconds()==10&&uploadPeriod()==10,"realtime fixes both cadences to ten seconds");
sharingMode.setSelection(0);check(samplePeriodSeconds()==300&&uploadPeriod()==7200,"scheduled controls retain independent cadences");
check(!prefs.getBoolean("active",false),"choosing a mode never enables sharing");
}
if(mode.equals("mine")||mode.equals("large"))selectTab(2);
else if(mode.equals("voice")||mode.equals("recording")||mode.equals("cancel")||mode.equals("narrow")||mode.equals("history")){
selectTab(1);voice.ui.removeCallbacks(voice.visual);VoiceSurface v=voice.page();v.expand.setVisibility(View.GONE);v.destination(new JSONObject("{\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}"),true);v.recipient.setText("家庭显示终端");v.status.setText("界面验收 · 不录音、不发送语音");
@@ -0,0 +1,28 @@
package cn.ucvl.zhaodisplay;
import android.content.*;import android.database.sqlite.*;import org.json.*;
/** Production SQLite/Keystore logic runs under the fixture's separate UID and database. */
final class QueueStorageChecks {
static void check(boolean v,String msg){if(!v)throw new AssertionError(msg);}
static void run(Context c)throws Exception{
c.deleteDatabase("storage-check.db");SQLiteDatabase old=c.openOrCreateDatabase("storage-check.db",0,null);
old.execSQL("CREATE TABLE points(id TEXT PRIMARY KEY,owner TEXT NOT NULL,session TEXT NOT NULL,at INTEGER,payload BLOB NOT NULL,batch TEXT)");
old.execSQL("CREATE TABLE batches(id TEXT PRIMARY KEY,owner TEXT,session TEXT,payload BLOB,digest TEXT,count INTEGER,next_try INTEGER)");
old.execSQL("CREATE TABLE totals(owner TEXT PRIMARY KEY,uploaded INTEGER NOT NULL,freed INTEGER NOT NULL)");
old.execSQL("INSERT INTO points VALUES ('old','legacy','old-session',1,X'01',NULL)");old.setVersion(1);old.close();
StoredLocationQueue q=new StoredLocationQueue(c);
check(q.stats("legacy")[0]==1,"v1 pending rows survive migration");
check(q.getReadableDatabase().getVersion()==2,"database migrated to v2");
q.discard("legacy");String owner=StoredLocationQueue.digest("synthetic"),session="test-session";
JSONObject point=new JSONObject().put("latitude",0).put("longitude",0).put("accuracy",5).put("at",System.currentTimeMillis()/1000d);
q.latest(owner,point);check(q.latest(owner).getDouble("latitude")==0,"encrypted latest round trip");
check(q.append(owner,session,point),"encrypted sample persisted");
StoredLocationQueue.Batch batch=q.next(owner,System.currentTimeMillis()+1000,System.currentTimeMillis());
check(batch!=null,"batch created");JSONObject accepted=new JSONObject().put("batchId",batch.id).put("sha256",batch.digest).put("count",batch.count).put("state","accepted");
check(!q.acknowledge(owner,batch,accepted)&&q.stats(owner)[0]==1,"accepted receipt keeps local data");
try{q.acknowledge(owner,batch,new JSONObject(accepted.toString()).put("sha256","wrong").put("state","verified"));throw new AssertionError("mismatched receipt accepted");}catch(SecurityException expected){}
check(q.stats(owner)[0]==1,"invalid receipt keeps pending row");
check(q.acknowledge(owner,batch,accepted.put("state","verified")),"verified receipt clears batch");
check(q.stats(owner)[0]==0&&q.stats(owner)[2]==1,"only verified point removed");
q.clearLatest(owner);check(q.latest(owner)==null,"latest removed on stop");q.close();c.deleteDatabase("storage-check.db");
}
}