WifiAwareService.java revision 9b37a65ec7b89ca58639443fd899824b28d04191
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
17package com.android.server.wifi.aware;
18
19import android.content.Context;
20import android.os.HandlerThread;
21import android.util.Log;
22
23import com.android.server.SystemService;
24import com.android.server.wifi.HalDeviceManager;
25import com.android.server.wifi.WifiInjector;
26
27/**
28 * Service implementing Wi-Fi Aware functionality. Delegates actual interface
29 * implementation to WifiAwareServiceImpl.
30 */
31public final class WifiAwareService extends SystemService {
32    private static final String TAG = "WifiAwareService";
33    final WifiAwareServiceImpl mImpl;
34
35    public WifiAwareService(Context context) {
36        super(context);
37        mImpl = new WifiAwareServiceImpl(context);
38    }
39
40    @Override
41    public void onStart() {
42        Log.i(TAG, "Registering " + Context.WIFI_AWARE_SERVICE);
43        publishBinderService(Context.WIFI_AWARE_SERVICE, mImpl);
44    }
45
46    @Override
47    public void onBootPhase(int phase) {
48        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
49            WifiInjector wifiInjector = WifiInjector.getInstance();
50            if (wifiInjector == null) {
51                Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!");
52                return;
53            }
54
55            HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager();
56
57            WifiAwareStateManager wifiAwareStateManager = new WifiAwareStateManager();
58            WifiAwareNativeCallback wifiAwareNativeCallback = new WifiAwareNativeCallback(
59                    wifiAwareStateManager);
60            WifiAwareNativeManager wifiAwareNativeManager = new WifiAwareNativeManager(
61                    wifiAwareStateManager, halDeviceManager, wifiAwareNativeCallback);
62            WifiAwareNativeApi wifiAwareNativeApi = new WifiAwareNativeApi(wifiAwareNativeManager);
63            wifiAwareStateManager.setNative(wifiAwareNativeManager, wifiAwareNativeApi);
64            WifiAwareShellCommand wifiAwareShellCommand = new WifiAwareShellCommand();
65            wifiAwareShellCommand.register("native_api", wifiAwareNativeApi);
66            wifiAwareShellCommand.register("state_mgr", wifiAwareStateManager);
67
68            HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread();
69            mImpl.start(awareHandlerThread, wifiAwareStateManager, wifiAwareShellCommand,
70                    wifiInjector.getWifiMetrics().getWifiAwareMetrics(),
71                    wifiInjector.getWifiPermissionsWrapper());
72        } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
73            mImpl.startLate();
74        }
75    }
76}
77
78