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 18 import android.car.CarInfoManager; 19 import android.car.ICarInfo; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.provider.Settings; 23 24 import com.android.car.hal.InfoHalService; 25 import com.android.car.internal.FeatureConfiguration; 26 import com.android.car.internal.FeatureUtil; 27 28 import java.io.PrintWriter; 29 30 public class CarInfoService extends ICarInfo.Stub implements CarServiceBase { 31 32 private final InfoHalService mInfoHal; 33 private final Context mContext; 34 CarInfoService(Context context, InfoHalService infoHal)35 public CarInfoService(Context context, InfoHalService infoHal) { 36 mInfoHal = infoHal; 37 mContext = context; 38 } 39 40 @Override getBasicInfo()41 public Bundle getBasicInfo() { 42 return mInfoHal.getBasicInfo(); 43 } 44 45 @Override getStringInfo(String key)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 init()65 public void init() { 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)); 71 } 72 73 @Override release()74 public synchronized void release() { 75 //nothing to do 76 } 77 78 @Override dump(PrintWriter writer)79 public void dump(PrintWriter writer) { 80 writer.println("*CarInfoService*"); 81 writer.println("**Check HAL dump"); 82 } 83 } 84 85