1 /*
2  * Copyright (C) 2017 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.rtt;
18 
19 import android.content.Context;
20 import android.net.wifi.aware.WifiAwareManager;
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.WifiContext;
27 import com.android.server.wifi.WifiInjector;
28 import com.android.server.wifi.util.WifiPermissionsUtil;
29 
30 /**
31  * TBD.
32  */
33 public class RttService extends SystemService {
34     private static final String TAG = "RttService";
35     private RttServiceImpl mImpl;
36 
RttService(Context contextBase)37     public RttService(Context contextBase) {
38         super(new WifiContext(contextBase));
39         mImpl = new RttServiceImpl(getContext());
40     }
41 
42     @Override
onStart()43     public void onStart() {
44         Log.i(TAG, "Registering " + Context.WIFI_RTT_RANGING_SERVICE);
45         publishBinderService(Context.WIFI_RTT_RANGING_SERVICE, mImpl);
46     }
47 
48     @Override
onBootPhase(int phase)49     public void onBootPhase(int phase) {
50         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
51             Log.i(TAG, "Starting " + Context.WIFI_RTT_RANGING_SERVICE);
52 
53             WifiInjector wifiInjector = WifiInjector.getInstance();
54             if (wifiInjector == null) {
55                 Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!");
56                 return;
57             }
58 
59             HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager();
60             HandlerThread handlerThread = wifiInjector.getRttHandlerThread();
61             WifiPermissionsUtil wifiPermissionsUtil = wifiInjector.getWifiPermissionsUtil();
62             RttMetrics rttMetrics = wifiInjector.getWifiMetrics().getRttMetrics();
63 
64             WifiAwareManager awareManager = getContext().getSystemService(WifiAwareManager.class);
65 
66             RttNative rttNative = new RttNative(mImpl, halDeviceManager);
67             mImpl.start(handlerThread.getLooper(), wifiInjector.getClock(), awareManager, rttNative,
68                     rttMetrics, wifiPermissionsUtil, wifiInjector.getSettingsConfigStore());
69         }
70     }
71 }
72