• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ethernet;
18 
19 import android.content.Context;
20 import android.net.LinkProperties;
21 import android.net.NetworkAgent;
22 import android.net.NetworkAgentConfig;
23 import android.net.NetworkCapabilities;
24 import android.net.NetworkProvider;
25 import android.net.NetworkScore;
26 import android.os.Looper;
27 import android.annotation.NonNull;
28 import android.annotation.Nullable;
29 
30 public class EthernetNetworkAgent extends NetworkAgent {
31 
32     private static final String TAG = "EthernetNetworkAgent";
33 
34     public interface Callbacks {
onNetworkUnwanted()35         void onNetworkUnwanted();
36     }
37 
38     private final Callbacks mCallbacks;
39 
EthernetNetworkAgent( @onNull Context context, @NonNull Looper looper, @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, @NonNull NetworkAgentConfig config, @Nullable NetworkProvider provider, @NonNull Callbacks cb)40     EthernetNetworkAgent(
41             @NonNull Context context,
42             @NonNull Looper looper,
43             @NonNull NetworkCapabilities nc,
44             @NonNull LinkProperties lp,
45             @NonNull NetworkAgentConfig config,
46             @Nullable NetworkProvider provider,
47             @NonNull Callbacks cb) {
48         super(context, looper, TAG, nc, lp, new NetworkScore.Builder().build(), config, provider);
49         mCallbacks = cb;
50     }
51 
52     @Override
onNetworkUnwanted()53     public void onNetworkUnwanted() {
54         mCallbacks.onNetworkUnwanted();
55     }
56 
57     // sendLinkProperties is final in NetworkAgent, so it cannot be mocked.
sendLinkPropertiesImpl(LinkProperties lp)58     public void sendLinkPropertiesImpl(LinkProperties lp) {
59         sendLinkProperties(lp);
60     }
61 
getCallbacks()62     public Callbacks getCallbacks() {
63         return mCallbacks;
64     }
65 }
66