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.WifiContext; 21 import android.net.wifi.aware.WifiAwareManager; 22 import android.os.HandlerThread; 23 import android.util.Log; 24 25 import com.android.server.SystemService; 26 import com.android.server.wifi.WifiInjector; 27 import com.android.server.wifi.util.WifiPermissionsUtil; 28 29 /** 30 * TBD. 31 */ 32 public class RttService extends SystemService { 33 private static final String TAG = "RttService"; 34 private RttServiceImpl mImpl; 35 RttService(Context contextBase)36 public RttService(Context contextBase) { 37 super(new WifiContext(contextBase)); 38 mImpl = new RttServiceImpl(getContext()); 39 } 40 41 @Override onStart()42 public void onStart() { 43 Log.i(TAG, "Registering " + Context.WIFI_RTT_RANGING_SERVICE); 44 publishBinderService(Context.WIFI_RTT_RANGING_SERVICE, mImpl); 45 } 46 47 @Override onBootPhase(int phase)48 public void onBootPhase(int phase) { 49 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { 50 Log.i(TAG, "Starting " + Context.WIFI_RTT_RANGING_SERVICE); 51 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 HandlerThread handlerThread = wifiInjector.getWifiHandlerThread(); 59 WifiPermissionsUtil wifiPermissionsUtil = wifiInjector.getWifiPermissionsUtil(); 60 RttMetrics rttMetrics = wifiInjector.getWifiMetrics().getRttMetrics(); 61 WifiAwareManager awareManager = getContext().getSystemService(WifiAwareManager.class); 62 63 mImpl.start(handlerThread.getLooper(), wifiInjector.getClock(), awareManager, 64 rttMetrics, wifiPermissionsUtil, wifiInjector.getSettingsConfigStore(), 65 wifiInjector.getHalDeviceManager()); 66 } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { 67 mImpl.handleBootCompleted(); 68 } 69 } 70 } 71