use of org.json.JSONException in project platform_frameworks_base by android.
the class ShortcutService method dumpCheckin.
/**
* Dumpsys for checkin.
*
* @param clear if true, clear the history information. Some other system services have this
* behavior but shortcut service doesn't for now.
*/
private void dumpCheckin(PrintWriter pw, boolean clear) {
synchronized (mLock) {
try {
final JSONArray users = new JSONArray();
for (int i = 0; i < mUsers.size(); i++) {
users.put(mUsers.valueAt(i).dumpCheckin(clear));
}
final JSONObject result = new JSONObject();
result.put(KEY_SHORTCUT, users);
result.put(KEY_LOW_RAM, injectIsLowRamDevice());
result.put(KEY_ICON_SIZE, mMaxIconDimension);
pw.println(result.toString(1));
} catch (JSONException e) {
Slog.e(TAG, "Unable to write in json", e);
}
}
}
use of org.json.JSONException in project Conversations by siacs.
the class Contact method deleteOtrFingerprint.
public boolean deleteOtrFingerprint(String fingerprint) {
synchronized (this.keys) {
boolean success = false;
try {
if (this.keys.has("otr_fingerprints")) {
JSONArray newPrints = new JSONArray();
JSONArray oldPrints = this.keys.getJSONArray("otr_fingerprints");
for (int i = 0; i < oldPrints.length(); ++i) {
if (!oldPrints.getString(i).equals(fingerprint)) {
newPrints.put(oldPrints.getString(i));
} else {
success = true;
}
}
this.keys.put("otr_fingerprints", newPrints);
}
return success;
} catch (JSONException e) {
return false;
}
}
}
use of org.json.JSONException in project core by s4.
the class GenericJsonClientStub method bytesFromEventWrapper.
@Override
public byte[] bytesFromEventWrapper(EventWrapper ew) {
JSONObject jevent = new JSONObject();
Object obj = ew.getEvent();
try {
jevent.put("stream", ew.getStreamName());
jevent.put("class", obj.getClass().getName());
jevent.put("object", GsonUtil.get().toJson(obj));
return jevent.toString().getBytes(Charset.forName("UTF8"));
} catch (JSONException e) {
logger.error("exception while converting event wrapper to bytes.", e);
return null;
}
}
use of org.json.JSONException in project core by s4.
the class Handshake method clientConnectCreate.
private ClientConnection clientConnectCreate(byte[] v, ByteArrayIOChannel io, Socket sock, List<String> reason) throws IOException {
try {
JSONObject cInfo = new JSONObject(new String(v));
String s = cInfo.optString("uuid", "");
if (s.isEmpty()) {
logger.error("missing client identifier during handshake.");
reason.add("missing UUID");
return null;
}
UUID u = UUID.fromString(s);
logger.info("connecting to client " + u);
s = cInfo.optString("readMode", "Private");
ClientReadMode rmode = ClientReadMode.fromString(s);
if (rmode == null) {
logger.error(u + ": unknown readMode " + s);
reason.add("unknown readMode " + s);
return null;
}
s = cInfo.optString("writeMode", "Enabled");
ClientWriteMode wmode = ClientWriteMode.fromString(s);
if (wmode == null) {
logger.error(u + ": unknown writeMode " + s);
reason.add("unknown writeMode " + s);
return null;
}
logger.info(u + " read=" + rmode + " write=" + wmode);
if (rmode == ClientReadMode.None && wmode == ClientWriteMode.Disabled) {
// client cannot disable read AND write...
logger.error("client neither reads nor writes.");
reason.add("read and write disabled");
return null;
}
ClientConnection conn = new ClientConnection(clientStub, sock, u, rmode, wmode);
if (rmode == ClientReadMode.Select) {
JSONArray incl = cInfo.optJSONArray("readInclude");
JSONArray excl = cInfo.optJSONArray("readExclude");
if (incl == null && excl == null) {
logger.error(u + ": missing stream selection information");
reason.add("missing readInclude and readExclude");
return null;
}
if (incl != null) {
List<String> streams = new ArrayList<String>(incl.length());
for (int i = 0; i < incl.length(); ++i) streams.add(incl.getString(i));
conn.includeStreams(streams);
}
if (excl != null) {
List<String> streams = new ArrayList<String>(excl.length());
for (int i = 0; i < excl.length(); ++i) streams.add(excl.getString(i));
conn.excludeStreams(streams);
}
}
return conn;
} catch (JSONException e) {
logger.error("malformed JSON from client during handshake", e);
reason.add("malformed JSON");
} catch (NumberFormatException e) {
logger.error("received malformed UUID", e);
reason.add("malformed UUID");
} catch (IllegalArgumentException e) {
logger.error("received malformed UUID", e);
reason.add("malformed UUID");
}
return null;
}
use of org.json.JSONException in project core by s4.
the class Handshake method clientConnect.
private ClientConnection clientConnect(byte[] v, ByteArrayIOChannel io, Socket sock) throws IOException {
List<String> reason = new ArrayList<String>(1);
ClientConnection conn = clientConnectCreate(v, io, sock, reason);
String message = null;
try {
JSONObject resp = new JSONObject();
resp.put("status", (conn != null ? "ok" : "failed"));
if (conn == null && !reason.isEmpty()) {
resp.put("reason", reason.get(0));
}
message = resp.toString();
} catch (JSONException e) {
logger.error("error creating response during connect.", e);
return null;
}
io.send(message.getBytes());
return conn;
}
Aggregations