aboutsummaryrefslogtreecommitdiff
path: root/car-lib/src/android/car/CarInfoManager.java
blob: d90883b68f2b8dce7167aed288f88db16107a00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.car;

import android.annotation.Nullable;
import android.car.annotation.ValueTypeDef;
import android.car.hardware.CarPropertyValue;
import android.car.hardware.property.CarPropertyManager;
import android.os.Bundle;
import android.os.IBinder;


/**
 * Utility to retrieve various static information from car. Each data are grouped as {@link Bundle}
 * and relevant data can be checked from {@link Bundle} using pre-specified keys.
 */
public final class CarInfoManager implements CarManagerBase{

    private static final boolean DBG = false;
    private static final String TAG = "CarInfoManager";
    private final CarPropertyManager mCarPropertyMgr;
    /**
     * Key for manufacturer of the car. Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_KEY_MANUFACTURER = 0x11100101;
    /**
     * Key for model name of the car. This information may not necessarily allow distinguishing
     * different car models as the same name may be used for different cars depending on
     * manufacturers. Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_KEY_MODEL = 0x11100102;
    /**
     * Key for model year of the car in AC. Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_KEY_MODEL_YEAR = 0x11400103;
    /**
     * Key for unique identifier for the car. This is not VIN, and id is persistent until user
     * resets it. Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = String.class)
    public static final String BASIC_INFO_KEY_VEHICLE_ID = "android.car.vehicle-id";

    /**
     * Key for product configuration info.
     * @FutureFeature Cannot drop due to usage in non-flag protected place.
     * @hide
     */
    @ValueTypeDef(type = String.class)
    public static final String INFO_KEY_PRODUCT_CONFIGURATION = "android.car.product-config";

    /* TODO bug: 32059999
    //@ValueTypeDef(type = Integer.class)
    //public static final String KEY_DRIVER_POSITION = "driver-position";

    //@ValueTypeDef(type = int[].class)
    //public static final String KEY_SEAT_CONFIGURATION = "seat-configuration";

    //@ValueTypeDef(type = Integer.class)
    //public static final String KEY_WINDOW_CONFIGURATION = "window-configuration";

    //MT, AT, CVT, ...
    //@ValueTypeDef(type = Integer.class)
    //public static final String KEY_TRANSMISSION_TYPE = "transmission-type";

    // add: transmission gear available selection, gear available steps
    //          drive wheel: FWD, RWD, AWD, 4WD */
    /**
     * Key for Fuel Capacity in milliliters.  Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_FUEL_CAPACITY = 0x11600104;
    /**
     * Key for Fuel Types.  This is an array of fuel types the vehicle supports.
     * Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_FUEL_TYPES = 0x11410105;
    /**
     * Key for EV Battery Capacity in WH.  Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer.class)
    public static final int BASIC_INFO_EV_BATTERY_CAPACITY = 0x11600106;
    /**
     * Key for EV Connector Types.  This is an array of connector types the vehicle supports.
     * Passed in basic info Bundle.
     * @hide
     */
    @ValueTypeDef(type = Integer[].class)
    public static final int BASIC_INFO_EV_CONNECTOR_TYPES = 0x11410107;

    /**
     * @return Manufacturer of the car.  Null if not available.
     */
    @Nullable
    public String getManufacturer() throws CarNotConnectedException {
        CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
                BASIC_INFO_KEY_MANUFACTURER, 0);
        return carProp != null ? carProp.getValue() : null;
    }

    /**
     * @return Model name of the car, null if not available.  This information
     * may not necessarily allow distinguishing different car models as the same
     * name may be used for different cars depending on manufacturers.
     */
    @Nullable
    public String getModel() throws CarNotConnectedException {
        CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(
                String.class, BASIC_INFO_KEY_MODEL, 0);
        return carProp != null ? carProp.getValue() : null;
    }

    /**
     * @return Model year of the car in AC.  Null if not available.
     */
    @Nullable
    public String getModelYear() throws CarNotConnectedException {
        CarPropertyValue<String> carProp = mCarPropertyMgr.getProperty(String.class,
                BASIC_INFO_KEY_MODEL_YEAR, 0);
        return carProp != null ? carProp.getValue() : null;
    }

    /**
     * @return Unique identifier for the car. This is not VIN, and vehicle id is
     * persistent until user resets it. This ID is guaranteed to be always
     * available.
     * TODO: BASIC_INFO_KEY_VEHICLE_ID property?
     */
    public String getVehicleId() throws CarNotConnectedException {
        return "";
    }

    /**
     * @return Fuel capacity of the car in milliliters.  0 if car doesn't run on
     *         fuel.
     */
    public float getFuelCapacity() throws CarNotConnectedException {
        CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
                BASIC_INFO_FUEL_CAPACITY, 0);
        return carProp != null ? carProp.getValue() : 0f;
    }

    /**
     * @return Array of FUEL_TYPEs available in the car.  Empty array if no fuel
     *         types available.
     */
    public @FuelType.Enum int[] getFuelTypes() throws CarNotConnectedException {
        return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_FUEL_TYPES, 0);
    }

    /**
     * @return Battery capacity of the car in WH.  0 if car doesn't run on
     *         battery.
     */
    public float getEvBatteryCapacity() throws CarNotConnectedException {
        CarPropertyValue<Float> carProp = mCarPropertyMgr.getProperty(Float.class,
                BASIC_INFO_EV_BATTERY_CAPACITY, 0);
        return carProp != null ? carProp.getValue() : 0f;
    }

    /**
     * @return Array of EV_CONNECTOR_TYPEs available in the car.  Empty array if
     *         no connector types available.
     */
    public @EvConnectorType.Enum int[] getEvConnectorTypes() throws CarNotConnectedException {
        return mCarPropertyMgr.getIntArrayProperty(BASIC_INFO_EV_CONNECTOR_TYPES, 0);
    }

    /** @hide */
    CarInfoManager(IBinder service) {
        mCarPropertyMgr = new CarPropertyManager(service, null, DBG, TAG);
    }

    /** @hide */
    public void onCarDisconnected() {
        mCarPropertyMgr.onCarDisconnected();
    }

}