• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.car;
18 
19 import android.car.annotation.ValueTypeDef;
20 import android.os.Bundle;
21 import android.os.IBinder;
22 import android.os.RemoteException;
23 
24 /**
25  * Utility to retrieve various static information from car. For given string keys, there can be
26  * different types of values and right query API like {@link #getFloat(String)} for float
27  * type, and {@link #getInt(String)} for int type, should be used. Passing a key string to wrong
28  * API will lead into {@link IllegalArgumentException}. All get* apis return null if requested
29  * property is not supported by the car. So caller should always check for null result.
30  */
31 public class CarInfoManager implements CarManagerBase {
32 
33     /**
34      * Manufacturer of the car.
35      */
36     @ValueTypeDef(type = String.class)
37     public static final String KEY_MANUFACTURER = "manufacturer";
38     /**
39      * Model name of the car. This information may not necessarily allow distinguishing different
40      * car models as the same name may be used for different cars depending on manufacturers.
41      */
42     @ValueTypeDef(type = String.class)
43     public static final String KEY_MODEL = "model";
44     /**
45      * Model year of the car in AC.
46      */
47     @ValueTypeDef(type = Integer.class)
48     public static final String KEY_MODEL_YEAR = "model-year";
49     /**
50      * Unique identifier for the car. This is not VIN, and id is persistent until user resets it.
51      */
52     @ValueTypeDef(type = String.class)
53     public static final String KEY_VEHICLE_ID = "vehicle-id";
54 
55     //TODO
56     //@ValueTypeDef(type = Integer.class)
57     //public static final String KEY_DRIVER_POSITION = "driver-position";
58 
59     //TODO
60     //@ValueTypeDef(type = int[].class)
61     //public static final String KEY_SEAT_CONFIGURATION = "seat-configuration";
62 
63     //TODO
64     //@ValueTypeDef(type = Integer.class)
65     //public static final String KEY_WINDOW_CONFIGURATION = "window-configuration";
66 
67     //TODO: MT, AT, CVT, ...
68     //@ValueTypeDef(type = Integer.class)
69     //public static final String KEY_TRANSMISSION_TYPE = "transmission-type";
70 
71     //TODO add: transmission gear available selection, gear available steps
72     //          drive wheel: FWD, RWD, AWD, 4WD
73 
74     private final ICarInfo mService;
75 
76     /**
77      * Retrieve floating point information for car.
78      * @param key
79      * @return null if the key is not supported.
80      * @throws CarNotConnectedException
81      * @throws IllegalArgumentException
82      */
getFloat(String key)83     public Float getFloat(String key) throws CarNotConnectedException, IllegalArgumentException {
84         try {
85             float[] v = mService.getFloat(key);
86             if (v != null) {
87                 return v[0];
88             }
89         } catch (IllegalStateException e) {
90             CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
91         } catch (RemoteException e) {
92             throw new CarNotConnectedException(e);
93         }
94         return null;
95     }
96 
getInt(String key)97     public Integer getInt(String key) throws CarNotConnectedException, IllegalArgumentException {
98         try {
99             int[] v = mService.getInt(key);
100             if (v != null) {
101                 return v[0];
102             }
103         } catch (IllegalStateException e) {
104             CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
105         } catch (RemoteException e) {
106             throw new CarNotConnectedException(e);
107         }
108         return null;
109     }
110 
getLong(String key)111     public Long getLong(String key) throws CarNotConnectedException, IllegalArgumentException {
112         try {
113             long[] v = mService.getLong(key);
114             if (v != null) {
115                 return v[0];
116             }
117         } catch (IllegalStateException e) {
118             CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
119         } catch (RemoteException e) {
120             throw new CarNotConnectedException(e);
121         }
122         return null;
123     }
124 
getString(String key)125     public String getString(String key) throws CarNotConnectedException, IllegalArgumentException {
126         try {
127             return mService.getString(key);
128         } catch (IllegalStateException e) {
129             CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
130         } catch (RemoteException e) {
131             throw new CarNotConnectedException(e);
132         }
133         return null;
134     }
135 
136     /**
137      * get Bundle for the given key. This is intended for passing vendor specific data for key
138      * defined only for the car vendor. Vendor extension can be used for other APIs like
139      * getInt / getString, but this is for passing more complex data.
140      * @param key
141      * @return
142      * @throws CarNotConnectedException
143      * @throws IllegalArgumentException
144      * @hide
145      */
getBundle(String key)146     public Bundle getBundle(String key) throws CarNotConnectedException, IllegalArgumentException {
147         try {
148             return mService.getBundle(key);
149         } catch (IllegalStateException e) {
150             CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
151         } catch (RemoteException e) {
152             throw new CarNotConnectedException(e);
153         }
154         return null;
155     }
156 
157     /** @hide */
CarInfoManager(IBinder service)158     CarInfoManager(IBinder service) {
159         mService = ICarInfo.Stub.asInterface(service);
160     }
161 
162     /** @hide */
163     @Override
onCarDisconnected()164     public void onCarDisconnected() {
165         //nothing to do
166     }
167 }
168