Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 817388e0 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Bonjour fixes

Change-Id: I1df1dc470bb42c84abc7e1a46bedf9f206910b65
parent 63c115c4
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -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}
@@ -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;
    }

@@ -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() {
@@ -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() {
@@ -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();
    }
@@ -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);
    }

@@ -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;
            }
+49 −1
Original line number Diff line number Diff line
@@ -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
@@ -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);
@@ -188,6 +210,7 @@ public class NsdManager {
        private DnsSdRegisterListener mDnsSdRegisterListener;
        private DnsSdUpdateRegistrationListener mDnsSdUpdateListener;
        private DnsSdResolveListener mDnsSdResolveListener;
        private ActionListener mDnsSdStopResolveListener;

        AsyncChannel mAsyncChannel;
        ServiceHandler mHandler;
@@ -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;
@@ -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");
@@ -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
+338 −38

File changed.

Preview size limit exceeded, changes collapsed.