Loading core/java/android/net/nsd/DnsSdServiceInfo.java +31 −16 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.net.nsd; import android.os.Parcelable; import android.os.Parcel; import java.net.InetAddress; /** * Defines a service based on DNS service discovery * {@hide} Loading @@ -27,20 +29,20 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { private String mServiceName; private String mRegistrationType; private String mServiceType; private DnsSdTxtRecord mTxtRecord; private String mHostname; private InetAddress mHost; private int mPort; DnsSdServiceInfo() { public DnsSdServiceInfo() { } DnsSdServiceInfo(String sn, String rt, DnsSdTxtRecord tr) { public DnsSdServiceInfo(String sn, String rt, DnsSdTxtRecord tr) { mServiceName = sn; mRegistrationType = rt; mServiceType = rt; mTxtRecord = tr; } Loading @@ -59,13 +61,13 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { @Override /** @hide */ public String getServiceType() { return mRegistrationType; return mServiceType; } @Override /** @hide */ public void setServiceType(String s) { mRegistrationType = s; mServiceType = s; } public DnsSdTxtRecord getTxtRecord() { Loading @@ -76,12 +78,12 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { mTxtRecord = new DnsSdTxtRecord(t); } public String getHostName() { return mHostname; public InetAddress getHost() { return mHost; } public void setHostName(String s) { mHostname = s; public void setHost(InetAddress s) { mHost = s; } public int getPort() { Loading @@ -96,7 +98,9 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { StringBuffer sb = new StringBuffer(); sb.append("name: ").append(mServiceName). append("type: ").append(mRegistrationType). append("type: ").append(mServiceType). append("host: ").append(mHost). append("port: ").append(mPort). append("txtRecord: ").append(mTxtRecord); return sb.toString(); } Loading @@ -109,9 +113,14 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { /** Implement the Parcelable interface */ public void writeToParcel(Parcel dest, int flags) { dest.writeString(mServiceName); dest.writeString(mRegistrationType); dest.writeString(mServiceType); dest.writeParcelable(mTxtRecord, flags); dest.writeString(mHostname); if (mHost != null) { dest.writeByte((byte)1); dest.writeByteArray(mHost.getAddress()); } else { dest.writeByte((byte)0); } dest.writeInt(mPort); } Loading @@ -121,9 +130,15 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { public DnsSdServiceInfo createFromParcel(Parcel in) { DnsSdServiceInfo info = new DnsSdServiceInfo(); info.mServiceName = in.readString(); info.mRegistrationType = in.readString(); info.mServiceType = in.readString(); info.mTxtRecord = in.readParcelable(null); info.mHostname = in.readString(); if (in.readByte() == 1) { try { info.mHost = InetAddress.getByAddress(in.createByteArray()); } catch (java.net.UnknownHostException e) {} } info.mPort = in.readInt(); return info; } Loading core/java/android/net/nsd/NsdManager.java +49 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,15 @@ public class NsdManager { /** @hide */ public static final int RESOLVE_SERVICE_SUCCEEDED = BASE + 17; /** @hide */ public static final int STOP_RESOLVE = BASE + 18; /** @hide */ public static final int STOP_RESOLVE_FAILED = BASE + 19; /** @hide */ public static final int STOP_RESOLVE_SUCCEEDED = BASE + 20; /** * Create a new Nsd instance. Applications use * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve Loading @@ -117,10 +126,23 @@ public class NsdManager { /** * Indicates that the operation failed because the framework is busy and * unable to service the request * unable to service the request. */ public static final int BUSY = 2; /** * Indicates that the operation failed because it is already active. */ public static final int ALREADY_ACTIVE = 3; /** * Indicates that the operation failed because maximum limit on * service registrations has reached. */ public static final int MAX_REGS_REACHED = 4; /** Interface for callback invocation when framework channel is connected or lost */ public interface ChannelListener { public void onChannelConnected(Channel c); Loading Loading @@ -188,6 +210,7 @@ public class NsdManager { private DnsSdRegisterListener mDnsSdRegisterListener; private DnsSdUpdateRegistrationListener mDnsSdUpdateListener; private DnsSdResolveListener mDnsSdResolveListener; private ActionListener mDnsSdStopResolveListener; AsyncChannel mAsyncChannel; ServiceHandler mHandler; Loading Loading @@ -278,6 +301,16 @@ public class NsdManager { (DnsSdServiceInfo) message.obj); } break; case STOP_RESOLVE_FAILED: if (mDnsSdStopResolveListener!= null) { mDnsSdStopResolveListener.onFailure(message.arg1); } break; case STOP_RESOLVE_SUCCEEDED: if (mDnsSdStopResolveListener != null) { mDnsSdStopResolveListener.onSuccess(); } break; default: Log.d(TAG, "Ignored " + message); break; Loading Loading @@ -345,6 +378,14 @@ public class NsdManager { c.mDnsSdResolveListener = b; } /** * Set the listener for stopping service resolution. Can be null. */ public void setStopResolveListener(Channel c, ActionListener b) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); c.mDnsSdStopResolveListener = b; } public void registerService(Channel c, DnsSdServiceInfo serviceInfo) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); if (serviceInfo == null) throw new IllegalArgumentException("Null serviceInfo"); Loading Loading @@ -378,6 +419,13 @@ public class NsdManager { c.mAsyncChannel.sendMessage(RESOLVE_SERVICE, serviceInfo); } public void stopServiceResolve(Channel c) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); if (c.mDnsSdResolveListener == null) throw new IllegalStateException("Resolve listener needs to be set first"); c.mAsyncChannel.sendMessage(STOP_RESOLVE); } /** * Get a reference to NetworkService handler. This is used to establish * an AsyncChannel communication with the service Loading services/java/com/android/server/NsdService.java +338 −38 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/net/nsd/DnsSdServiceInfo.java +31 −16 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.net.nsd; import android.os.Parcelable; import android.os.Parcel; import java.net.InetAddress; /** * Defines a service based on DNS service discovery * {@hide} Loading @@ -27,20 +29,20 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { private String mServiceName; private String mRegistrationType; private String mServiceType; private DnsSdTxtRecord mTxtRecord; private String mHostname; private InetAddress mHost; private int mPort; DnsSdServiceInfo() { public DnsSdServiceInfo() { } DnsSdServiceInfo(String sn, String rt, DnsSdTxtRecord tr) { public DnsSdServiceInfo(String sn, String rt, DnsSdTxtRecord tr) { mServiceName = sn; mRegistrationType = rt; mServiceType = rt; mTxtRecord = tr; } Loading @@ -59,13 +61,13 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { @Override /** @hide */ public String getServiceType() { return mRegistrationType; return mServiceType; } @Override /** @hide */ public void setServiceType(String s) { mRegistrationType = s; mServiceType = s; } public DnsSdTxtRecord getTxtRecord() { Loading @@ -76,12 +78,12 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { mTxtRecord = new DnsSdTxtRecord(t); } public String getHostName() { return mHostname; public InetAddress getHost() { return mHost; } public void setHostName(String s) { mHostname = s; public void setHost(InetAddress s) { mHost = s; } public int getPort() { Loading @@ -96,7 +98,9 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { StringBuffer sb = new StringBuffer(); sb.append("name: ").append(mServiceName). append("type: ").append(mRegistrationType). append("type: ").append(mServiceType). append("host: ").append(mHost). append("port: ").append(mPort). append("txtRecord: ").append(mTxtRecord); return sb.toString(); } Loading @@ -109,9 +113,14 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { /** Implement the Parcelable interface */ public void writeToParcel(Parcel dest, int flags) { dest.writeString(mServiceName); dest.writeString(mRegistrationType); dest.writeString(mServiceType); dest.writeParcelable(mTxtRecord, flags); dest.writeString(mHostname); if (mHost != null) { dest.writeByte((byte)1); dest.writeByteArray(mHost.getAddress()); } else { dest.writeByte((byte)0); } dest.writeInt(mPort); } Loading @@ -121,9 +130,15 @@ public class DnsSdServiceInfo implements NetworkServiceInfo, Parcelable { public DnsSdServiceInfo createFromParcel(Parcel in) { DnsSdServiceInfo info = new DnsSdServiceInfo(); info.mServiceName = in.readString(); info.mRegistrationType = in.readString(); info.mServiceType = in.readString(); info.mTxtRecord = in.readParcelable(null); info.mHostname = in.readString(); if (in.readByte() == 1) { try { info.mHost = InetAddress.getByAddress(in.createByteArray()); } catch (java.net.UnknownHostException e) {} } info.mPort = in.readInt(); return info; } Loading
core/java/android/net/nsd/NsdManager.java +49 −1 Original line number Diff line number Diff line Loading @@ -93,6 +93,15 @@ public class NsdManager { /** @hide */ public static final int RESOLVE_SERVICE_SUCCEEDED = BASE + 17; /** @hide */ public static final int STOP_RESOLVE = BASE + 18; /** @hide */ public static final int STOP_RESOLVE_FAILED = BASE + 19; /** @hide */ public static final int STOP_RESOLVE_SUCCEEDED = BASE + 20; /** * Create a new Nsd instance. Applications use * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve Loading @@ -117,10 +126,23 @@ public class NsdManager { /** * Indicates that the operation failed because the framework is busy and * unable to service the request * unable to service the request. */ public static final int BUSY = 2; /** * Indicates that the operation failed because it is already active. */ public static final int ALREADY_ACTIVE = 3; /** * Indicates that the operation failed because maximum limit on * service registrations has reached. */ public static final int MAX_REGS_REACHED = 4; /** Interface for callback invocation when framework channel is connected or lost */ public interface ChannelListener { public void onChannelConnected(Channel c); Loading Loading @@ -188,6 +210,7 @@ public class NsdManager { private DnsSdRegisterListener mDnsSdRegisterListener; private DnsSdUpdateRegistrationListener mDnsSdUpdateListener; private DnsSdResolveListener mDnsSdResolveListener; private ActionListener mDnsSdStopResolveListener; AsyncChannel mAsyncChannel; ServiceHandler mHandler; Loading Loading @@ -278,6 +301,16 @@ public class NsdManager { (DnsSdServiceInfo) message.obj); } break; case STOP_RESOLVE_FAILED: if (mDnsSdStopResolveListener!= null) { mDnsSdStopResolveListener.onFailure(message.arg1); } break; case STOP_RESOLVE_SUCCEEDED: if (mDnsSdStopResolveListener != null) { mDnsSdStopResolveListener.onSuccess(); } break; default: Log.d(TAG, "Ignored " + message); break; Loading Loading @@ -345,6 +378,14 @@ public class NsdManager { c.mDnsSdResolveListener = b; } /** * Set the listener for stopping service resolution. Can be null. */ public void setStopResolveListener(Channel c, ActionListener b) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); c.mDnsSdStopResolveListener = b; } public void registerService(Channel c, DnsSdServiceInfo serviceInfo) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); if (serviceInfo == null) throw new IllegalArgumentException("Null serviceInfo"); Loading Loading @@ -378,6 +419,13 @@ public class NsdManager { c.mAsyncChannel.sendMessage(RESOLVE_SERVICE, serviceInfo); } public void stopServiceResolve(Channel c) { if (c == null) throw new IllegalArgumentException("Channel needs to be initialized"); if (c.mDnsSdResolveListener == null) throw new IllegalStateException("Resolve listener needs to be set first"); c.mAsyncChannel.sendMessage(STOP_RESOLVE); } /** * Get a reference to NetworkService handler. This is used to establish * an AsyncChannel communication with the service Loading
services/java/com/android/server/NsdService.java +338 −38 File changed.Preview size limit exceeded, changes collapsed. Show changes