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; |
| 17 | |
Keun-young Park | e54ac27 | 2016-02-16 19:02:18 -0800 | [diff] [blame] | 18 | import android.car.CarInfoManager; |
| 19 | import android.car.ICarInfo; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Keun-young Park | 064ddd8 | 2015-12-21 23:57:50 +0000 | [diff] [blame] | 21 | import android.os.Bundle; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 22 | import android.provider.Settings; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 23 | |
| 24 | import com.android.car.hal.InfoHalService; |
Antonio Cortes | c52d5f9 | 2017-02-06 08:47:38 -0800 | [diff] [blame] | 25 | import com.android.car.internal.FeatureConfiguration; |
| 26 | import com.android.car.internal.FeatureUtil; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 27 | |
| 28 | import java.io.PrintWriter; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 29 | |
| 30 | public class CarInfoService extends ICarInfo.Stub implements CarServiceBase { |
| 31 | |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 32 | private final InfoHalService mInfoHal; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 33 | private final Context mContext; |
| 34 | |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 35 | public CarInfoService(Context context, InfoHalService infoHal) { |
| 36 | mInfoHal = infoHal; |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 37 | mContext = context; |
| 38 | } |
| 39 | |
| 40 | @Override |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 41 | public Bundle getBasicInfo() { |
| 42 | return mInfoHal.getBasicInfo(); |
Keun-young Park | 064ddd8 | 2015-12-21 23:57:50 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
Keun-young Park | 161f69e | 2017-01-27 16:13:00 -0800 | [diff] [blame] | 46 | public String getStringInfo(String key) { |
| 47 | switch (key) { |
| 48 | case CarInfoManager.INFO_KEY_PRODUCT_CONFIGURATION: |
| 49 | FeatureUtil.assertFeature( |
| 50 | FeatureConfiguration.ENABLE_PRODUCT_CONFIGURATION_INFO); |
| 51 | // still protect with if-feature code. code under if can be dropped by |
| 52 | // proguard if necessary. |
| 53 | if (FeatureConfiguration.ENABLE_PRODUCT_CONFIGURATION_INFO) { |
| 54 | //TODO get it from HAL layer |
| 55 | return null; |
| 56 | } |
| 57 | break; |
| 58 | default: // just throw exception |
| 59 | break; |
| 60 | } |
| 61 | throw new IllegalArgumentException("Unsupported key:" + key); |
| 62 | } |
| 63 | |
| 64 | @Override |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 65 | public void init() { |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 66 | Bundle info = mInfoHal.getBasicInfo(); |
| 67 | // do not update ID immediately even if user clears it. |
| 68 | info.putString(CarInfoManager.BASIC_INFO_KEY_VEHICLE_ID, |
| 69 | Settings.Secure.getString(mContext.getContentResolver(), |
| 70 | Settings.Secure.ANDROID_ID)); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public synchronized void release() { |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 75 | //nothing to do |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void dump(PrintWriter writer) { |
| 80 | writer.println("*CarInfoService*"); |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 81 | writer.println("**Check HAL dump"); |
keunyoung | a3b28d8 | 2015-08-25 13:05:15 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
Keun-young Park | 6745635 | 2016-10-03 13:45:19 -0700 | [diff] [blame] | 84 | |