feat: add typed data and views with scoped device power
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
/** Pure Java checks: no transport, credentials, Android runtime or physical power operations. */
|
||||
public class PhonePowerModelTest {
|
||||
static int assertions;
|
||||
static void check(boolean condition,String description){assertions++;if(!condition)throw new AssertionError(description);}
|
||||
static PhonePowerModel power(int run,int op,String state,long at,boolean start,boolean shutdown,boolean managed){return new PhonePowerModel(run,op,state,at,start,shutdown,managed);}
|
||||
public static void main(String[] args){
|
||||
PhonePowerModel online=power(1,0,"online",1000,false,true,true);
|
||||
check(online.run(1045)==1,"fresh online RUN remains observed at TTL boundary");
|
||||
check(online.may(2,1045,false),"fresh explicitly allowed shutdown");
|
||||
check(!online.may(1,1000,false),"online cannot be started even when caller chooses OP1");
|
||||
check(online.run(1046)==-1,"stale RUN must become unknown");
|
||||
check(!online.may(2,1046,false),"stale permission cannot enable shutdown");
|
||||
PhonePowerModel offline=power(0,0,"offline",1000,true,false,true);
|
||||
check(offline.run(1000)==0&&offline.may(1,1000,false),"fresh offline asset allows granted start");
|
||||
check(!offline.may(2,1000,false),"offline cannot be shut down");
|
||||
check(!power(0,0,"offline",1000,false,false,true).may(1,1000,false),"view grant is not control grant");
|
||||
check(!power(1,0,"online",1000,true,true,false).may(2,1000,false),"unmanaged assets cannot receive power commands");
|
||||
check(!online.may(2,1000,true),"in flight request blocks repeated taps");
|
||||
for(int op:new int[]{1,2}){
|
||||
PhonePowerModel pending=power(1,op,"online",1000,true,true,true);
|
||||
check(pending.run(1000)==1,"OP must not infer RUN");
|
||||
check(!pending.may(1,1000,false)&&!pending.may(2,1000,false),"server pending OP blocks further commands");
|
||||
}
|
||||
for(PhonePowerModel invalid:new PhonePowerModel[]{power(-1,0,"unknown",1000,true,true,true),power(0,0,"online",1000,true,true,true),power(1,0,"offline",1000,true,true,true),power(1,0,"online",0,true,true,true),power(1,0,"online",1100,true,true,true),power(1,7,"online",1000,true,true,true)}){
|
||||
check(invalid.run(1000)==-1,"unknown, inconsistent or invalid server state fails closed");
|
||||
check(!invalid.may(1,1000,false)&&!invalid.may(2,1000,false),"invalid state disables both actions");
|
||||
}
|
||||
check(!online.may(0,1000,false)&&!online.may(3,1000,false),"only OP1 and OP2 are executable");
|
||||
|
||||
PhoneHomeSession session=new PhoneHomeSession();
|
||||
session.bind("paired-a",true,1);PhoneHomeSession.Ticket first=session.begin();
|
||||
check(session.accepts(first,"paired-a"),"current paired foreground request accepted");
|
||||
check(!session.accepts(first,"paired-b"),"token supplier change rejects callback before next render");
|
||||
session.bind("paired-a",true,1);check(session.accepts(first,"paired-a"),"same context refresh retains request");
|
||||
PhoneHomeSession.Ticket newer=session.begin();check(!session.accepts(first,"paired-a")&&session.accepts(newer,"paired-a"),"newer request supersedes old response");
|
||||
session.bind("paired-a",true,2);check(!session.accepts(newer,"paired-a"),"tab switch invalidates callbacks");
|
||||
PhoneHomeSession.Ticket tab=session.begin();session.bind("paired-a",false,2);check(!session.accepts(tab,"paired-a"),"pause invalidates callbacks");
|
||||
session.bind("paired-a",true,2);check(!session.accepts(tab,"paired-a"),"resume cannot revive pre-pause response");
|
||||
PhoneHomeSession.Ticket rebound=session.begin();session.bind("paired-b",true,2);check(!session.accepts(rebound,"paired-a")&&!session.accepts(rebound,"paired-b"),"re-pair invalidates old identity");
|
||||
session.bind("",true,2);try{session.begin();throw new AssertionError("unpaired request allowed");}catch(IllegalStateException expected){assertions++;}
|
||||
session.bind("paired-b",false,2);try{session.begin();throw new AssertionError("background request allowed");}catch(IllegalStateException expected){assertions++;}
|
||||
System.out.println("Phone power/session: "+assertions+" assertions passed");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
/** Executes real URL construction and WebView allowlists without network or Android runtime. */
|
||||
public class ServerEndpointTest {
|
||||
static int assertions;
|
||||
static void check(boolean condition,String message){assertions++;if(!condition)throw new AssertionError(message);}
|
||||
public static void main(String[] args){
|
||||
check(ServerEndpoint.api("/api/phone/home").equals("https://home.ucvl.cn/api/phone/home"),"phone API uses the official domain");
|
||||
check(ServerEndpoint.api("/api/display/heartbeat").equals("https://home.ucvl.cn/api/display/heartbeat"),"display heartbeat shares the same endpoint");
|
||||
check(ServerEndpoint.MAP_PHONE.equals("https://home.ucvl.cn/maps/phone"),"first-party map entry uses official origin");
|
||||
check(ServerEndpoint.tvNavigation(ServerEndpoint.TV+"?client=android&load=42#display=fixture"),"display pairing fragment stays on official TV origin");
|
||||
check(ServerEndpoint.tvNavigation("https://home.ucvl.cn:443/tv/child"),"explicit HTTPS default port and TV child allowed");
|
||||
for(String url:new String[]{"https://home.ucvl.cn/maps/phone","https://home.ucvl.cn:443/maps/tile?z=1&x=1&y=0","https://home.ucvl.cn/ui/assets/map-abc.js"})check(ServerEndpoint.mapResource(url),"allow only first-party map resources: "+url);
|
||||
check(ServerEndpoint.mapPage("https://home.ucvl.cn/maps/phone?theme=day"),"ready callback accepts exact map document with query");
|
||||
check(!ServerEndpoint.mapPage("https://home.ucvl.cn/maps/phone-evil"),"map ready is not a prefix match");
|
||||
check(!ServerEndpoint.mapPage("https://home.ucvl.cn/maps/tile"),"tile cannot mark map document ready");
|
||||
for(String url:new String[]{null,"","http://home.ucvl.cn/maps/phone","https://zhao.ucvl.cn/maps/phone","https://home.ucvl.cn.evil.invalid/maps/phone","https://evil.invalid@home.ucvl.cn/maps/phone","https://home.ucvl.cn@evil.invalid/maps/phone","https://home.ucvl.cn:444/maps/phone","https://home.ucvl.cn./maps/phone","//home.ucvl.cn/maps/phone","file:///maps/phone","javascript:alert(1)","https://home.ucvl.cn/maps/../api/private","https://home.ucvl.cn/maps/%2e%2e/api/private","https://home.ucvl.cn/maps/%252e%252e/api/private","https://home.ucvl.cn/maps/%2f..%2fapi/private","https://home.ucvl.cn/maps\\phone","https://home.ucvl.cn/maps//phone"}){
|
||||
check(!ServerEndpoint.mapResource(url),"reject unsafe map resource: "+url);
|
||||
check(!ServerEndpoint.mapPage(url),"reject unsafe map completion URL: "+url);
|
||||
}
|
||||
for(String url:new String[]{"https://home.ucvl.cn/api/phone/home","https://home.ucvl.cn/maps","https://home.ucvl.cn/ui/assets-evil/map.js","https://home.ucvl.cn/ui/private"})check(!ServerEndpoint.mapResource(url),"reject unrelated first-party path: "+url);
|
||||
for(String url:new String[]{"https://home.ucvl.cn/tv-evil","https://home.ucvl.cn/tv/../api","https://home.ucvl.cn:8443/tv","https://evil.invalid/tv","https://zhao.ucvl.cn/tv","https://home.ucvl.cn/maps/phone","https://user@home.ucvl.cn/tv","http://home.ucvl.cn/tv"})check(!ServerEndpoint.tvNavigation(url),"reject unsafe TV navigation: "+url);
|
||||
for(String path:new String[]{null,"","api/voice","//evil.invalid/api/voice","https://evil.invalid/api/voice","/maps/phone","/api/../tv","/api/%2e%2e/tv","/api/voice#token"}){
|
||||
try{ServerEndpoint.api(path);throw new AssertionError("unsafe API path accepted: "+path);}catch(IllegalArgumentException expected){assertions++;}
|
||||
}
|
||||
System.out.println("Server endpoint allowlist: "+assertions+" assertions passed");
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ if($LASTEXITCODE){throw 'Test resource linking failed'}
|
||||
$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)
|
||||
$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\PhoneHomePanel.java","$source\src\cn\ucvl\zhaodisplay\PhonePowerModel.java","$source\src\cn\ucvl\zhaodisplay\PhoneHomeSession.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" .
|
||||
|
||||
@@ -6,6 +6,7 @@ final class DisplayApi {
|
||||
static class ApiError extends Exception {final int status;ApiError(int status){this.status=status;}}
|
||||
static JSONObject call(String path,String token,JSONObject body)throws Exception{
|
||||
if(expired)throw new ApiError(401);if(offline)throw new ApiError(503);String action=body.optString("action");
|
||||
if(path.equals("/api/phone/home"))return HomeFixture.call(token,body);
|
||||
if(path.equals("/api/voice")){
|
||||
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\":[]}");
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
/** Entirely synthetic grants and machines. Test APK has no Internet permission. */
|
||||
final class HomeFixture {
|
||||
static volatile String mode="";static volatile int commands;static volatile JSONObject lastCommand;
|
||||
static volatile boolean holdNextCatalog=false,held=false,release=false;
|
||||
static JSONObject power(String id)throws Exception{
|
||||
long now=System.currentTimeMillis()/1000;boolean offline=id.equals("demo-offline"),unknown=mode.equals("devices-unknown");
|
||||
int op=mode.equals("devices-pending")?2:0;
|
||||
JSONObject p=new JSONObject().put("run",unknown?JSONObject.NULL:offline?0:1).put("op",op).put("state",unknown?"unknown":offline?"offline":"online").put("checkedAt",now-(mode.equals("devices-stale")?90:0)).put("canStart",offline&&!unknown&&op==0).put("canShutdown",!offline&&!unknown&&op==0&&!mode.equals("devices-view-only")).put("managed",true);
|
||||
p.put("last",op==0?JSONObject.NULL:new JSONObject().put("id","bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb").put("op",2).put("status","pending").put("result","等待设备确认").put("at",now));return p;
|
||||
}
|
||||
static JSONObject device(String id,String name,String family)throws Exception{return new JSONObject().put("id",id).put("source","managed").put("name",name).put("deviceType","computer").put("familyId",family).put("familyName",family.equals("demo-home")?"演示家庭":"演示工作室").put("siteName","演示书房").put("power",power(id));}
|
||||
static JSONObject call(String token,JSONObject body)throws Exception{
|
||||
if(token==null||token.isEmpty())throw new AssertionError("phone home requires the pairing bearer token");
|
||||
if(mode.equals("devices-denied"))throw new DisplayApi.ApiError(403);
|
||||
String action=body.getString("action");
|
||||
if(action.equals("catalog")){
|
||||
JSONArray families=new JSONArray().put(new JSONObject().put("id","demo-home").put("name","演示家庭").put("kind","family"));
|
||||
JSONArray devices=new JSONArray();
|
||||
if(!mode.equals("devices-empty")&&!token.equals("rebound-token")){families.put(new JSONObject().put("id","demo-office").put("name","演示工作室").put("kind","office"));devices.put(device("demo-online","演示笔记本","demo-home")).put(device("demo-offline","演示工作电脑","demo-office"));}
|
||||
JSONObject result=new JSONObject().put("households",families).put("devices",devices).put("activeId","demo-home");
|
||||
if(holdNextCatalog){holdNextCatalog=false;held=true;long until=System.currentTimeMillis()+5000;while(!release&&System.currentTimeMillis()<until)Thread.sleep(10);held=false;}
|
||||
return result;
|
||||
}
|
||||
if(action.equals("status"))return new JSONObject().put("power",power(body.getString("deviceId")));
|
||||
if(action.equals("command")){
|
||||
if(!body.optBoolean("confirm")||!body.optString("requestId").matches("[0-9a-f]{32}"))throw new AssertionError("command must carry explicit confirm and a unique request id");
|
||||
int op=body.optInt("op");if(op!=1&&op!=2)throw new AssertionError("only discrete power operations");
|
||||
commands++;lastCommand=body;JSONObject p=power(body.getString("deviceId"));p.put("op",op).put("canStart",false).put("canShutdown",false).put("last",new JSONObject().put("id",body.getString("requestId")).put("op",op).put("status","pending").put("result","已提交演示请求").put("at",System.currentTimeMillis()/1000));return new JSONObject().put("power",p);
|
||||
}
|
||||
throw new AssertionError("unexpected home action "+action);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.ucvl.zhaodisplay;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Handler;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
/** Exercises production navigation and native power cards through isolated API responses. */
|
||||
final class HomePanelChecks {
|
||||
static Button button(View root,String text){if(root instanceof Button&&((Button)root).getText().toString().equals(text))return (Button)root;if(root instanceof ViewGroup){ViewGroup group=(ViewGroup)root;for(int i=0;i<group.getChildCount();i++){Button b=button(group.getChildAt(i),text);if(b!=null)return b;}}return null;}
|
||||
static boolean text(View root,String value){if(root instanceof TextView&&((TextView)root).getText().toString().contains(value))return true;if(root instanceof ViewGroup){ViewGroup group=(ViewGroup)root;for(int i=0;i<group.getChildCount();i++)if(text(group.getChildAt(i),value))return true;}return false;}
|
||||
static void later(Runnable action){new Handler().postDelayed(action,500);}
|
||||
static void run(PhonePreviewActivity a,Runnable done){
|
||||
a.selectTab(PhoneLayout.HOUSEHOLDS);
|
||||
later(()->{
|
||||
PhoneHomePanel panel=a.phoneHome;
|
||||
if(a.mode.equals("devices-denied")){a.check(panel.devices.getChildCount()==0,"denied grant clears device cards");a.selectTab(PhoneLayout.DEVICES);later(()->{a.check(text(a.phone.pages[PhoneLayout.DEVICES],"授权"),"denied access is explicit");done.run();});return;}
|
||||
a.check(text(panel.households,"演示家庭"),"paired household remains visible");
|
||||
if(a.mode.equals("devices-empty")){a.check(panel.devices.getChildCount()==0,"pairing alone grants no devices");a.selectTab(PhoneLayout.DEVICES);later(()->{a.check(text(a.phone.pages[PhoneLayout.DEVICES],"管理员"),"empty grant tells user to contact administrator");done.run();});return;}
|
||||
a.check(panel.households.getChildCount()==2,"only API-authorized households shown");
|
||||
if(a.mode.startsWith("households")){done.run();return;}
|
||||
button(panel.households,"查看设备").performClick();
|
||||
later(()->{
|
||||
a.check(a.phone.tab==PhoneLayout.DEVICES,"household selection opens device page");
|
||||
a.check(panel.devices.getChildCount()==1&&text(panel.devices,"演示笔记本")&&!text(panel.devices,"演示工作电脑"),"family selection scopes visible devices");
|
||||
a.check(text(panel.devices,"演示书房")&&text(panel.devices,"RUN")&&text(panel.devices,"OP")&&text(panel.devices,"检查时间")&&text(panel.devices,"最近结果"),"managed card exposes location and measured state details");
|
||||
Button start=button(panel.devices,"开机"),stop=button(panel.devices,"关机");
|
||||
a.check(!start.isEnabled(),"online device start disabled");
|
||||
boolean blocked=a.mode.equals("devices-stale")||a.mode.equals("devices-unknown")||a.mode.equals("devices-pending")||a.mode.equals("devices-view-only");
|
||||
a.check(stop.isEnabled()!=blocked,"shutdown follows freshness, pending OP and explicit grant");
|
||||
if(a.mode.equals("devices-stale")||a.mode.equals("devices-unknown"))a.check(text(panel.devices,"未知"),"stale/unknown RUN never presented as online");
|
||||
a.check(start.getHeight()>=a.style.dp(48)&&stop.getHeight()>=a.style.dp(48),"power controls preserve touch targets on narrow/large text views");
|
||||
a.check(stop.getWidth()>a.style.dp(150),"stacked controls retain usable width");
|
||||
if(a.mode.equals("devices-token")||a.mode.equals("devices-lifecycle")){
|
||||
HomeFixture.release=false;HomeFixture.holdNextCatalog=true;panel.deviceRefresh.performClick();
|
||||
later(()->{a.check(HomeFixture.held,"catalog response is delayed at the network boundary");
|
||||
if(a.mode.equals("devices-token")){a.prefs.edit().putString("token","rebound-token").commit();panel.contextChanged();}else panel.active(false);
|
||||
HomeFixture.release=true;later(()->{a.check(panel.devices.getChildCount()==0,"old identity/lifecycle callback cannot restore device grants");
|
||||
if(a.mode.equals("devices-lifecycle")){panel.active(true);later(()->{a.check(panel.devices.getChildCount()==1,"resume reloads authorized current catalog");done.run();});}else done.run();
|
||||
});
|
||||
});return;
|
||||
}
|
||||
if(a.mode.equals("devices-revoked")){
|
||||
HomeFixture.mode="devices-denied";panel.deviceRefresh.performClick();later(()->{a.check(panel.devices.getChildCount()==0&&text(a.phone.pages[PhoneLayout.DEVICES],"授权"),"revocation clears previously visible controls");done.run();});return;
|
||||
}
|
||||
if(a.mode.equals("devices-command")){
|
||||
int before=HomeFixture.commands;stop.performClick();a.check(panel.confirmation!=null&&panel.confirmation.isShowing(),"shutdown has native confirmation");a.check(HomeFixture.commands==before,"opening confirmation never dispatches");panel.confirmation.getButton(AlertDialog.BUTTON_NEGATIVE).performClick();a.check(HomeFixture.commands==before,"cancel leaves machine untouched");stop.performClick();panel.confirmation.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
||||
later(()->{a.check(HomeFixture.commands==before+1&&HomeFixture.lastCommand.optInt("op")==2,"confirmed shutdown dispatches exactly once");a.check(!button(panel.devices,"关机").isEnabled(),"pending command disables repeat");done.run();});return;
|
||||
}
|
||||
if(a.mode.equals("devices-offline")){
|
||||
a.selectTab(PhoneLayout.HOUSEHOLDS);later(()->{button((ViewGroup)panel.households.getChildAt(1),"查看设备").performClick();later(()->{a.check(text(panel.devices,"RUN 0")&&button(panel.devices,"开机").isEnabled()&&!button(panel.devices,"关机").isEnabled(),"offline explicit control grant enables only start");done.run();});});return;
|
||||
}
|
||||
done.run();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,14 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
protected void attachBaseContext(android.content.Context base){android.content.res.Configuration c=new android.content.res.Configuration(base.getResources().getConfiguration());c.densityDpi=420;super.attachBaseContext(base.createConfigurationContext(c));}
|
||||
public void onCreate(Bundle state){
|
||||
mode=getIntent().getStringExtra("mode");if(mode==null)mode="family";
|
||||
if(mode.equals("large")||mode.equals("settings-large")||mode.equals("voice-large")){android.content.res.Configuration cfg=new android.content.res.Configuration(getResources().getConfiguration());cfg.fontScale=1.35f;getResources().updateConfiguration(cfg,getResources().getDisplayMetrics());}
|
||||
DisplayApi.offline="offline".equals(mode);DisplayApi.expired="expired".equals(mode);
|
||||
if(mode.equals("large")||mode.equals("settings-large")||mode.equals("voice-large")||mode.equals("devices-large")){android.content.res.Configuration cfg=new android.content.res.Configuration(getResources().getConfiguration());cfg.fontScale=1.35f;getResources().updateConfiguration(cfg,getResources().getDisplayMetrics());}
|
||||
HomeFixture.mode=mode;DisplayApi.offline="offline".equals(mode);DisplayApi.expired="expired".equals(mode);
|
||||
getSharedPreferences("location",0).edit().clear().putString("token","unpaired".equals(mode)?"":"synthetic-token").putString("memberName","示例成员").putString("home","我的家 · 演示家庭").putLong("expires",System.currentTimeMillis()+86400000L).putString("status","共享关闭 · 可以查看已授权的家人").apply();
|
||||
super.onCreate(state);
|
||||
// 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)||"voice-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 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);
|
||||
int width="narrow".equals(mode)||"large".equals(mode)||"voice-large".equals(mode)||"devices-narrow".equals(mode)||"devices-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.startsWith("devices")||mode.startsWith("households"))HomePanelChecks.run(this,this::save);else 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{
|
||||
@@ -28,32 +28,32 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
check(map.items.optJSONObject(0).optString("id").equals("c")&&map.items.optJSONObject(2).optString("id").equals("b"),"collection time descending, missing fixes last");
|
||||
((android.view.ViewGroup)familyList.getChildAt(0)).getChildAt(1).performClick();check(map.focused==map.items.optJSONObject(0).optJSONObject("position"),"row focuses the matching point");
|
||||
check(voice.getParent()==null,"no voice dock on the position page");check(voice.dock.receiverCard.getParent()==phone.voiceSettings,"receiver controls belong to my settings");
|
||||
phone.nav.getChildAt(2).performClick();check(phone.tab==2,"mine tab click");phone.sampling.performClick();check(detailDialog!=null&&detailDialog.isShowing(),"sampling opens full screen");detailDialog.dismiss();
|
||||
phone.nav.getChildAt(PhoneLayout.MINE).performClick();check(phone.tab==PhoneLayout.MINE,"mine tab click");phone.sampling.performClick();check(detailDialog!=null&&detailDialog.isShowing(),"sampling opens full screen");detailDialog.dismiss();
|
||||
check(sampleCadence.getParent()==sampleSection,"sample controls retain their owner");
|
||||
phone.upload.performClick();check(detailDialog!=null,"upload detail");detailDialog.dismiss();
|
||||
phone.nav.getChildAt(0).performClick();check(phone.tab==0,"family navigation");
|
||||
phone.nav.getChildAt(PhoneLayout.LOCATION).performClick();check(phone.tab==PhoneLayout.LOCATION,"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");
|
||||
selectTab(PhoneLayout.MINE);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);
|
||||
if(mode.equals("mine")||mode.equals("large"))selectTab(PhoneLayout.MINE);
|
||||
else if(mode.equals("voice")||mode.equals("voice-large")||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("界面验收 · 不录音、不发送语音");
|
||||
selectTab(PhoneLayout.COMMUNICATION);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("界面验收 · 不录音、不发送语音");
|
||||
boolean recording=mode.equals("recording")||mode.equals("cancel");for(int i=0;i<31;i++)v.recording(recording,mode.equals("cancel"),8000,(int)(9000*Math.abs(Math.sin(i))),false,true);
|
||||
}
|
||||
else if(mode.equals("unpaired")){check(shareControls.getVisibility()==View.GONE,"unpaired share controls hidden");check(phone.tab==2,"unpaired starts on my page");}
|
||||
else selectTab(0);
|
||||
else if(mode.equals("unpaired")){check(shareControls.getVisibility()==View.GONE,"unpaired share controls hidden");check(phone.tab==PhoneLayout.MINE,"unpaired starts on my page");}
|
||||
else selectTab(PhoneLayout.LOCATION);
|
||||
if(mode.equals("expired")){check(pairingRequired(),"expired requires re-pairing");check(!sharing.isEnabled(),"expired cannot start sharing");phone.check.performClick();check(detailDialog!=null&&pairSection.getParent()!=settings,"status routes to pairing instead of OS permission settings");detailDialog.dismiss();}
|
||||
if(mode.equals("offline")){check(familyList.getChildCount()==0,"offline stale positions removed");check(!sharing.isEnabled(),"offline cannot start sharing");}
|
||||
check(phone.nav.getChildCount()==3,"exactly three tabs");check(phone.navLabels[0].getText().toString().equals("位置")&&phone.navLabels[1].getText().toString().equals("沟通"),"requested navigation names");
|
||||
check(phone.nav.getChildCount()==5,"exactly five tabs");String[] names={"位置","家庭","设备","沟通","我的"};for(int i=0;i<names.length;i++)check(phone.navLabels[i].getText().toString().equals(names[i]),"requested navigation names");
|
||||
check(voice.page().receiverCard.getParent()==null,"communication page does not duplicate settings");
|
||||
check(phone.nav.getChildAt(phone.tab).isSelected(),"active Bootstrap navigation state");
|
||||
Button disabled=style.button("测试",false);disabled.setEnabled(false);check(disabled.getCurrentTextColor()==0xff868e96,"disabled button has distinct text color");
|
||||
if(mode.startsWith("settings")||mode.equals("upload-settings")||mode.equals("pair-settings")){
|
||||
selectTab(2);boolean upload=mode.equals("upload-settings"),pair=mode.equals("pair-settings");showDetail(pair?"配对与设备":upload?"集中上传与离线暂存":"共享模式与采集频率",pair?pairSection:upload?uploadSection:sampleSection);
|
||||
selectTab(PhoneLayout.MINE);boolean upload=mode.equals("upload-settings"),pair=mode.equals("pair-settings");showDetail(pair?"配对与设备":upload?"集中上传与离线暂存":"共享模式与采集频率",pair?pairSection:upload?uploadSection:sampleSection);
|
||||
if(upload){cadence.setSelection(uploadIntervals.length-1);}else if(!pair){sampleCadence.setSelection(sampleIntervals.length-1);}
|
||||
detailDialog.getWindow().setLayout(style.dp(mode.equals("settings-narrow")||mode.equals("settings-large")?320:390),style.dp(720));previewRoot=detailDialog.getWindow().getDecorView();
|
||||
check(pair||((upload?cadence:sampleCadence).getAdapter() instanceof PhoneStyle.FormAdapter),"native Bootstrap select adapter installed");
|
||||
@@ -63,5 +63,5 @@ public class PhonePreviewActivity extends LocationActivity {
|
||||
void exerciseHistory(){
|
||||
new Handler().postDelayed(()->{check(voice.nextBefore==12,"history initial page");voice.page().chat.older.performClick();new Handler().postDelayed(()->{check(voice.historyBefore==12&&voice.nextBefore==0,"older page loaded");check(!voice.page().chat.older.isEnabled(),"end of history disables older");voice.page().chat.latest.performClick();new Handler().postDelayed(()->{check(voice.historyBefore==0&&voice.nextBefore==12,"return to latest page");check(!voice.enabled,"reading history does not enable reception");save();},250);},250);},250);
|
||||
}
|
||||
void save(){previewRoot.postDelayed(()->{try{if(detailDialog==null)check(sampleSection.getParent()==settings&&uploadSection.getParent()==settings,"dismissed forms safely returned after queued dialog callbacks");else{EditText field=mode.equals("pair-settings")?code:mode.equals("upload-settings")?customAmount:sampleAmount;check(field.getHeight()>=style.dp(48),"form fields retain accessible touch height");check(field.getWidth()>style.dp(60),"custom amount retains usable width");if(!mode.equals("pair-settings")){LinearLayout period=mode.equals("upload-settings")?customPeriod:samplePeriod;View unit=mode.equals("upload-settings")?customUnit:sampleUnit;check(unit.getBottom()<=period.getHeight(),"unit selector is not clipped by baseline alignment");}}if(phone.tab==1){check(voice.page().chat.messages.getChildCount()==3,"real controller loads chat history");check(voice.nextBefore==12,"older history cursor available");check(voice.page().chat.scroll.getHeight()>=style.dp(90),"chat viewport="+voice.page().chat.scroll.getHeight()+", root="+voice.page().getHeight()+", chat="+voice.page().chat.getHeight()+", compose="+voice.page().compose.getHeight()+", compact="+voice.page().compact);check(voice.page().speak.getHeight()>=style.dp(110),"microphone remains a large target");}android.graphics.Bitmap b=android.graphics.Bitmap.createBitmap(previewRoot.getWidth(),previewRoot.getHeight(),android.graphics.Bitmap.Config.ARGB_8888);previewRoot.draw(new android.graphics.Canvas(b));try(java.io.FileOutputStream f=new java.io.FileOutputStream(new java.io.File(getExternalFilesDir(null),"preview.png"))){b.compress(android.graphics.Bitmap.CompressFormat.PNG,100,f);}b.recycle();try(java.io.FileWriter f=new java.io.FileWriter(new java.io.File(getExternalFilesDir(null),"checks.txt"))){f.write("PASS "+mode+" production navigation, chronological list, focus, chat visibility and settings ownership");}}catch(Exception e){throw new RuntimeException(e);}},600);}
|
||||
void save(){previewRoot.postDelayed(()->{try{if(detailDialog==null)check(sampleSection.getParent()==settings&&uploadSection.getParent()==settings,"dismissed forms safely returned after queued dialog callbacks");else{EditText field=mode.equals("pair-settings")?code:mode.equals("upload-settings")?customAmount:sampleAmount;check(field.getHeight()>=style.dp(48),"form fields retain accessible touch height");check(field.getWidth()>style.dp(60),"custom amount retains usable width");if(!mode.equals("pair-settings")){LinearLayout period=mode.equals("upload-settings")?customPeriod:samplePeriod;View unit=mode.equals("upload-settings")?customUnit:sampleUnit;check(unit.getBottom()<=period.getHeight(),"unit selector is not clipped by baseline alignment");}}if(phone.tab==PhoneLayout.COMMUNICATION){check(voice.page().chat.messages.getChildCount()==3,"real controller loads chat history");check(voice.nextBefore==12,"older history cursor available");check(voice.page().chat.scroll.getHeight()>=style.dp(90),"chat viewport="+voice.page().chat.scroll.getHeight()+", root="+voice.page().getHeight()+", chat="+voice.page().chat.getHeight()+", compose="+voice.page().compose.getHeight()+", compact="+voice.page().compact);check(voice.page().speak.getHeight()>=style.dp(110),"microphone remains a large target");}android.graphics.Bitmap b=android.graphics.Bitmap.createBitmap(previewRoot.getWidth(),previewRoot.getHeight(),android.graphics.Bitmap.Config.ARGB_8888);previewRoot.draw(new android.graphics.Canvas(b));try(java.io.FileOutputStream f=new java.io.FileOutputStream(new java.io.File(getExternalFilesDir(null),"preview.png"))){b.compress(android.graphics.Bitmap.CompressFormat.PNG,100,f);}b.recycle();try(java.io.FileWriter f=new java.io.FileWriter(new java.io.File(getExternalFilesDir(null),"checks.txt"))){f.write("PASS "+mode+" production navigation, chronological list, focus, chat visibility and settings ownership");}}catch(Exception e){throw new RuntimeException(e);}},600);}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
param([string]$ToolRoot='C:\Users\Administrator\Documents\ChatGPT\优创未来\services\toplc-vpn-android\.tools')
|
||||
$ErrorActionPreference='Stop'
|
||||
$source=Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||
$stage=Join-Path $env:TEMP ('ZhaoPhoneModel-'+[guid]::NewGuid().ToString('N'))
|
||||
New-Item -ItemType Directory -Path $stage | Out-Null
|
||||
$jdk=Join-Path $ToolRoot 'jdk-staging\jdk-21.0.12.1+1'
|
||||
$files=@('PhonePowerModel','PhoneHomeSession','LocationCadence','VoiceGesture','ServerEndpoint') | ForEach-Object {Join-Path $source "src\cn\ucvl\zhaodisplay\$_.java"}
|
||||
$tests=@('PhonePowerModelTest','LocationCadenceTest','VoiceGestureTest','ServerEndpointTest') | ForEach-Object {Join-Path $source "tests\$_.java"}
|
||||
& "$jdk\bin\javac.exe" -encoding UTF-8 -d $stage @files @tests
|
||||
if($LASTEXITCODE){throw 'Phone model Java compilation failed'}
|
||||
foreach($test in @('PhonePowerModelTest','LocationCadenceTest','VoiceGestureTest','ServerEndpointTest')){
|
||||
& "$jdk\bin\java.exe" -cp $stage "cn.ucvl.zhaodisplay.$test"
|
||||
if($LASTEXITCODE){throw "$test failed"}
|
||||
}
|
||||
Reference in New Issue
Block a user