1 /* 2 * Copyright (C) 2023 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 android.net.nsd; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.LongDef; 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * OffloadEngine is an interface for mDns hardware offloading. 29 * 30 * An offloading engine can interact with the firmware code to instruct the hardware to 31 * offload some of mDns network traffic before it reached android OS. This can improve the 32 * power consumption performance of the host system by not always waking up the OS to handle 33 * the mDns packet when the device is in low power mode. 34 * 35 * @hide 36 */ 37 @FlaggedApi("com.android.net.flags.register_nsd_offload_engine_api") 38 @SystemApi 39 public interface OffloadEngine { 40 /** 41 * Indicates that the OffloadEngine can generate replies to mDns queries. 42 * 43 * @see OffloadServiceInfo#getOffloadPayload() 44 */ 45 int OFFLOAD_TYPE_REPLY = 1; 46 /** 47 * Indicates that the OffloadEngine can filter and drop mDns queries. 48 */ 49 int OFFLOAD_TYPE_FILTER_QUERIES = 1 << 1; 50 /** 51 * Indicates that the OffloadEngine can filter and drop mDns replies. It can allow mDns packets 52 * to be received even when no app holds a {@link android.net.wifi.WifiManager.MulticastLock}. 53 */ 54 int OFFLOAD_TYPE_FILTER_REPLIES = 1 << 2; 55 56 /** 57 * Indicates that the OffloadEngine can bypass multicast lock. 58 */ 59 int OFFLOAD_CAPABILITY_BYPASS_MULTICAST_LOCK = 1; 60 61 /** 62 * @hide 63 */ 64 @Retention(RetentionPolicy.SOURCE) 65 @LongDef(flag = true, prefix = {"OFFLOAD_TYPE"}, value = { 66 OFFLOAD_TYPE_REPLY, 67 OFFLOAD_TYPE_FILTER_QUERIES, 68 OFFLOAD_TYPE_FILTER_REPLIES, 69 }) 70 @interface OffloadType {} 71 72 /** 73 * @hide 74 */ 75 @Retention(RetentionPolicy.SOURCE) 76 @LongDef(flag = true, prefix = {"OFFLOAD_CAPABILITY"}, value = { 77 OFFLOAD_CAPABILITY_BYPASS_MULTICAST_LOCK 78 }) 79 @interface OffloadCapability {} 80 81 /** 82 * To be called when the OffloadServiceInfo is added or updated. 83 * 84 * @param info The OffloadServiceInfo to add or update. 85 */ onOffloadServiceUpdated(@onNull OffloadServiceInfo info)86 void onOffloadServiceUpdated(@NonNull OffloadServiceInfo info); 87 88 /** 89 * To be called when the OffloadServiceInfo is removed. 90 * 91 * @param info The OffloadServiceInfo to remove. 92 */ onOffloadServiceRemoved(@onNull OffloadServiceInfo info)93 void onOffloadServiceRemoved(@NonNull OffloadServiceInfo info); 94 } 95