• 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, @NonNull String packageName)46     public void connectToNetwork(
47             @NonNull NetworkUpdateResult result,
48             @NonNull ActionListenerWrapper wrapper,
49             int callingUid, @NonNull String packageName) {
50         connectToNetwork(
51                 mActiveModeWarden.getPrimaryClientModeManager(), result, wrapper, callingUid,
52                 packageName);
53     }
54 
55     /**
56      * Trigger connection to an existing network and provide status via the provided callback.
57      * This uses the provided client mode manager for making the connection.
58      */
connectToNetwork( @onNull ClientModeManager clientModeManager, @NonNull NetworkUpdateResult result, @NonNull ActionListenerWrapper wrapper, int callingUid, @NonNull String packageName)59     public void connectToNetwork(
60             @NonNull ClientModeManager clientModeManager,
61             @NonNull NetworkUpdateResult result,
62             @NonNull ActionListenerWrapper wrapper,
63             int callingUid, @NonNull String packageName) {
64         int netId = result.getNetworkId();
65         if (mWifiConfigManager.getConfiguredNetwork(netId) == null) {
66             Log.e(TAG, "connectToNetwork Invalid network Id=" + netId);
67             wrapper.sendFailure(WifiManager.ActionListener.FAILURE_INTERNAL_ERROR);
68             return;
69         }
70         mWifiConfigManager.updateBeforeConnect(netId, callingUid, packageName);
71         clientModeManager.connectNetwork(result, wrapper, callingUid, packageName);
72     }
73 }
74