package cn.ucvl.zhaodisplay; import org.json.*; /** Test-only transport. The fixture has no Internet permission and never calls production. */ final class DisplayApi { static volatile boolean offline=false,expired=false; 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/voice"))return new JSONObject("{\"enabled\":false,\"allowed\":[],\"candidates\":[{\"id\":\"phone:demo\",\"name\":\"示例家人的手机\"}],\"targets\":[{\"id\":\"display:demo\",\"name\":\"家庭显示终端\",\"kind\":\"display\",\"online\":true}],\"sent\":[],\"inbox\":[]}"); 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));JSONObject b=new JSONObject("{\"id\":\"b\",\"name\":\"家人乙(示例)\",\"status\":\"scheduled\",\"scheduleReason\":\"sampling\"}");return new JSONObject().put("items",new JSONArray().put(a).put(b));} 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); } }