keunyoung | a3b28d8 | 2015-08-25 13:05:15 -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 | package com.android.car.hal; |
| 17 | |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 18 | import android.car.CarInfoManager; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 19 | import android.hardware.vehicle.V2_0.VehiclePropConfig; |
| 20 | import android.hardware.vehicle.V2_0.VehiclePropValue; |
| 21 | import android.hardware.vehicle.V2_0.VehicleProperty; |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | |
| 25 | import com.android.car.CarLog; |
| 26 | |
| 27 | import java.io.PrintWriter; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 28 | import java.util.Collection; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 29 | import java.util.LinkedList; |
| 30 | import java.util.List; |
| 31 | |
| 32 | public class InfoHalService extends HalServiceBase { |
| 33 | |
| 34 | private final VehicleHal mHal; |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 35 | private Bundle mBasicInfo = new Bundle(); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 36 | |
| 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 Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 48 | mBasicInfo = new Bundle(); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 52 | public synchronized Collection<VehiclePropConfig> takeSupportedProperties( |
| 53 | Collection<VehiclePropConfig> allProperties) { |
| 54 | List<VehiclePropConfig> supported = new LinkedList<>(); |
keunyoung | fe30ba0 | 2015-09-17 17:56:35 -0700 | [diff] [blame] | 55 | for (VehiclePropConfig p: allProperties) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 56 | switch (p.prop) { |
| 57 | case VehicleProperty.INFO_MAKE: |
| 58 | readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MANUFACTURER); |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 59 | break; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 60 | case VehicleProperty.INFO_MODEL: |
| 61 | readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MODEL); |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 62 | break; |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 63 | case VehicleProperty.INFO_MODEL_YEAR: |
| 64 | readPropertyToBundle(p.prop, CarInfoManager.BASIC_INFO_KEY_MODEL_YEAR); |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 65 | break; |
| 66 | default: // not supported |
| 67 | break; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | return supported; |
| 71 | } |
| 72 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 73 | 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 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 83 | @Override |
keunyoung | fe30ba0 | 2015-09-17 17:56:35 -0700 | [diff] [blame] | 84 | public void handleHalEvents(List<VehiclePropValue> values) { |
| 85 | for (VehiclePropValue v : values) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame^] | 86 | logUnexpectedEvent(v.prop); |
keunyoung | fe30ba0 | 2015-09-17 17:56:35 -0700 | [diff] [blame] | 87 | } |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void dump(PrintWriter writer) { |
| 92 | writer.println("*InfoHal*"); |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 93 | writer.println("**BasicInfo:" + mBasicInfo); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 96 | public synchronized Bundle getBasicInfo() { |
| 97 | return mBasicInfo; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | private void logUnexpectedEvent(int property) { |
| 101 | Log.w(CarLog.TAG_INFO, "unexpected HAL event for property 0x" + |
| 102 | Integer.toHexString(property)); |
| 103 | } |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 104 | } |