• 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.net.wifi.WifiManager;
21 import android.util.Log;
22 
23 import com.android.server.wifi.util.ActionListenerWrapper;
24 
25 /**
26  * This class is used to hold connection logic that is shared between {@link WifiServiceImpl} and
27  * other helper classes, because helper classes should not call WifiServiceImpl directly.
28  */
29 public class ConnectHelper {
30     private static final String TAG = "WifiConnectHelper";
31 
32     private final ActiveModeWarden mActiveModeWarden;
33     private final WifiConfigManager mWifiConfigManager;
34 
ConnectHelper( ActiveModeWarden activeModeWarden, WifiConfigManager wifiConfigManager)35     public ConnectHelper(
36             ActiveModeWarden activeModeWarden,
37             WifiConfigManager wifiConfigManager) {
38         mActiveModeWarden = activeModeWarden;
39         mWifiConfigManager = wifiConfigManager;
40     }
41 
42     /**
43      * Trigger connection to an existing network and provide status via the provided callback.
44      * This uses the primary client mode manager for making the connection.
45      */
connectToNetwork( @onNull NetworkUpdateResult result, @NonNull ActionListenerWrapper wrapper, int callingUid)46     public void connectToNetwork(
47             @NonNull NetworkUpdateResult result,
48             @NonNull ActionListenerWrapper wrapper,
49             int callingUid) {
50         connectToNetwork(
51                 mActiveModeWarden.getPrimaryClientModeManager(), result, wrapper, callingUid);
52     }
53 
54     /**
55      * Trigger connection to an existing network and provide status via the provided callback.
56      * This uses the provided client mode manager for making the connection.
57      */
connectToNetwork( @onNull ClientModeManager clientModeManager, @NonNull NetworkUpdateResult result, @NonNull ActionListenerWrapper wrapper, int callingUid)58     public void connectToNetwork(
59             @NonNull ClientModeManager clientModeManager,
60             @NonNull NetworkUpdateResult result,
61             @NonNull ActionListenerWrapper wrapper,
62             int callingUid) {
63         int netId = result.getNetworkId();
64         if (mWifiConfigManager.getConfiguredNetwork(netId) == null) {
65             Log.e(TAG, "connectToNetwork Invalid network Id=" + netId);
66             wrapper.sendFailure(WifiManager.ERROR);
67             return;
68         }
69         mWifiConfigManager.updateBeforeConnect(netId, callingUid);
70         clientModeManager.connectNetwork(result, wrapper, callingUid);
71     }
72 }
73