• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.wifi;
18 
19 import android.annotation.NonNull;
20 import android.util.ArraySet;
21 
22 import java.util.Set;
23 
24 /**
25  * This class is used for other modules to monitor events occurring in {@link ClientModeImpl},
26  * without putting that code directly in ClientModeImpl and cluttering it.
27  *
28  * TODO(b/175896748): Eventually, our goal is to make ClientModeImpl contain only code that is
29  *  critical to its main functionality (connection tracking), and move other auxiliary code
30  *  elsewhere (such as here).
31  */
32 public class ClientModeImplMonitor implements ClientModeImplListener {
33 
34     private final Set<ClientModeImplListener> mListeners = new ArraySet<>();
35 
36     /** Register a listener. */
registerListener(@onNull ClientModeImplListener listener)37     public void registerListener(@NonNull ClientModeImplListener listener) {
38         mListeners.add(listener);
39     }
40 
41     /** Unregister a listener. */
unregisterListener(@onNull ClientModeImplListener listener)42     public void unregisterListener(@NonNull ClientModeImplListener listener) {
43         mListeners.remove(listener);
44     }
45 
46     @Override
onL2Connected(@onNull ConcreteClientModeManager clientModeManager)47     public void onL2Connected(@NonNull ConcreteClientModeManager clientModeManager) {
48         for (ClientModeImplListener listener : mListeners) {
49             listener.onL2Connected(clientModeManager);
50         }
51     }
52 
53     // TODO(b/175896748): not yet triggered by ClientModeImpl
54     @Override
onL3Connected(@onNull ConcreteClientModeManager clientModeManager)55     public void onL3Connected(@NonNull ConcreteClientModeManager clientModeManager) {
56         for (ClientModeImplListener listener : mListeners) {
57             listener.onL3Connected(clientModeManager);
58         }
59     }
60 
61     @Override
onInternetValidated(@onNull ConcreteClientModeManager clientModeManager)62     public void onInternetValidated(@NonNull ConcreteClientModeManager clientModeManager) {
63         for (ClientModeImplListener listener : mListeners) {
64             listener.onInternetValidated(clientModeManager);
65         }
66     }
67 
68     @Override
onConnectionStart(@onNull ConcreteClientModeManager clientModeManager)69     public void onConnectionStart(@NonNull ConcreteClientModeManager clientModeManager) {
70         for (ClientModeImplListener listener : mListeners) {
71             listener.onConnectionStart(clientModeManager);
72         }
73     }
74 
75     @Override
onConnectionEnd(@onNull ConcreteClientModeManager clientModeManager)76     public void onConnectionEnd(@NonNull ConcreteClientModeManager clientModeManager) {
77         for (ClientModeImplListener listener : mListeners) {
78             listener.onConnectionEnd(clientModeManager);
79         }
80     }
81 
82     @Override
onCaptivePortalDetected(@onNull ConcreteClientModeManager clientModeManager)83     public void onCaptivePortalDetected(@NonNull ConcreteClientModeManager clientModeManager) {
84         for (ClientModeImplListener listener : mListeners) {
85             listener.onCaptivePortalDetected(clientModeManager);
86         }
87     }
88 }
89