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