• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.aware;
18 
19 import android.content.Context;
20 import android.net.wifi.WifiContext;
21 import android.os.HandlerThread;
22 import android.util.Log;
23 
24 import com.android.server.SystemService;
25 import com.android.server.wifi.HalDeviceManager;
26 import com.android.server.wifi.WifiInjector;
27 import com.android.server.wifi.WifiNative;
28 import com.android.wifi.flags.FeatureFlags;
29 
30 /**
31  * Service implementing Wi-Fi Aware functionality. Delegates actual interface
32  * implementation to WifiAwareServiceImpl.
33  */
34 public final class WifiAwareService extends SystemService {
35     private static final String TAG = "WifiAwareService";
36     final WifiAwareServiceImpl mImpl;
37 
WifiAwareService(Context contextBase)38     public WifiAwareService(Context contextBase) {
39         super(new WifiContext(contextBase));
40         mImpl = new WifiAwareServiceImpl(getContext());
41     }
42 
43     @Override
onStart()44     public void onStart() {
45         Log.i(TAG, "Registering " + Context.WIFI_AWARE_SERVICE);
46         publishBinderService(Context.WIFI_AWARE_SERVICE, mImpl);
47     }
48 
49     @Override
onBootPhase(int phase)50     public void onBootPhase(int phase) {
51         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
52             WifiInjector wifiInjector = WifiInjector.getInstance();
53             if (wifiInjector == null) {
54                 Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!");
55                 return;
56             }
57 
58             HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager();
59             WifiNative wifiNative = wifiInjector.getWifiNative();
60             FeatureFlags featureFlags = wifiInjector.getDeviceConfigFacade().getFeatureFlags();
61 
62             WifiAwareStateManager wifiAwareStateManager = new WifiAwareStateManager(wifiInjector,
63                     new PairingConfigManager());
64             WifiAwareNativeCallback wifiAwareNativeCallback = new WifiAwareNativeCallback(
65                     wifiAwareStateManager);
66             WifiAwareNativeManager wifiAwareNativeManager = new WifiAwareNativeManager(
67                     wifiAwareStateManager, halDeviceManager, wifiAwareNativeCallback,
68                     wifiNative, featureFlags);
69             WifiAwareNativeApi wifiAwareNativeApi = new WifiAwareNativeApi(wifiAwareNativeManager);
70             wifiAwareStateManager.setNative(wifiAwareNativeManager, wifiAwareNativeApi);
71             WifiAwareShellCommand wifiAwareShellCommand = new WifiAwareShellCommand();
72             wifiAwareShellCommand.register("native_api", wifiAwareNativeApi);
73             wifiAwareShellCommand.register("native_cb", wifiAwareNativeCallback);
74             wifiAwareShellCommand.register("state_mgr", wifiAwareStateManager);
75 
76             HandlerThread awareHandlerThread = wifiInjector.getWifiHandlerThread();
77             mImpl.start(awareHandlerThread, wifiAwareStateManager, wifiAwareShellCommand,
78                     wifiInjector.getWifiMetrics().getWifiAwareMetrics(),
79                     wifiInjector.getWifiPermissionsUtil(),
80                     wifiInjector.getWifiPermissionsWrapper(), wifiInjector.getSettingsConfigStore(),
81                     wifiAwareNativeManager, wifiAwareNativeApi, wifiAwareNativeCallback,
82                     wifiInjector.makeNetdWrapper(), wifiInjector.getInterfaceConflictManager());
83         } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
84             mImpl.startLate();
85         }
86     }
87 }
88 
89