keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.car; |
| 18 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 19 | import java.io.PrintWriter; |
| 20 | |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.os.IBinder; |
| 24 | import android.support.car.Car; |
| 25 | import android.support.car.CarInfo; |
| 26 | import android.support.car.CarUiInfo; |
| 27 | import android.support.car.ICar; |
| 28 | import android.support.car.ICarConnectionListener; |
| 29 | import android.support.car.ICarSensor; |
| 30 | import android.util.Log; |
| 31 | |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 32 | import com.android.car.hal.VehicleHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 33 | import com.android.internal.annotations.GuardedBy; |
| 34 | |
| 35 | public 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; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 42 | private final VehicleHal mHal; |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 43 | |
| 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; |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 64 | mHal = VehicleHal.getInstance(serviceContext.getApplicationContext()); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 65 | mCarSensorService = new CarSensorService(serviceContext); |
| 66 | } |
| 67 | |
| 68 | private void init() { |
| 69 | mCarSensorService.init(); |
| 70 | } |
| 71 | |
| 72 | private void release() { |
| 73 | mCarSensorService.release(); |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 74 | VehicleHal.releaseInstance(); |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 75 | } |
| 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 | } |
keunyoung | cc449f7 | 2015-08-12 10:46:27 -0700 | [diff] [blame^] | 130 | |
| 131 | void dump(PrintWriter writer) { |
| 132 | writer.println("**CarSensorService"); |
| 133 | mCarSensorService.dump(writer); |
| 134 | } |
keunyoung | ca51507 | 2015-07-10 12:21:47 -0700 | [diff] [blame] | 135 | } |