• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.tv.mdnsoffloadmanager.util;
18 
19 import android.net.nsd.NsdManager;
20 import android.net.nsd.OffloadEngine;
21 import android.util.Log;
22 
23 import androidx.annotation.NonNull;
24 
25 import java.util.concurrent.Executor;
26 
27 /**
28  * Wrapper around {@link NsdManager} for testing purposes.
29  */
30 public class NsdManagerWrapper {
31     private static final String TAG = NsdManagerWrapper.class.getSimpleName();
32     private final NsdManager mManager;
33 
NsdManagerWrapper(NsdManager manager)34     public NsdManagerWrapper(NsdManager manager) {
35         mManager = manager;
36     }
37 
registerOffloadEngine( @onNull String ifaceName, long offloadType, long offloadCapability, @NonNull Executor executor, @NonNull OffloadEngine engine)38     public void registerOffloadEngine(
39             @NonNull String ifaceName,
40             long offloadType,
41             long offloadCapability,
42             @NonNull Executor executor,
43             @NonNull OffloadEngine engine) {
44         Log.d(TAG, "Register offload engine for iface {" + ifaceName + "}.") ;
45         try {
46             mManager.registerOffloadEngine(ifaceName, offloadType, offloadCapability, executor, engine);
47         } catch (IllegalStateException e) {
48             String msg = "Error while registering offload engine for iFace {" + ifaceName + "}";
49             Log.e(TAG, msg, e);
50         }
51     }
52 
unregisterOffloadEngine(@onNull OffloadEngine engine)53     public void unregisterOffloadEngine(@NonNull OffloadEngine engine) {
54         Log.d(TAG, "Unregister offload engine");
55         try {
56           mManager.unregisterOffloadEngine(engine);
57         } catch (IllegalStateException e) {
58             Log.e(TAG,"Error while unregistering offload engine.", e);
59         }
60 
61     }
62 }
63