public JSONStringer generateDeviceJSON(Context context, boolean isFirst, String userAccount) { LocationUtils location = new LocationUtils(context); JSONStringer deviceJson = new JSONStringer(); try { deviceJson.object(); deviceJson.key("deviceid"); // deviceJson.value(getsDeviceIdSHA1()); deviceJson.value(getPseudoID()); deviceJson.key("useraccount"); deviceJson.value(userAccount); // /TODO deviceJson.key("devicename"); deviceJson.value(sDeviceManufacturer); deviceJson.key("devicetype"); deviceJson.value("1"); // 1手机 deviceJson.key("deviceos"); deviceJson.value(2000); // Android deviceJson.key("devicemac"); deviceJson.value(WLAN_MAC); deviceJson.key("devicephonenum"); deviceJson.value(TEL); deviceJson.key("deviceislock"); deviceJson.value(0); deviceJson.key("deviceisdel"); deviceJson.value(0); deviceJson.key("deviceinittime"); Date date = new Date(); deviceJson.value(date.getTime()); // TODO 日期格式 long型 deviceJson.key("devicevalidperiod"); deviceJson.value(365); // //TODO 暂定365天有效。服务器需要支持修改 deviceJson.key("deviceisillegal"); deviceJson.value(0); deviceJson.key("deviceisactive"); deviceJson.value(isFirst ? 1 : 0); // 第一台设备不做peer校验,直接注册 deviceJson.key("deviceislogout"); deviceJson.value(0); deviceJson.key("deviceeaster"); deviceJson.value(userAccount); deviceJson.key("bakstr1"); deviceJson.value(location.getLocation()); // TODO 目前是经度+空格+纬度 deviceJson.endObject(); Log.d(TAG, "JSON-----" + deviceJson.toString()); } catch (JSONException e) { e.printStackTrace(); } return deviceJson; }
/** * Add to the location stack all locations of an exception chain. This allows to have all possible * location information in the stacktrace, as some exceptions like SAXParseException don't output * their location in printStackTrace(). * * <p>Traversal of the call chain stops at the first <code>Locatable</code> exception which is * supposed to handle the loction of its causes by itself. * * <p>This method is static as a convenience for {@link LocatedRuntimeException other * implementations} of locatable exceptions. * * @param self the current locatable exception * @param cause a cause of <code>self</code> */ public static void addCauseLocations(MultiLocatable self, Throwable cause) { if (cause == null || cause instanceof Locatable) { // Locatable handles its location itself return; } // Add parent location first addCauseLocations(self, cause.getCause()); // then ourselve's Location loc = LocationUtils.getLocation(cause); if (LocationUtils.isKnown(loc)) { // Get the exception's short name String name = cause.getClass().getName(); int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(pos + 1); } loc = new LocationImpl( "[" + name + "]", loc.getURI(), loc.getLineNumber(), loc.getColumnNumber()); self.addLocation(loc); } }