}
@Override
public void onErrorEvent(int i, int i1) { }
};
- SET 和 GET,以HVAC空调为例:
mCarHvacManager.setIntProperty(ID_HVAC_LOCK_VENTILATION_ON, VehicleAreaType.VEHICLE_AREA_TYPE_GLOBAL, HVAC_ON);
float temp = mCarHvacManager.getFloatProperty(ID_HVAC_TEMPERATURE_SET, SEAT_ROW_1_LEFT);
VehicleAreaType分为GLOBAL(全局)、WINDOW(车窗)、MIRROR(镜子)、SEAT(座椅)、DOOR(车门)、WHEEL(车轮)等:
enum VehicleArea : int32_t {
GLOBAL = 0x01000000,
/** WINDOW maps to enum VehicleAreaWindow */
WINDOW = 0x03000000,
/** MIRROR maps to enum VehicleAreaMirror */
MIRROR = 0x04000000,
/** SEAT maps to enum VehicleAreaSeat */
SEAT = 0x05000000,
/** DOOR maps to enum VehicleAreaDoor */
DOOR = 0x06000000,
/** WHEEL maps to enum VehicleAreaWheel */
WHEEL = 0x07000000,
/** IN_OUT_CAR maps to enum VehicleAreaInOutCar,车内外 */
IN_OUT_CAR = 0x08000000,
MASK = 0x0f000000,
};
CarAPI (car-lib:android.car.jar)
1.createCar:
public static Car createCar(Context context, ServiceConnection serviceConnectionListener, @Nullable Handler handler) {
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
Log.e(CarLibLog.TAG_CAR, “FEATURE_AUTOMOTIVE not declared while android.car is used”);
return null;
}
try {
return new Car(context, serviceConnectionListener, handler);
} catch (IllegalArgumentException e) { // Expected when car service loader is not available.
}
return null;
}
- getCarManager(“serviceName”) -> createCarManager(“serviceName”, IBinder)
public Object getCarManager(String serviceName) throws CarNotConnectedException {
CarManagerBase manager;
ICar service = getICarOrThrow();
synchronized (mCarManagerLock) {
manager = mServiceMap.get(serviceName);
if (manager == null) {
try {
if(TBOX_SERVICE.equals(serviceName)){
manager = createCarManager(serviceName, null);
return manager;
}
IBinder binder = service.getCarService(serviceName);
if (binder == null) {
Log.w(CarLibLog.TAG_CAR, “could not get binder for service:” + serviceName);
return null;
}
manager = createCarManager(serviceName, binder);
if (manager == null) {
Log.w(CarLibLog.TAG_CAR, “could not create manager for service:” + serviceName);
return null;
}
mServiceMap.put(serviceName, manager);
} catch (RemoteException e) {
handleRemoteException(e);
}
}
}
return manager;
}
private CarManagerBase createCarManager(String serviceName, IBinder binder) throws CarNotConnectedException {
CarManagerBase manager = null;
Log.d(“liueg”, "------------------createCarManager()serviceName "+serviceName);
switch (serviceName) {
case AUDIO_SERVICE: manager = new CarAudioManager(binder, mContext, mEventHandler);break;
case SENSOR_SERVICE: manager = new CarSensorManager(binder, mContext, mEventHandler);break;
case DYSENSOR_SERVICE: manager = new CarDYSensorManager(binder, mContext, mEventHandler);break;
case INFO_SERVICE: manager = new CarInfoManager(binder);break;
case APP_FOCUS_SERVICE: manager = new CarAppFocusManager(binder, mEventHandler);break;
case PACKAGE_SERVICE: manager = new CarPackageManager(binder, mContext);break;
case CAR_NAVIGATION_SERVICE: manager = new CarNavigationStatusManager(binder);break;
case CABIN_SERVICE: manager = new CarCabinManager(binder, mContext, mEventHandler);break;
case DIAGNOSTIC_SERVICE: manager = new CarDiagnosticManager(binder, mContext, mEventHandler);break;
case HVAC_SERVICE: manager = new CarHvacManager(binder, mContext, mEventHandler);break;
case DYHVAC_SERVICE: manager = new CarDYHvacManager(binder, mContext, mEventHandler);