1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.connectivity.mdns; 18 19 import android.annotation.NonNull; 20 21 import java.util.List; 22 23 /** 24 * Listener interface for mDNS service instance discovery events. 25 * 26 * @hide 27 */ 28 public interface MdnsServiceBrowserListener { 29 30 /** 31 * Called when an mDNS service instance is found. This method would be called only if all 32 * service records (PTR, SRV, TXT, A or AAAA) are received . 33 * 34 * @param serviceInfo The found mDNS service instance. 35 */ onServiceFound(@onNull MdnsServiceInfo serviceInfo)36 void onServiceFound(@NonNull MdnsServiceInfo serviceInfo); 37 38 /** 39 * Called when an mDNS service instance is updated. This method would be called only if all 40 * service records (PTR, SRV, TXT, A or AAAA) are received before. 41 * 42 * @param serviceInfo The updated mDNS service instance. 43 */ onServiceUpdated(@onNull MdnsServiceInfo serviceInfo)44 void onServiceUpdated(@NonNull MdnsServiceInfo serviceInfo); 45 46 /** 47 * Called when a mDNS service instance is no longer valid and removed. This method would be 48 * called only if all service records (PTR, SRV, TXT, A or AAAA) are received before. 49 * 50 * @param serviceInfo The service instance of the removed mDNS service. 51 */ onServiceRemoved(@onNull MdnsServiceInfo serviceInfo)52 void onServiceRemoved(@NonNull MdnsServiceInfo serviceInfo); 53 54 /** 55 * Called when searching for mDNS service has stopped because of an error. 56 * 57 * TODO (changed when importing code): define error constants 58 * 59 * @param error The error code of the stop reason. 60 */ onSearchStoppedWithError(int error)61 void onSearchStoppedWithError(int error); 62 63 /** Called when it failed to start an mDNS service discovery process. */ onSearchFailedToStart()64 void onSearchFailedToStart(); 65 66 /** 67 * Called when a mDNS service discovery query has been sent. 68 * 69 * @param subtypes The list of subtypes in the discovery query. 70 * @param transactionId The transaction ID of the query. 71 */ onDiscoveryQuerySent(@onNull List<String> subtypes, int transactionId)72 void onDiscoveryQuerySent(@NonNull List<String> subtypes, int transactionId); 73 74 /** 75 * Called when an error has happened when parsing a received mDNS response packet. 76 * 77 * @param receivedPacketNumber The packet sequence number of the received packet. 78 * @param errorCode The error code, defined in {@link MdnsResponseErrorCode}. 79 */ onFailedToParseMdnsResponse(int receivedPacketNumber, int errorCode)80 void onFailedToParseMdnsResponse(int receivedPacketNumber, int errorCode); 81 82 /** 83 * Called when a mDNS service instance is discovered. This method would be called if the PTR 84 * record has been received. 85 * 86 * @param serviceInfo The discovered mDNS service instance. 87 */ onServiceNameDiscovered(@onNull MdnsServiceInfo serviceInfo)88 void onServiceNameDiscovered(@NonNull MdnsServiceInfo serviceInfo); 89 90 /** 91 * Called when a discovered mDNS service instance is no longer valid and removed. 92 * 93 * @param serviceInfo The service instance of the removed mDNS service. 94 */ onServiceNameRemoved(@onNull MdnsServiceInfo serviceInfo)95 void onServiceNameRemoved(@NonNull MdnsServiceInfo serviceInfo); 96 }