blob: 598ac8d50a3640dbb57a4d03bb56dab858ff6626 [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
2 * Copyright (C) 2015 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.car;
18
keunyoungcc449f72015-08-12 10:46:27 -070019import java.io.PrintWriter;
20
keunyoungca515072015-07-10 12:21:47 -070021import android.content.Context;
22import android.content.Intent;
23import android.os.IBinder;
24import android.support.car.Car;
25import android.support.car.CarInfo;
26import android.support.car.CarUiInfo;
27import android.support.car.ICar;
28import android.support.car.ICarConnectionListener;
29import android.support.car.ICarSensor;
30import android.util.Log;
31
keunyoungcc449f72015-08-12 10:46:27 -070032import com.android.car.hal.VehicleHal;
keunyoungca515072015-07-10 12:21:47 -070033import com.android.internal.annotations.GuardedBy;
34
35public class ICarImpl extends ICar.Stub {
36 private static final int VERSION = 1;
37
38 @GuardedBy("ICarImpl.class")
39 private static ICarImpl sInstance = null;
40
41 private final Context mContext;
keunyoungcc449f72015-08-12 10:46:27 -070042 private final VehicleHal mHal;
keunyoungca515072015-07-10 12:21:47 -070043
44 private final CarSensorService mCarSensorService;
45
46 public synchronized static ICarImpl getInstance(Context serviceContext) {
47 if (sInstance == null) {
48 sInstance = new ICarImpl(serviceContext);
49 sInstance.init();
50 }
51 return sInstance;
52 }
53
54 public synchronized static void releaseInstance() {
55 if (sInstance == null) {
56 return;
57 }
58 sInstance.release();
59 sInstance = null;
60 }
61
62 public ICarImpl(Context serviceContext) {
63 mContext = serviceContext;
keunyoungcc449f72015-08-12 10:46:27 -070064 mHal = VehicleHal.getInstance(serviceContext.getApplicationContext());
keunyoungca515072015-07-10 12:21:47 -070065 mCarSensorService = new CarSensorService(serviceContext);
66 }
67
68 private void init() {
69 mCarSensorService.init();
70 }
71
72 private void release() {
73 mCarSensorService.release();
keunyoungcc449f72015-08-12 10:46:27 -070074 VehicleHal.releaseInstance();
keunyoungca515072015-07-10 12:21:47 -070075 }
76
77 @Override
78 public int getVersion() {
79 return VERSION;
80 }
81
82 @Override
83 public IBinder getCarService(String serviceName) {
84 switch (serviceName) {
85 case Car.SENSOR_SERVICE:
86 return mCarSensorService;
87 default:
88 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
89 return null;
90 }
91 }
92
93 @Override
94 public CarInfo getCarInfo() {
95 //TODO
96 return null;
97 }
98
99 @Override
100 public CarUiInfo getCarUiInfo() {
101 //TODO
102 return null;
103 }
104
105 @Override
106 public boolean isConnectedToCar() {
107 return true; // always connected in embedded
108 }
109
110 @Override
111 public int getCarConnectionType() {
112 return Car.CONNECTION_TYPE_EMBEDDED;
113 }
114
115 @Override
116 public void registerCarConnectionListener(int clientVersion, ICarConnectionListener listener) {
117 //TODO
118 }
119
120 @Override
121 public void unregisterCarConnectionListener(ICarConnectionListener listener) {
122 //TODO
123 }
124
125 @Override
126 public boolean startCarActivity(Intent intent) {
127 //TODO
128 return false;
129 }
keunyoungcc449f72015-08-12 10:46:27 -0700130
131 void dump(PrintWriter writer) {
132 writer.println("**CarSensorService");
133 mCarSensorService.dump(writer);
134 }
keunyoungca515072015-07-10 12:21:47 -0700135}