Back to project page Android-NetPowerctrl-Shared.
The source code is released under:
Copyright (c) 2014, David Gr?ff All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...
If you think the Android project Android-NetPowerctrl-Shared listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package oly.netpowerctrl.device_base.device; /*www.j av a 2 s.com*/ import android.support.annotation.NonNull; import android.util.JsonReader; import android.util.JsonToken; import android.util.JsonWriter; import java.io.IOException; /** * This is used by extensions and their device connections. */ public class DeviceConnectionAPI extends DeviceConnection { public static final String ID = "API"; private boolean includeUseCounter = false; public DeviceConnectionAPI(Device device) { super(device); mIsAssignedByDevice = true; } @SuppressWarnings("unused") public void setIncludeUseCounter(boolean includeUseCounter) { this.includeUseCounter = includeUseCounter; } public void toJSON(JsonWriter writer) throws IOException { writer.beginObject(); writer.name("connection_type").value(ID); writer.name("HostName").value(mHostName); if (includeUseCounter) { writer.name("receivedPackets").value(receivedPackets); if (not_reachable_reason != null) writer.name("not_reachable_reason").value(not_reachable_reason); } writer.endObject(); } @Override public boolean fromJSON(@NonNull JsonReader reader, boolean beginObjectAlreadyCalled) throws IOException, ClassNotFoundException { if (!beginObjectAlreadyCalled) reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); assert name != null; switch (name) { case "not_reachable_reason": if (reader.peek() == JsonToken.STRING) not_reachable_reason = reader.nextString(); else reader.skipValue(); break; case "receivedPackets": receivedPackets = reader.nextInt(); break; case "HostName": mHostName = reader.nextString(); break; default: reader.skipValue(); break; } } reader.endObject(); if (mHostName == null) mHostName = ""; return mHostName.length() > 0; } @Override public boolean needResolveName() { return false; } @Override public int getDestinationPort() { return -1; } @Override public String getProtocol() { return ID; } @Override public boolean equalsByDestinationAddress(DeviceConnection otherConnection, boolean lookupDNSName) { return mHostName.equals(otherConnection.mHostName); } @Override public int computeHash() { StringBuilder builder = new StringBuilder(); builder.append(ID); builder.append(mHostName); return builder.toString().hashCode(); } }