blob: 56e3b08ff17afe6312279e4c356a61185a7cc17d [file] [log] [blame]
keunyounga3b28d82015-08-25 13:05:15 -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 */
16package com.android.car.hal;
17
Keun-young Parke54ac272016-02-16 19:02:18 -080018import android.car.CarInfoManager;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070019import android.hardware.vehicle.V2_0.VehiclePropConfig;
20import android.hardware.vehicle.V2_0.VehiclePropValue;
21import android.hardware.vehicle.V2_0.VehicleProperty;
Keun-young Park67456352016-10-03 13:45:19 -070022import android.os.Bundle;
keunyounga3b28d82015-08-25 13:05:15 -070023import android.util.Log;
24
25import com.android.car.CarLog;
26
27import java.io.PrintWriter;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070028import java.util.Collection;
keunyounga3b28d82015-08-25 13:05:15 -070029import java.util.LinkedList;
30import java.util.List;
31
32public class InfoHalService extends HalServiceBase {
33
34 private final VehicleHal mHal;
Keun-young Park67456352016-10-03 13:45:19 -070035 private Bundle mBasicInfo = new Bundle();
keunyounga3b28d82015-08-25 13:05:15 -070036
37 public InfoHalService(VehicleHal hal) {
38 mHal = hal;
39 }
40
41 @Override
42 public void init() {
43 //nothing to do
44 }
45
46 @Override
47 public synchronized void release() {
Keun-young Park67456352016-10-03 13:45:19 -070048 mBasicInfo = new Bundle();
keunyounga3b28d82015-08-25 13:05:15 -070049 }
50
51 @Override
Pavel Maltsev0d07c762016-11-03 16:40:15 -070052 public synchronized Collection<VehiclePropConfig> takeSupportedProperties(
53 Collection<VehiclePropConfig> allProperties) {
54 List<VehiclePropConfig> supported = new LinkedList<>();
keunyoungfe30ba02015-09-17 17:56:35 -070055 for (VehiclePropConfig p: allProperties) {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070056 switch (p.prop) {
57 case VehicleProperty.INFO_MAKE:
58 readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MANUFACTURER);
Keun-young Park67456352016-10-03 13:45:19 -070059 break;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070060 case VehicleProperty.INFO_MODEL:
61 readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MODEL);
Keun-young Park67456352016-10-03 13:45:19 -070062 break;
Pavel Maltsev0d07c762016-11-03 16:40:15 -070063 case VehicleProperty.INFO_MODEL_YEAR:
64 readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MODEL_YEAR);
Keun-young Park67456352016-10-03 13:45:19 -070065 break;
66 default: // not supported
67 break;
keunyounga3b28d82015-08-25 13:05:15 -070068 }
69 }
70 return supported;
71 }
72
Pavel Maltsev0d07c762016-11-03 16:40:15 -070073 private void readPropertyToBundle(int prop, String key) {
74 String value = "";
75 try {
76 value = mHal.get(String.class, prop);
77 } catch (PropertyTimeoutException e) {
78 Log.e(CarLog.TAG_INFO, "Unable to read property", e);
79 }
80 mBasicInfo.putString(key, value);
81 }
82
keunyounga3b28d82015-08-25 13:05:15 -070083 @Override
keunyoungfe30ba02015-09-17 17:56:35 -070084 public void handleHalEvents(List<VehiclePropValue> values) {
85 for (VehiclePropValue v : values) {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070086 logUnexpectedEvent(v.prop);
keunyoungfe30ba02015-09-17 17:56:35 -070087 }
keunyounga3b28d82015-08-25 13:05:15 -070088 }
89
90 @Override
91 public void dump(PrintWriter writer) {
92 writer.println("*InfoHal*");
Keun-young Park67456352016-10-03 13:45:19 -070093 writer.println("**BasicInfo:" + mBasicInfo);
keunyounga3b28d82015-08-25 13:05:15 -070094 }
95
Keun-young Park67456352016-10-03 13:45:19 -070096 public synchronized Bundle getBasicInfo() {
97 return mBasicInfo;
keunyounga3b28d82015-08-25 13:05:15 -070098 }
99
100 private void logUnexpectedEvent(int property) {
101 Log.w(CarLog.TAG_INFO, "unexpected HAL event for property 0x" +
102 Integer.toHexString(property));
103 }
keunyounga3b28d82015-08-25 13:05:15 -0700104}