resolve merge conflicts of 235f8ac to nyc-car-dev
Change-Id: I49327e591ef08875a92928535a1a0c69f7368804
diff --git a/car-lib/api/current.txt b/car-lib/api/current.txt
index d64459f..5619b71 100644
--- a/car-lib/api/current.txt
+++ b/car-lib/api/current.txt
@@ -6,7 +6,7 @@
method public static android.car.Car createCar(android.content.Context, android.content.ServiceConnection);
method public void disconnect();
method public int getCarConnectionType();
- method public java.lang.Object getCarManager(java.lang.String);
+ method public java.lang.Object getCarManager(java.lang.String) throws android.car.CarNotConnectedException;
method public boolean isConnected();
method public boolean isConnecting();
field public static final java.lang.String APP_CONTEXT_SERVICE = "app_context";
@@ -21,13 +21,13 @@
}
public class CarAppContextManager {
- method public int getActiveAppContexts();
- method public boolean isOwningContext(int);
+ method public int getActiveAppContexts() throws android.car.CarNotConnectedException;
+ method public boolean isOwningContext(int) throws android.car.CarNotConnectedException;
method public void onCarDisconnected();
- method public void registerContextListener(android.car.CarAppContextManager.AppContextChangeListener, int);
- method public void resetActiveContexts(int);
- method public void setActiveContexts(android.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws java.lang.SecurityException;
- method public void unregisterContextListener();
+ method public void registerContextListener(android.car.CarAppContextManager.AppContextChangeListener, int) throws android.car.CarNotConnectedException;
+ method public void resetActiveContexts(int) throws android.car.CarNotConnectedException;
+ method public void setActiveContexts(android.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws android.car.CarNotConnectedException, java.lang.SecurityException;
+ method public void unregisterContextListener() throws android.car.CarNotConnectedException;
field public static final int APP_CONTEXT_NAVIGATION = 1; // 0x1
field public static final int APP_CONTEXT_VOICE_COMMAND = 2; // 0x2
}
@@ -301,8 +301,8 @@
method public boolean isSensorSupported(int) throws android.car.CarNotConnectedException;
method public static boolean isSensorSupported(int[], int);
method public boolean registerListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int, int) throws android.car.CarNotConnectedException, java.lang.IllegalArgumentException;
- method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener);
- method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int);
+ method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener) throws android.car.CarNotConnectedException;
+ method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.car.CarNotConnectedException;
field public static final int SENSOR_RATE_FAST = 1; // 0x1
field public static final int SENSOR_RATE_FASTEST = 0; // 0x0
field public static final int SENSOR_RATE_NORMAL = 3; // 0x3
diff --git a/car-lib/api/system-current.txt b/car-lib/api/system-current.txt
index 28751cd..1eb9592 100644
--- a/car-lib/api/system-current.txt
+++ b/car-lib/api/system-current.txt
@@ -6,7 +6,7 @@
method public static android.car.Car createCar(android.content.Context, android.content.ServiceConnection);
method public void disconnect();
method public int getCarConnectionType();
- method public java.lang.Object getCarManager(java.lang.String);
+ method public java.lang.Object getCarManager(java.lang.String) throws android.car.CarNotConnectedException;
method public boolean isConnected();
method public boolean isConnecting();
field public static final java.lang.String APP_CONTEXT_SERVICE = "app_context";
@@ -33,13 +33,13 @@
}
public class CarAppContextManager {
- method public int getActiveAppContexts();
- method public boolean isOwningContext(int);
+ method public int getActiveAppContexts() throws android.car.CarNotConnectedException;
+ method public boolean isOwningContext(int) throws android.car.CarNotConnectedException;
method public void onCarDisconnected();
- method public void registerContextListener(android.car.CarAppContextManager.AppContextChangeListener, int);
- method public void resetActiveContexts(int);
- method public void setActiveContexts(android.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws java.lang.SecurityException;
- method public void unregisterContextListener();
+ method public void registerContextListener(android.car.CarAppContextManager.AppContextChangeListener, int) throws android.car.CarNotConnectedException;
+ method public void resetActiveContexts(int) throws android.car.CarNotConnectedException;
+ method public void setActiveContexts(android.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws android.car.CarNotConnectedException, java.lang.SecurityException;
+ method public void unregisterContextListener() throws android.car.CarNotConnectedException;
field public static final int APP_CONTEXT_NAVIGATION = 1; // 0x1
field public static final int APP_CONTEXT_VOICE_COMMAND = 2; // 0x2
}
@@ -79,10 +79,10 @@
public class CarProjectionManager {
method public void onCarDisconnected();
- method public void registerProjectionRunner(android.content.Intent);
- method public void regsiterProjectionListener(android.car.CarProjectionManager.CarProjectionListener, int);
- method public void unregisterProjectionRunner(android.content.Intent);
- method public void unregsiterProjectionListener();
+ method public void registerProjectionRunner(android.content.Intent) throws android.car.CarNotConnectedException;
+ method public void regsiterProjectionListener(android.car.CarProjectionManager.CarProjectionListener, int) throws android.car.CarNotConnectedException;
+ method public void unregisterProjectionRunner(android.content.Intent) throws android.car.CarNotConnectedException;
+ method public void unregsiterProjectionListener() throws android.car.CarNotConnectedException;
field public static final int PROJECTION_LONG_PRESS_VOICE_SEARCH = 2; // 0x2
field public static final int PROJECTION_VOICE_SEARCH = 1; // 0x1
}
@@ -470,8 +470,8 @@
method public boolean isSensorSupported(int) throws android.car.CarNotConnectedException;
method public static boolean isSensorSupported(int[], int);
method public boolean registerListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int, int) throws android.car.CarNotConnectedException, java.lang.IllegalArgumentException;
- method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener);
- method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int);
+ method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener) throws android.car.CarNotConnectedException;
+ method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.car.CarNotConnectedException;
field public static final int SENSOR_RATE_FAST = 1; // 0x1
field public static final int SENSOR_RATE_FASTEST = 0; // 0x0
field public static final int SENSOR_RATE_NORMAL = 3; // 0x3
@@ -498,20 +498,20 @@
public class CarCamera {
ctor public CarCamera(android.car.hardware.camera.ICarCamera, int);
- method public android.graphics.Rect getCameraCrop();
- method public android.graphics.Rect getCameraPosition();
- method public android.car.hardware.camera.CarCameraState getCameraState();
- method public int getCapabilities();
- method public void setCameraCrop(android.graphics.Rect);
- method public void setCameraPosition(android.graphics.Rect);
- method public void setCameraState(android.car.hardware.camera.CarCameraState);
+ method public android.graphics.Rect getCameraCrop() throws android.car.CarNotConnectedException;
+ method public android.graphics.Rect getCameraPosition() throws android.car.CarNotConnectedException;
+ method public android.car.hardware.camera.CarCameraState getCameraState() throws android.car.CarNotConnectedException;
+ method public int getCapabilities() throws android.car.CarNotConnectedException;
+ method public void setCameraCrop(android.graphics.Rect) throws android.car.CarNotConnectedException;
+ method public void setCameraPosition(android.graphics.Rect) throws android.car.CarNotConnectedException;
+ method public void setCameraState(android.car.hardware.camera.CarCameraState) throws android.car.CarNotConnectedException;
field public static final java.lang.String TAG;
field public final int mCameraType;
}
public class CarCameraManager {
method public void closeCamera(android.car.hardware.camera.CarCamera);
- method public int getCameraCapabilities(int);
+ method public int getCameraCapabilities(int) throws android.car.CarNotConnectedException;
method public int[] getCameraList();
method public android.car.hardware.camera.CarCamera openCamera(int);
field public static final int ANDROID_OVERLAY_SUPPORT_FLAG = 1; // 0x1
@@ -568,16 +568,16 @@
}
public class CarHvacManager {
- method public boolean getBooleanProperty(int, int);
- method public float getFloatProperty(int, int);
- method public int getIntProperty(int, int);
- method public java.util.List<android.car.hardware.hvac.CarHvacManager.CarHvacBaseProperty> getPropertyList();
+ method public boolean getBooleanProperty(int, int) throws android.car.CarNotConnectedException;
+ method public float getFloatProperty(int, int) throws android.car.CarNotConnectedException;
+ method public int getIntProperty(int, int) throws android.car.CarNotConnectedException;
+ method public java.util.List<android.car.hardware.hvac.CarHvacManager.CarHvacBaseProperty> getPropertyList() throws android.car.CarNotConnectedException;
method public static boolean isZonedProperty(int);
method public synchronized void registerListener(android.car.hardware.hvac.CarHvacManager.CarHvacEventListener) throws android.car.CarNotConnectedException;
- method public void setBooleanProperty(int, int, boolean);
- method public void setFloatProperty(int, int, float);
- method public void setIntProperty(int, int, int);
- method public synchronized void unregisterListener();
+ method public void setBooleanProperty(int, int, boolean) throws android.car.CarNotConnectedException;
+ method public void setFloatProperty(int, int, float) throws android.car.CarNotConnectedException;
+ method public void setIntProperty(int, int, int) throws android.car.CarNotConnectedException;
+ method public synchronized void unregisterListener() throws android.car.CarNotConnectedException;
field public static final boolean DBG = true;
field public static final int HVAC_AIR_RECIRCULATION_ON = 4; // 0x4
field public static final int HVAC_AUTOMATIC_MODE_ON = 3; // 0x3
@@ -701,11 +701,11 @@
}
public class CarRadioManager {
- method public android.car.hardware.radio.CarRadioPreset getPreset(int);
+ method public android.car.hardware.radio.CarRadioPreset getPreset(int) throws android.car.CarNotConnectedException;
method public int getPresetCount();
method public synchronized void registerListener(android.car.hardware.radio.CarRadioManager.CarRadioEventListener) throws android.car.CarNotConnectedException;
- method public boolean setPreset(android.car.hardware.radio.CarRadioPreset) throws java.lang.IllegalArgumentException;
- method public synchronized void unregisterListener();
+ method public boolean setPreset(android.car.hardware.radio.CarRadioPreset) throws android.car.CarNotConnectedException, java.lang.IllegalArgumentException;
+ method public synchronized void unregisterListener() throws android.car.CarNotConnectedException;
field public static final boolean DBG = true;
field public static final java.lang.String TAG = "CarRadioManager";
}
diff --git a/car-lib/src/android/car/Car.java b/car-lib/src/android/car/Car.java
index 4153765..e0d91f4 100644
--- a/car-lib/src/android/car/Car.java
+++ b/car-lib/src/android/car/Car.java
@@ -368,8 +368,9 @@
* SensorManagerService sensorManagerService = car.getCarManager(Car.SENSOR_SERVICE);
* @param serviceName Name of service that should be created like {@link #SENSOR_SERVICE}.
* @return Matching service manager or null if there is no such service.
+ * @throws CarNotConnectedException
*/
- public Object getCarManager(String serviceName) {
+ public Object getCarManager(String serviceName) throws CarNotConnectedException {
CarManagerBase manager = null;
ICar service = getICarOrThrow();
synchronized (mCarManagerLock) {
@@ -426,7 +427,8 @@
}
}
- private CarManagerBase createCarManager(String serviceName, IBinder binder) {
+ private CarManagerBase createCarManager(String serviceName, IBinder binder)
+ throws CarNotConnectedException {
CarManagerBase manager = null;
switch (serviceName) {
case AUDIO_SERVICE:
diff --git a/car-lib/src/android/car/CarAppContextManager.java b/car-lib/src/android/car/CarAppContextManager.java
index ba165dc..22e36bf 100644
--- a/car-lib/src/android/car/CarAppContextManager.java
+++ b/car-lib/src/android/car/CarAppContextManager.java
@@ -21,9 +21,9 @@
import android.os.Looper;
import android.os.RemoteException;
+import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
-import java.lang.ref.WeakReference;
/**
* CarAppContextManager allows applications to set and listen for the current application context
@@ -96,9 +96,11 @@
* Register listener to monitor app context change. Only one listener can be registered and
* registering multiple times will lead into only the last listener to be active.
* @param listener
- * @param contextFilter Flags of contexts to get notification.
+ * @param contextFilter Flags of cotexts to get notification.
+ * @throws CarNotConnectedException
*/
- public void registerContextListener(AppContextChangeListener listener, int contextFilter) {
+ public void registerContextListener(AppContextChangeListener listener, int contextFilter)
+ throws CarNotConnectedException {
if (listener == null) {
throw new IllegalArgumentException("null listener");
}
@@ -107,7 +109,7 @@
try {
mService.registerContextListener(mBinderListener, contextFilter);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
}
mListener = listener;
@@ -117,36 +119,35 @@
/**
* Unregister listener and stop listening context change events. If app has owned a context
- * by {@link #resetActiveContexts(int)}, it will be reset to inactive state.
+ * by {@link #setActiveContext(int)}, it will be reset to inactive state.
+ * @throws CarNotConnectedException
*/
- public void unregisterContextListener() {
+ public void unregisterContextListener() throws CarNotConnectedException {
synchronized(this) {
try {
mService.unregisterContextListener(mBinderListener);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
mListener = null;
mContextFilter = 0;
}
}
- public int getActiveAppContexts() {
+ public int getActiveAppContexts() throws CarNotConnectedException {
try {
return mService.getActiveAppContexts();
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
- return 0;
}
- public boolean isOwningContext(int context) {
+ public boolean isOwningContext(int context) throws CarNotConnectedException {
try {
return mService.isOwningContext(mBinderListener, context);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
- return false;
}
/**
@@ -159,10 +160,11 @@
* registering multiple times will lead into only the last listener to be active.
* @param ownershipListener
* @param contexts
+ * @throws CarNotConnectedException
* @throws SecurityException If owner cannot be changed.
*/
public void setActiveContexts(AppContextOwnershipChangeListener ownershipListener, int contexts)
- throws SecurityException {
+ throws SecurityException, CarNotConnectedException {
if (ownershipListener == null) {
throw new IllegalArgumentException("null listener");
}
@@ -170,7 +172,7 @@
try {
mService.setActiveContexts(mBinderListener, contexts);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
for (int flag = APP_CONTEXT_START_FLAG; flag <= APP_CONTEXT_END_FLAG; flag <<= 1) {
if ((flag & contexts) != 0) {
@@ -184,12 +186,13 @@
* Reset the given contexts, i.e. mark them as inactive. This also involves releasing ownership
* for the context.
* @param contexts
+ * @throws CarNotConnectedException
*/
- public void resetActiveContexts(int contexts) {
+ public void resetActiveContexts(int contexts) throws CarNotConnectedException {
try {
mService.resetActiveContexts(mBinderListener, contexts);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
synchronized (this) {
for (int flag = APP_CONTEXT_START_FLAG; flag <= APP_CONTEXT_END_FLAG; flag <<= 1) {
diff --git a/car-lib/src/android/car/CarInfoManager.java b/car-lib/src/android/car/CarInfoManager.java
index 3813bba..a04159d 100644
--- a/car-lib/src/android/car/CarInfoManager.java
+++ b/car-lib/src/android/car/CarInfoManager.java
@@ -21,9 +21,6 @@
import android.os.IBinder;
import android.os.RemoteException;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-
/**
* Utility to retrieve various static information from car. For given string keys, there can be
* different types of values and right query API like {@link #getFloat(String)} for float
@@ -92,7 +89,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
return null;
}
@@ -106,7 +103,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
return null;
}
@@ -120,7 +117,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
return null;
}
@@ -131,7 +128,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
return null;
}
@@ -152,7 +149,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
return null;
}
diff --git a/car-lib/src/android/car/CarProjectionManager.java b/car-lib/src/android/car/CarProjectionManager.java
index 45c2c8a..d4a7477 100644
--- a/car-lib/src/android/car/CarProjectionManager.java
+++ b/car-lib/src/android/car/CarProjectionManager.java
@@ -74,8 +74,10 @@
* registering multiple times will lead into only the last listener to be active.
* @param listener
* @param voiceSearchFilter Flags of voice search requests to get notification.
+ * @throws CarNotConnectedException
*/
- public void regsiterProjectionListener(CarProjectionListener listener, int voiceSearchFilter) {
+ public void regsiterProjectionListener(CarProjectionListener listener, int voiceSearchFilter)
+ throws CarNotConnectedException {
if (listener == null) {
throw new IllegalArgumentException("null listener");
}
@@ -84,7 +86,7 @@
try {
mService.regsiterProjectionListener(mBinderListener, voiceSearchFilter);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
}
mListener = listener;
@@ -94,13 +96,14 @@
/**
* Unregister listener and stop listening projection events.
+ * @throws CarNotConnectedException
*/
- public void unregsiterProjectionListener() {
+ public void unregsiterProjectionListener() throws CarNotConnectedException {
synchronized (this) {
try {
mService.unregsiterProjectionListener(mBinderListener);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
mListener = null;
mVoiceSearchFilter = 0;
@@ -110,8 +113,10 @@
/**
* Registers projection runner on projection start with projection service
* to create reverse binding.
+ * @param serviceIntent
+ * @throws CarNotConnectedException
*/
- public void registerProjectionRunner(Intent serviceIntent) {
+ public void registerProjectionRunner(Intent serviceIntent) throws CarNotConnectedException {
if (serviceIntent == null) {
throw new IllegalArgumentException("null serviceIntent");
}
@@ -119,7 +124,7 @@
try {
mService.registerProjectionRunner(serviceIntent);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
}
}
@@ -127,8 +132,10 @@
/**
* Unregisters projection runner on projection stop with projection service to create
* reverse binding.
+ * @param serviceIntent
+ * @throws CarNotConnectedException
*/
- public void unregisterProjectionRunner(Intent serviceIntent) {
+ public void unregisterProjectionRunner(Intent serviceIntent) throws CarNotConnectedException {
if (serviceIntent == null) {
throw new IllegalArgumentException("null serviceIntent");
}
@@ -136,7 +143,7 @@
try {
mService.unregisterProjectionRunner(serviceIntent);
} catch (RemoteException e) {
- //ignore as CarApi will handle disconnection anyway.
+ throw new CarNotConnectedException(e);
}
}
}
diff --git a/car-lib/src/android/car/hardware/CarSensorManager.java b/car-lib/src/android/car/hardware/CarSensorManager.java
index fedf3de..dab13bc 100644
--- a/car-lib/src/android/car/hardware/CarSensorManager.java
+++ b/car-lib/src/android/car/hardware/CarSensorManager.java
@@ -25,11 +25,11 @@
import android.car.CarNotConnectedException;
import android.content.Context;
import android.os.Handler;
+import android.os.Handler.Callback;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
-import android.os.Handler.Callback;
import android.util.Log;
import java.lang.ref.WeakReference;
@@ -197,7 +197,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- //ignore
+ throw new CarNotConnectedException(e);
}
return new int[0];
}
@@ -302,8 +302,10 @@
* Stop getting sensor update for the given listener. If there are multiple registrations for
* this listener, all listening will be stopped.
* @param listener
+ * @throws CarNotConnectedException
*/
- public void unregisterListener(CarSensorEventListener listener) {
+ public void unregisterListener(CarSensorEventListener listener)
+ throws CarNotConnectedException {
//TODO: removing listener should reset update rate
synchronized(mActiveSensorListeners) {
Iterator<Integer> sensorIterator = mActiveSensorListeners.keySet().iterator();
@@ -319,15 +321,17 @@
* for other sensors, those subscriptions will not be affected.
* @param listener
* @param sensorType
+ * @throws CarNotConnectedException
*/
- public void unregisterListener(CarSensorEventListener listener, int sensorType) {
+ public void unregisterListener(CarSensorEventListener listener, int sensorType)
+ throws CarNotConnectedException {
synchronized(mActiveSensorListeners) {
doUnregisterListenerLocked(listener, sensorType, null);
}
}
private void doUnregisterListenerLocked(CarSensorEventListener listener, Integer sensor,
- Iterator<Integer> sensorIterator) {
+ Iterator<Integer> sensorIterator) throws CarNotConnectedException {
CarSensorListeners listeners = mActiveSensorListeners.get(sensor);
if (listeners != null) {
if (listeners.contains(listener)) {
@@ -338,7 +342,7 @@
mService.unregisterSensorListener(sensor.intValue(),
mCarSensorEventListenerToService);
} catch (RemoteException e) {
- // ignore
+ throw new CarNotConnectedException(e);
}
if (sensorIterator == null) {
mActiveSensorListeners.remove(sensor);
@@ -359,7 +363,7 @@
} catch (IllegalStateException e) {
CarApiUtil.checkCarNotConnectedExceptionFromCarService(e);
} catch (RemoteException e) {
- return false;
+ throw new CarNotConnectedException(e);
}
return true;
}
diff --git a/car-lib/src/android/car/hardware/camera/CarCamera.java b/car-lib/src/android/car/hardware/camera/CarCamera.java
index 3c49b4c..8610d7d 100644
--- a/car-lib/src/android/car/hardware/camera/CarCamera.java
+++ b/car-lib/src/android/car/hardware/camera/CarCamera.java
@@ -17,6 +17,7 @@
package android.car.hardware.camera;
import android.annotation.SystemApi;
+import android.car.CarNotConnectedException;
import android.graphics.Rect;
import android.os.RemoteException;
import android.util.Log;
@@ -36,48 +37,43 @@
mCameraType = cameraType;
}
- public int getCapabilities() {
- int capabilities;
+ public int getCapabilities() throws CarNotConnectedException {
try {
- capabilities = mService.getCapabilities(mCameraType);
+ return mService.getCapabilities(mCameraType);
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCapabilities", e);
- capabilities = 0;
+ throw new CarNotConnectedException(e);
}
- return capabilities;
}
- public Rect getCameraCrop() {
- Rect rect;
+ public Rect getCameraCrop() throws CarNotConnectedException {
try {
- rect = mService.getCameraCrop(mCameraType);
+ return mService.getCameraCrop(mCameraType);
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCameraCrop", e);
- rect = null;
+ throw new CarNotConnectedException(e);
}
- return rect;
}
- public void setCameraCrop(Rect rect) {
+ public void setCameraCrop(Rect rect) throws CarNotConnectedException {
try {
mService.setCameraCrop(mCameraType, rect);
} catch (RemoteException e) {
Log.e(TAG, "Exception in setCameraCrop", e);
+ throw new CarNotConnectedException(e);
}
}
- public Rect getCameraPosition() {
- Rect rect;
+ public Rect getCameraPosition() throws CarNotConnectedException {
try {
- rect = mService.getCameraPosition(mCameraType);
+ return mService.getCameraPosition(mCameraType);
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCameraPosition", e);
- rect = null;
+ throw new CarNotConnectedException(e);
}
- return rect;
}
- public void setCameraPosition(Rect rect) {
+ public void setCameraPosition(Rect rect) throws CarNotConnectedException {
try {
mService.setCameraPosition(mCameraType, rect);
} catch (RemoteException e) {
@@ -85,22 +81,21 @@
}
}
- public CarCameraState getCameraState() {
- CarCameraState state;
+ public CarCameraState getCameraState() throws CarNotConnectedException {
try {
- state = mService.getCameraState(mCameraType);
+ return mService.getCameraState(mCameraType);
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCameraState", e);
- state = null;
+ throw new CarNotConnectedException(e);
}
- return state;
}
- public void setCameraState(CarCameraState state) {
+ public void setCameraState(CarCameraState state) throws CarNotConnectedException {
try {
mService.setCameraState(mCameraType, state);
} catch (RemoteException e) {
Log.e(TAG, "Exception in setCameraState", e);
+ throw new CarNotConnectedException(e);
}
}
}
diff --git a/car-lib/src/android/car/hardware/camera/CarCameraManager.java b/car-lib/src/android/car/hardware/camera/CarCameraManager.java
index 5e3554d..f835cc1 100644
--- a/car-lib/src/android/car/hardware/camera/CarCameraManager.java
+++ b/car-lib/src/android/car/hardware/camera/CarCameraManager.java
@@ -19,6 +19,7 @@
import android.annotation.SystemApi;
import android.car.Car;
import android.car.CarManagerBase;
+import android.car.CarNotConnectedException;
import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
@@ -51,13 +52,14 @@
* Should not be obtained directly by clients, use {@link Car.getCarManager()} instead.
* @hide
*/
- public CarCameraManager(IBinder service, Context context) {
+ public CarCameraManager(IBinder service, Context context) throws CarNotConnectedException{
mService = ICarCamera.Stub.asInterface(service);
try {
mCameraList = mService.getCameraList();
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCameraList", e);
mCameraList = null;
+ throw new CarNotConnectedException(e);
}
}
@@ -73,14 +75,15 @@
*
* @param cameraType Camera type to query capabilites
* @return Bitmask of camera capabilities available for this device
+ * @throws CarNotConnectedException
*/
- public int getCameraCapabilities(int cameraType) {
+ public int getCameraCapabilities(int cameraType) throws CarNotConnectedException {
int capabilities;
try {
capabilities = mService.getCapabilities(cameraType);
} catch (RemoteException e) {
Log.e(TAG, "Exception in getCameraCapabilities", e);
- capabilities = 0;
+ throw new CarNotConnectedException(e);
}
return capabilities;
}
diff --git a/car-lib/src/android/car/hardware/hvac/CarHvacManager.java b/car-lib/src/android/car/hardware/hvac/CarHvacManager.java
index bc36ffb..2019bd0 100644
--- a/car-lib/src/android/car/hardware/hvac/CarHvacManager.java
+++ b/car-lib/src/android/car/hardware/hvac/CarHvacManager.java
@@ -448,12 +448,12 @@
try {
mListenerToService = new CarHvacEventListenerToService(this);
mService.registerListener(mListenerToService);
- } catch (RemoteException ex) {
- Log.e(TAG, "Could not connect: " + ex.toString());
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not connect: " + e.toString());
mListener = null;
- throw new CarNotConnectedException(ex);
- } catch (IllegalStateException ex) {
- Car.checkCarNotConnectedExceptionFromCarService(ex);
+ throw new CarNotConnectedException(e);
+ } catch (IllegalStateException e) {
+ Car.checkCarNotConnectedExceptionFromCarService(e);
}
}
@@ -463,15 +463,16 @@
* @param
* @return
*/
- public synchronized void unregisterListener() {
+ public synchronized void unregisterListener() throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "unregisterListener");
}
try {
mService.unregisterListener(mListenerToService);
- } catch (RemoteException ex) {
- // do nothing.
- Log.e(TAG, "Could not unregister: " + ex.toString());
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not unregister: " + e.toString());
+ throw new CarNotConnectedException(e);
+
}
mListenerToService = null;
mListener = null;
@@ -483,14 +484,14 @@
* @return Caller must check the property type and typecast to the appropriate subclass
* (CarHvacBooleanProperty, CarHvacFloatProperty, CarrHvacIntProperty)
*/
- public List<CarHvacBaseProperty> getPropertyList() {
+ public List<CarHvacBaseProperty> getPropertyList() throws CarNotConnectedException {
List<CarHvacBaseProperty> hvacProps = new ArrayList<>();
List<CarHvacProperty> carProps;
try {
carProps = mService.getHvacProperties();
} catch (RemoteException e) {
Log.w(TAG, "Exception in getPropertyList", e);
- return null;
+ throw new CarNotConnectedException(e);
}
for (CarHvacProperty carProp : carProps) {
@@ -524,16 +525,16 @@
* @param zone Zone of the property to get
* @return
*/
- public boolean getBooleanProperty(int prop, int zone) {
+ public boolean getBooleanProperty(int prop, int zone) throws CarNotConnectedException {
CarHvacProperty carProp;
if (DBG) {
Log.d(TAG, "getBooleanProperty: prop = " + prop + " zone = " + zone);
}
try {
carProp = mService.getProperty(prop, zone);
- } catch (RemoteException ex) {
- Log.e(TAG, "getProperty failed with " + ex.toString());
- return false;
+ } catch (RemoteException e) {
+ Log.e(TAG, "getProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
if (carProp.getType() == PROPERTY_TYPE_BOOLEAN) {
@@ -550,16 +551,16 @@
* @param zone Zone of the property to get
* @return
*/
- public float getFloatProperty(int prop, int zone) {
+ public float getFloatProperty(int prop, int zone) throws CarNotConnectedException {
CarHvacProperty carProp;
if (DBG) {
Log.d(TAG, "getFloatProperty: prop = " + prop + " zone = " + zone);
}
try {
carProp = mService.getProperty(prop, zone);
- } catch (RemoteException ex) {
- Log.e(TAG, "getProperty failed with " + ex.toString());
- return 0;
+ } catch (RemoteException e) {
+ Log.e(TAG, "getProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
if (carProp.getType() == PROPERTY_TYPE_FLOAT) {
@@ -576,16 +577,16 @@
* @param zone Zone of the property to get
* @return
*/
- public int getIntProperty(int prop, int zone) {
+ public int getIntProperty(int prop, int zone) throws CarNotConnectedException {
CarHvacProperty carProp;
if (DBG) {
Log.d(TAG, "getIntProperty: prop = " + prop + " zone = " + zone);
}
try {
carProp = mService.getProperty(prop, zone);
- } catch (RemoteException ex) {
- Log.e(TAG, "getProperty failed with " + ex.toString());
- return 0;
+ } catch (RemoteException e) {
+ Log.e(TAG, "getProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
if (carProp.getType() == PROPERTY_TYPE_INT) {
@@ -604,19 +605,21 @@
* @param zone Zone(s) to apply the modification. Multiple zones may be OR'd together
* @param val Value to set
*/
- public void setBooleanProperty(int prop, int zone, boolean val) {
+ public void setBooleanProperty(int prop, int zone, boolean val)
+ throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "setBooleanProperty: prop = " + prop + " zone = " + zone + " val = " + val);
}
try {
CarHvacProperty carProp = new CarHvacProperty(prop, zone, val);
mService.setProperty(carProp);
- } catch (RemoteException ex) {
- Log.e(TAG, "setBooleanProperty failed with " + ex.toString());
+ } catch (RemoteException e) {
+ Log.e(TAG, "setBooleanProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
}
- public void setFloatProperty(int prop, int zone, float val) {
+ public void setFloatProperty(int prop, int zone, float val) throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "setFloatProperty: prop = " + prop + " zone = " + zone + " val = " + val);
}
@@ -625,12 +628,13 @@
CarHvacProperty carProp = new CarHvacProperty(prop, zone,
new float[] { 0 }, new float[] { 0 }, val);
mService.setProperty(carProp);
- } catch (RemoteException ex) {
- Log.e(TAG, "setFloatProperty failed with " + ex.toString());
+ } catch (RemoteException e) {
+ Log.e(TAG, "setFloatProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
}
- public void setIntProperty(int prop, int zone, int val) {
+ public void setIntProperty(int prop, int zone, int val) throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "setIntProperty: prop = " + prop + " zone = " + zone + " val = " + val);
}
@@ -639,8 +643,9 @@
CarHvacProperty carProp = new CarHvacProperty(prop, zone,
new int[] { 0 }, new int[] { 0 }, val);
mService.setProperty(carProp);
- } catch (RemoteException ex) {
- Log.e(TAG, "setIntProperty failed with " + ex.toString());
+ } catch (RemoteException e) {
+ Log.e(TAG, "setIntProperty failed with " + e.toString());
+ throw new CarNotConnectedException(e);
}
}
@@ -694,7 +699,11 @@
@Override
public void onCarDisconnected() {
if (mListener != null) {
- unregisterListener();
+ try {
+ unregisterListener();
+ } catch (CarNotConnectedException e) {
+ // ignore, as car is already disconnected.
+ }
}
}
}
diff --git a/car-lib/src/android/car/hardware/radio/CarRadioManager.java b/car-lib/src/android/car/hardware/radio/CarRadioManager.java
index 86effe2..b1177c2 100644
--- a/car-lib/src/android/car/hardware/radio/CarRadioManager.java
+++ b/car-lib/src/android/car/hardware/radio/CarRadioManager.java
@@ -20,7 +20,6 @@
import android.car.Car;
import android.car.CarManagerBase;
import android.car.CarNotConnectedException;
-import android.content.Context;
import android.hardware.radio.RadioManager;
import android.os.Handler;
import android.os.IBinder;
@@ -113,7 +112,7 @@
* Should not be obtained directly by clients, use {@link Car.getCarManager()} instead.
* @hide
*/
- public CarRadioManager(IBinder service, Looper looper) {
+ public CarRadioManager(IBinder service, Looper looper) throws CarNotConnectedException {
mService = ICarRadio.Stub.asInterface(service);
mHandler = new EventCallbackHandler(this, looper);
@@ -121,8 +120,8 @@
try {
mCount = mService.getPresetCount();
} catch (RemoteException ex) {
- // Do nothing.
Log.e(TAG, "Could not connect: " + ex.toString());
+ throw new CarNotConnectedException(ex);
}
}
@@ -152,15 +151,15 @@
/**
* Unregister {@link CarRadioEventListener}.
*/
- public synchronized void unregisterListener() {
+ public synchronized void unregisterListener() throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "unregisterListener");
}
try {
mService.unregisterListener(mListenerToService);
} catch (RemoteException ex) {
- // do nothing.
Log.e(TAG, "Could not connect: " + ex.toString());
+ throw new CarNotConnectedException(ex);
}
mListenerToService = null;
mListener = null;
@@ -179,7 +178,7 @@
* Get preset value for a specific radio preset.
* @return: a {@link CarRadioPreset} object, {@link null} if the call failed.
*/
- public CarRadioPreset getPreset(int presetNumber) {
+ public CarRadioPreset getPreset(int presetNumber) throws CarNotConnectedException {
if (DBG) {
Log.d(TAG, "getPreset");
}
@@ -188,7 +187,7 @@
return preset;
} catch (RemoteException ex) {
Log.e(TAG, "getPreset failed with " + ex.toString());
- return null;
+ throw new CarNotConnectedException(ex);
}
}
@@ -204,13 +203,13 @@
* b) Listener is not set correctly, since otherwise the user of this API cannot confirm if the
* request succeeded.
*/
- public boolean setPreset(CarRadioPreset preset) throws IllegalArgumentException {
+ public boolean setPreset(CarRadioPreset preset) throws IllegalArgumentException,
+ CarNotConnectedException {
try {
return mService.setPreset(preset);
} catch (RemoteException ex) {
- // do nothing.
- return false;
- }
+ throw new CarNotConnectedException(ex);
+ }
}
private void dispatchEventToClient(CarRadioEvent event) {
diff --git a/car-support-lib/api/current.txt b/car-support-lib/api/current.txt
index b6f07dd..8024aaa 100644
--- a/car-support-lib/api/current.txt
+++ b/car-support-lib/api/current.txt
@@ -32,12 +32,12 @@
public abstract class CarAppContextManager {
ctor public CarAppContextManager();
- method public abstract int getActiveAppContexts();
- method public abstract boolean isOwningContext(int);
- method public abstract void registerContextListener(android.support.car.CarAppContextManager.AppContextChangeListener, int);
- method public abstract void resetActiveContexts(int);
- method public abstract void setActiveContexts(android.support.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws java.lang.IllegalStateException, java.lang.SecurityException;
- method public abstract void unregisterContextListener();
+ method public abstract int getActiveAppContexts() throws android.support.car.CarNotConnectedException;
+ method public abstract boolean isOwningContext(int) throws android.support.car.CarNotConnectedException;
+ method public abstract void registerContextListener(android.support.car.CarAppContextManager.AppContextChangeListener, int) throws android.support.car.CarNotConnectedException;
+ method public abstract void resetActiveContexts(int) throws android.support.car.CarNotConnectedException;
+ method public abstract void setActiveContexts(android.support.car.CarAppContextManager.AppContextOwnershipChangeListener, int) throws android.support.car.CarNotConnectedException, java.lang.IllegalStateException, java.lang.SecurityException;
+ method public abstract void unregisterContextListener() throws android.support.car.CarNotConnectedException;
field public static final int APP_CONTEXT_NAVIGATION = 1; // 0x1
field public static final int APP_CONTEXT_VOICE_COMMAND = 2; // 0x2
}
@@ -600,8 +600,8 @@
method public abstract boolean isSensorSupported(int) throws android.support.car.CarNotConnectedException;
method public static boolean isSensorSupported(int[], int);
method public abstract boolean registerListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener, int, int) throws android.support.car.CarNotConnectedException, java.lang.IllegalArgumentException;
- method public abstract void unregisterListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener);
- method public abstract void unregisterListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener, int);
+ method public abstract void unregisterListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener) throws android.support.car.CarNotConnectedException;
+ method public abstract void unregisterListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.support.car.CarNotConnectedException;
field public static final int SENSOR_RATE_FAST = 1; // 0x1
field public static final int SENSOR_RATE_FASTEST = 0; // 0x0
field public static final int SENSOR_RATE_NORMAL = 3; // 0x3
diff --git a/car-support-lib/src/android/support/car/CarAppContextManager.java b/car-support-lib/src/android/support/car/CarAppContextManager.java
index 865150c..64198eb 100644
--- a/car-support-lib/src/android/support/car/CarAppContextManager.java
+++ b/car-support-lib/src/android/support/car/CarAppContextManager.java
@@ -70,28 +70,32 @@
* registering multiple times will lead into only the last listener to be active.
* @param listener
* @param contextFilter Flags of contexts to get notification.
+ * @throws CarNotConnectedException
*/
public abstract void registerContextListener(AppContextChangeListener listener,
- int contextFilter);
+ int contextFilter) throws CarNotConnectedException;
/**
* Unregister listener and stop listening context change events. If app has owned a context
* by {@link #setActiveContext(int)}, it will be reset to inactive state.
+ * @throws CarNotConnectedException
*/
- public abstract void unregisterContextListener();
+ public abstract void unregisterContextListener() throws CarNotConnectedException;
/**
* Retrieve currently active contexts.
* @return
+ * @throws CarNotConnectedException
*/
- public abstract int getActiveAppContexts();
+ public abstract int getActiveAppContexts() throws CarNotConnectedException;
/**
* Check if the current process is owning the given context.
* @param context
* @return
+ * @throws CarNotConnectedException
*/
- public abstract boolean isOwningContext(int context);
+ public abstract boolean isOwningContext(int context) throws CarNotConnectedException;
/**
* Set the given contexts as active. By setting this, the application is becoming owner
@@ -103,14 +107,16 @@
* @param contexts
* @throws IllegalStateException If listener was not registered.
* @throws SecurityException If owner cannot be changed.
+ * @throws CarNotConnectedException
*/
public abstract void setActiveContexts(AppContextOwnershipChangeListener ownershipListener,
- int contexts) throws IllegalStateException, SecurityException;
+ int contexts) throws IllegalStateException, SecurityException, CarNotConnectedException;
/**
* Reset the given contexts, i.e. mark them as inactive. This also involves releasing ownership
* for the context.
* @param contexts
+ * @throws CarNotConnectedException
*/
- public abstract void resetActiveContexts(int contexts);
+ public abstract void resetActiveContexts(int contexts) throws CarNotConnectedException;
}
diff --git a/car-support-lib/src/android/support/car/CarAppContextManagerEmbedded.java b/car-support-lib/src/android/support/car/CarAppContextManagerEmbedded.java
index ff289bc..cd145ac 100644
--- a/car-support-lib/src/android/support/car/CarAppContextManagerEmbedded.java
+++ b/car-support-lib/src/android/support/car/CarAppContextManagerEmbedded.java
@@ -38,7 +38,8 @@
}
@Override
- public void registerContextListener(AppContextChangeListener listener, int contextFilter) {
+ public void registerContextListener(AppContextChangeListener listener, int contextFilter)
+ throws CarNotConnectedException {
if (listener == null) {
throw new IllegalArgumentException("null listener");
}
@@ -46,30 +47,48 @@
synchronized(this) {
mListener = proxy;
}
- mManager.registerContextListener(proxy, contextFilter);
+ try {
+ mManager.registerContextListener(proxy, contextFilter);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
- public void unregisterContextListener() {
+ public void unregisterContextListener() throws CarNotConnectedException {
synchronized(this) {
mListener = null;
}
- mManager.unregisterContextListener();
+ try {
+ mManager.unregisterContextListener();
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
+
}
@Override
- public int getActiveAppContexts() {
- return mManager.getActiveAppContexts();
+ public int getActiveAppContexts() throws CarNotConnectedException {
+ try {
+ return mManager.getActiveAppContexts();
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
- public boolean isOwningContext(int context) {
- return mManager.isOwningContext(context);
+ public boolean isOwningContext(int context) throws CarNotConnectedException {
+ try {
+ return mManager.isOwningContext(context);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
public void setActiveContexts(AppContextOwnershipChangeListener ownershipListener,
- int contexts) throws IllegalStateException, SecurityException {
+ int contexts) throws IllegalStateException, SecurityException,
+ CarNotConnectedException {
if (ownershipListener == null) {
throw new IllegalArgumentException("null listener");
}
@@ -82,12 +101,20 @@
}
}
}
- mManager.setActiveContexts(proxy, contexts);
+ try{
+ mManager.setActiveContexts(proxy, contexts);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
- public void resetActiveContexts(int contexts) {
- mManager.resetActiveContexts(contexts);
+ public void resetActiveContexts(int contexts) throws CarNotConnectedException {
+ try {
+ mManager.resetActiveContexts(contexts);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
synchronized (this) {
for (int flag = APP_CONTEXT_START_FLAG; flag <= APP_CONTEXT_END_FLAG; flag <<= 1) {
if ((flag & contexts) != 0) {
diff --git a/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java b/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java
index 7b5c788..f22b95a 100644
--- a/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java
+++ b/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java
@@ -102,8 +102,14 @@
}
@Override
- public Object getCarManager(String serviceName) {
- Object manager = mCar.getCarManager(serviceName);
+ public Object getCarManager(String serviceName) throws CarNotConnectedException {
+ Object manager;
+ try {
+ manager = mCar.getCarManager(serviceName);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
+
if (manager == null) {
return null;
}
diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorManager.java b/car-support-lib/src/android/support/car/hardware/CarSensorManager.java
index ebffaf8..04d63a1 100644
--- a/car-support-lib/src/android/support/car/hardware/CarSensorManager.java
+++ b/car-support-lib/src/android/support/car/hardware/CarSensorManager.java
@@ -17,25 +17,11 @@
package android.support.car.hardware;
import android.Manifest;
-import android.support.annotation.RequiresPermission;
-import android.content.Context;
-import android.os.Handler;
import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.Handler.Callback;
+import android.support.annotation.RequiresPermission;
import android.support.car.Car;
-import android.support.car.CarApiUtil;
-import android.support.car.CarLibLog;
import android.support.car.CarManagerBase;
import android.support.car.CarNotConnectedException;
-import android.util.Log;
-
-import java.lang.ref.WeakReference;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
/**
* API for monitoring car sensor data.
@@ -214,7 +200,8 @@
* this listener, all listening will be stopped.
* @param listener
*/
- public abstract void unregisterListener(CarSensorEventListener listener);
+ public abstract void unregisterListener(CarSensorEventListener listener)
+ throws CarNotConnectedException;
/**
* Stop getting sensor update for the given listener and sensor. If the same listener is used
@@ -222,7 +209,8 @@
* @param listener
* @param sensorType
*/
- public abstract void unregisterListener(CarSensorEventListener listener, int sensorType);
+ public abstract void unregisterListener(CarSensorEventListener listener, int sensorType)
+ throws CarNotConnectedException;
/**
* Get the most recent CarSensorEvent for the given type.
diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java b/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java
index 2c00d3b..dbffb13 100644
--- a/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java
+++ b/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java
@@ -110,7 +110,8 @@
}
@Override
- public void unregisterListener(CarSensorEventListener listener) {
+ public void unregisterListener(CarSensorEventListener listener)
+ throws CarNotConnectedException {
mCarSensorsProxy.unregisterSensorListener(listener);
CarSensorEventListenerProxy proxy = null;
synchronized (this) {
@@ -120,11 +121,16 @@
}
mListeners.remove(proxy);
}
- mManager.unregisterListener(proxy);
+ try {
+ mManager.unregisterListener(proxy);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
- public void unregisterListener(CarSensorEventListener listener, int sensorType) {
+ public void unregisterListener(CarSensorEventListener listener, int sensorType)
+ throws CarNotConnectedException {
mCarSensorsProxy.unregisterSensorListener(listener, sensorType);
CarSensorEventListenerProxy proxy = null;
synchronized (this) {
@@ -137,7 +143,11 @@
mListeners.remove(proxy);
}
}
- mManager.unregisterListener(proxy, sensorType);
+ try {
+ mManager.unregisterListener(proxy, sensorType);
+ } catch (android.car.CarNotConnectedException e) {
+ throw new CarNotConnectedException(e);
+ }
}
@Override
diff --git a/car-systemtest-lib/src/android/car/test/VehicleHalEmulator.java b/car-systemtest-lib/src/android/car/test/VehicleHalEmulator.java
index 1abf02c..876ad6e 100644
--- a/car-systemtest-lib/src/android/car/test/VehicleHalEmulator.java
+++ b/car-systemtest-lib/src/android/car/test/VehicleHalEmulator.java
@@ -71,8 +71,12 @@
* @param car
*/
public VehicleHalEmulator(Car car) {
- mCarTestManager = new CarTestManager(
- (CarTestManagerBinderWrapper) car.getCarManager(Car.TEST_SERVICE));
+ try {
+ mCarTestManager = new CarTestManager(
+ (CarTestManagerBinderWrapper) car.getCarManager(Car.TEST_SERVICE));
+ } catch (CarNotConnectedException e) {
+ throw new RuntimeException(e);
+ }
}
/**
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
index 903b436..88270da 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java
@@ -146,7 +146,11 @@
protected void onDestroy() {
super.onDestroy();
if (mCarSensorManager != null) {
- mCarSensorManager.unregisterListener(mListener);
+ try {
+ mCarSensorManager.unregisterListener(mListener);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to unregister car seonsor listener", e);
+ }
}
if (mCarApi != null) {
mCarApi.disconnect();
@@ -176,9 +180,9 @@
mCarAppContextManager =
(CarAppContextManager) mCarApi.getCarManager(Car.APP_CONTEXT_SERVICE);
} catch (CarNotConnectedException e) {
- Log.e(TAG, "Car is not connected!");
+ Log.e(TAG, "Car is not connected!", e);
} catch (CarNotSupportedException e) {
- Log.e(TAG, "Car is not supported!");
+ Log.e(TAG, "Car is not supported!", e);
}
}
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/audio/AudioTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/audio/AudioTestFragment.java
index e1198e0..16e2e57 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/audio/AudioTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/audio/AudioTestFragment.java
@@ -128,15 +128,27 @@
mCar = Car.createCar(mContext, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
- mAppContextManager =
- (CarAppContextManager) mCar.getCarManager(Car.APP_CONTEXT_SERVICE);
- mAppContextManager.registerContextListener(new AppContextChangeListener() {
- @Override
- public void onAppContextChange(int activeContexts) {
- }
- }, CarAppContextManager.APP_CONTEXT_NAVIGATION |
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
- mCarAudioManager = (CarAudioManager) mCar.getCarManager(Car.AUDIO_SERVICE);
+ try {
+ mAppContextManager =
+ (CarAppContextManager) mCar.getCarManager(Car.APP_CONTEXT_SERVICE);
+ } catch (CarNotConnectedException e) {
+ throw new RuntimeException("Failed to create app context manager", e);
+ }
+ try {
+ mAppContextManager.registerContextListener(new AppContextChangeListener() {
+ @Override
+ public void onAppContextChange(int activeContexts) {
+ }
+ }, CarAppContextManager.APP_CONTEXT_NAVIGATION |
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to register context listener", e);
+ }
+ try {
+ mCarAudioManager = (CarAudioManager) mCar.getCarManager(Car.AUDIO_SERVICE);
+ } catch (CarNotConnectedException e) {
+ throw new RuntimeException("Failed to create audio manager", e);
+ }
mMusicAudioAttrib = mCarAudioManager.getAudioAttributesForCarUsage(
CarAudioManager.CAR_AUDIO_USAGE_MUSIC);
mNavAudioAttrib = mCarAudioManager.getAudioAttributesForCarUsage(
@@ -147,6 +159,7 @@
CarAudioManager.CAR_AUDIO_USAGE_RADIO);
mSystemSoundAudioAttrib = mCarAudioManager.getAudioAttributesForCarUsage(
CarAudioManager.CAR_AUDIO_USAGE_SYSTEM_SOUND);
+
mMusicPlayer = new AudioPlayer(mContext, R.raw.john_harrison_with_the_wichita_state_university_chamber_players_05_summer_mvt_2_adagio,
mMusicAudioAttrib);
mMusicPlayerShort = new AudioPlayer(mContext, R.raw.ring_classic_01,
@@ -169,7 +182,7 @@
@Override
public void onServiceDisconnected(ComponentName name) {
}
- }, Looper.getMainLooper());
+ }, Looper.getMainLooper());
mCar.connect();
}
@@ -223,15 +236,23 @@
Log.i(TAG, "Nav start");
}
if (!mNavGuidancePlayer.isPlaying()) {
- mAppContextManager.setActiveContexts(mOwnershipListener,
- CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ try {
+ mAppContextManager.setActiveContexts(mOwnershipListener,
+ CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set active context", e);
+ }
mNavGuidancePlayer.start(true, false,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
new PlayStateListener() {
@Override
public void onCompletion() {
- mAppContextManager.resetActiveContexts(
- CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ try {
+ mAppContextManager.resetActiveContexts(
+ CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to reset active context", e);
+ }
}
});
}
@@ -247,15 +268,23 @@
if (DBG) {
Log.i(TAG, "VR start");
}
- mAppContextManager.setActiveContexts(mOwnershipListener,
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ try {
+ mAppContextManager.setActiveContexts(mOwnershipListener,
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set active context", e);
+ }
if (!mVrPlayer.isPlaying()) {
mVrPlayer.start(true, false, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT,
new PlayStateListener() {
@Override
public void onCompletion() {
- mAppContextManager.resetActiveContexts(
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ try {
+ mAppContextManager.resetActiveContexts(
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to reset active context", e);
+ }
}
});
}
@@ -400,8 +429,12 @@
mAudioFocusHandler = null;
}
if (mAppContextManager != null) {
- mAppContextManager.resetActiveContexts(CarAppContextManager.APP_CONTEXT_NAVIGATION |
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ try {
+ mAppContextManager.resetActiveContexts(CarAppContextManager.APP_CONTEXT_NAVIGATION |
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to reset active context", e);
+ }
}
}
@@ -415,8 +448,12 @@
if (DBG) {
Log.i(TAG, "Nav start");
}
- mAppContextManager.setActiveContexts(mOwnershipListener,
- CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ try {
+ mAppContextManager.setActiveContexts(mOwnershipListener,
+ CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set active context", e);
+ }
mCarAudioManager.requestAudioFocus(mNavFocusListener, mNavAudioAttrib,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, 0);
}
@@ -431,8 +468,12 @@
if (DBG) {
Log.i(TAG, "Nav end");
}
- mAppContextManager.resetActiveContexts(
- CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ try {
+ mAppContextManager.resetActiveContexts(
+ CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to reset active context", e);
+ }
mCarAudioManager.abandonAudioFocus(mNavFocusListener, mNavAudioAttrib);
}
@@ -446,8 +487,12 @@
if (DBG) {
Log.i(TAG, "VR start");
}
- mAppContextManager.setActiveContexts(mOwnershipListener,
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ try {
+ mAppContextManager.setActiveContexts(mOwnershipListener,
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set active context", e);
+ }
mCarAudioManager.requestAudioFocus(mVrFocusListener, mVrAudioAttrib,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, 0);
}
@@ -462,8 +507,12 @@
if (DBG) {
Log.i(TAG, "VR end");
}
- mAppContextManager.resetActiveContexts(
- CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ try {
+ mAppContextManager.resetActiveContexts(
+ CarAppContextManager.APP_CONTEXT_VOICE_COMMAND);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to reset active context", e);
+ }
mCarAudioManager.abandonAudioFocus(mVrFocusListener, mVrAudioAttrib);
}
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/camera/CameraTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/camera/CameraTestFragment.java
index 8d68cf4..f9f1319 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/camera/CameraTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/camera/CameraTestFragment.java
@@ -16,20 +16,18 @@
package com.google.android.car.kitchensink.camera;
-import android.os.Bundle;
import android.car.CarNotConnectedException;
import android.car.hardware.camera.CarCamera;
-import android.car.hardware.camera.CarCameraState;
import android.car.hardware.camera.CarCameraManager;
+import android.car.hardware.camera.CarCameraState;
import android.graphics.Rect;
+import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import android.widget.RadioButton;
-import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;
@@ -67,19 +65,27 @@
Button btn = (Button) v.findViewById(R.id.btnGetCap);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- int cap = mRvcCamera.getCapabilities();
- mTvCap.setText(String.valueOf(cap));
+ try {
+ int cap = mRvcCamera.getCapabilities();
+ mTvCap.setText(String.valueOf(cap));
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get camera capabilities", e);
+ }
}
});
btn = (Button) v.findViewById(R.id.btnGetRvcCrop);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- Rect rect = mRvcCamera.getCameraCrop();
- if(rect != null) {
- mTvRvcCrop.setText(rect.toString());
- } else {
- mTvRvcCrop.setText("null");
+ try {
+ Rect rect = mRvcCamera.getCameraCrop();
+ if(rect != null) {
+ mTvRvcCrop.setText(rect.toString());
+ } else {
+ mTvRvcCrop.setText("null");
+ }
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get camera crop", e);
}
}
});
@@ -87,11 +93,15 @@
btn = (Button) v.findViewById(R.id.btnGetRvcPos);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- Rect rect = mRvcCamera.getCameraPosition();
- if(rect != null) {
- mTvRvcPos.setText(String.valueOf(rect));
- } else {
- mTvRvcPos.setText("null");
+ try {
+ Rect rect = mRvcCamera.getCameraPosition();
+ if(rect != null) {
+ mTvRvcPos.setText(String.valueOf(rect));
+ } else {
+ mTvRvcPos.setText("null");
+ }
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get camere position", e);
}
}
});
@@ -99,11 +109,15 @@
btn = (Button) v.findViewById(R.id.btnGetCameraState);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- CarCameraState state = mRvcCamera.getCameraState();
- if(state != null) {
- mTvCameraState.setText(state.toString());
- } else {
- mTvCameraState.setText("null");
+ try {
+ CarCameraState state = mRvcCamera.getCameraState();
+ if(state != null) {
+ mTvCameraState.setText(state.toString());
+ } else {
+ mTvCameraState.setText("null");
+ }
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get camere state", e);
}
}
});
@@ -112,7 +126,11 @@
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Rect rect = new Rect(160, 240, 560, 480);
- mRvcCamera.setCameraCrop(rect);
+ try {
+ mRvcCamera.setCameraCrop(rect);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera crop", e);
+ }
}
});
@@ -120,7 +138,11 @@
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Rect rect = new Rect(0, 0, 720, 480);
- mRvcCamera.setCameraCrop(rect);
+ try {
+ mRvcCamera.setCameraCrop(rect);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera crop", e);
+ }
}
});
@@ -128,7 +150,11 @@
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Rect rect = new Rect(300, 0, 800, 480);
- mRvcCamera.setCameraPosition(rect);
+ try {
+ mRvcCamera.setCameraPosition(rect);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera position", e);
+ }
}
});
@@ -136,7 +162,11 @@
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Rect rect = new Rect(500, 0, 800, 480);
- mRvcCamera.setCameraPosition(rect);
+ try {
+ mRvcCamera.setCameraPosition(rect);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera position", e);
+ }
}
});
@@ -144,7 +174,11 @@
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Rect rect = new Rect(300, 0, 500, 300);
- mRvcCamera.setCameraPosition(rect);
+ try {
+ mRvcCamera.setCameraPosition(rect);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera position", e);
+ }
}
});
@@ -152,7 +186,11 @@
toggleBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CarCameraState state = new CarCameraState(false, toggleBtn.isChecked());
- mRvcCamera.setCameraState(state);
+ try {
+ mRvcCamera.setCameraState(state);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set camera state", e);
+ }
}
});
@@ -167,4 +205,3 @@
mCarCameraManager = cameraManager;
}
}
-
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/cluster/InstrumentClusterFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/cluster/InstrumentClusterFragment.java
index 0c633a4..91f8d39 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/cluster/InstrumentClusterFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/cluster/InstrumentClusterFragment.java
@@ -15,8 +15,6 @@
*/
package com.google.android.car.kitchensink.cluster;
-import com.google.android.car.kitchensink.R;
-
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
@@ -32,6 +30,8 @@
import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import com.google.android.car.kitchensink.R;
+
/**
* Contains functions to test instrument cluster API.
*/
@@ -82,35 +82,48 @@
}
private void initCluster() {
- mCarAppContextManager.registerContextListener(new AppContextChangeListener() {
- @Override
- public void onAppContextChange(int activeContexts) {
- Log.d(TAG, "onAppContextChange, activeContexts: " + activeContexts);
- }
- }, CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ try {
+ mCarAppContextManager.registerContextListener(new AppContextChangeListener() {
+ @Override
+ public void onAppContextChange(int activeContexts) {
+ Log.d(TAG, "onAppContextChange, activeContexts: " + activeContexts);
+ }
+ }, CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to register context listener", e);
+ }
- mCarAppContextManager.setActiveContexts(new AppContextOwnershipChangeListener() {
- @Override
- public void onAppContextOwnershipLoss(int context) {
- Log.w(TAG, "onAppContextOwnershipLoss, context: " + context);
+ try {
+ mCarAppContextManager.setActiveContexts(new AppContextOwnershipChangeListener() {
+ @Override
+ public void onAppContextOwnershipLoss(int context) {
+ Log.w(TAG, "onAppContextOwnershipLoss, context: " + context);
+ new AlertDialog.Builder(getContext())
+ .setTitle(getContext().getApplicationInfo().name)
+ .setMessage(R.string.cluster_nav_app_context_loss)
+ .show();
+ }
+ }, CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set active context", e);
+ }
- new AlertDialog.Builder(getContext())
- .setTitle(getContext().getApplicationInfo().name)
- .setMessage(R.string.cluster_nav_app_context_loss)
- .show();
+ try {
+ boolean ownsContext =
+ mCarAppContextManager.isOwningContext(
+ CarAppContextManager.APP_CONTEXT_NAVIGATION);
+ Log.d(TAG, "Owns APP_CONTEXT_NAVIGATION: " + ownsContext);
+ if (!ownsContext) {
+ throw new RuntimeException("Context was not acquired.");
}
- }, CarAppContextManager.APP_CONTEXT_NAVIGATION);
- boolean ownsContext =
- mCarAppContextManager.isOwningContext(CarAppContextManager.APP_CONTEXT_NAVIGATION);
- Log.d(TAG, "Owns APP_CONTEXT_NAVIGATION: " + ownsContext);
- if (!ownsContext) {
- throw new RuntimeException("Context was not acquired.");
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get owned context", e);
}
try {
mCarNavigationManager.sendNavigationStatus(CarNavigationManager.STATUS_ACTIVE);
} catch (CarNotConnectedException e) {
- e.printStackTrace();
+ Log.e(TAG, "Failed to set navigation status", e);
}
}
}
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/hvac/HvacTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/hvac/HvacTestFragment.java
index 0354a76..baffbf9 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/hvac/HvacTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/hvac/HvacTestFragment.java
@@ -18,14 +18,11 @@
import android.car.CarNotConnectedException;
import android.car.VehicleZoneUtil;
-import android.car.hardware.hvac.CarHvacEvent;
+import android.car.hardware.hvac.CarHvacManager;
import android.car.hardware.hvac.CarHvacManager.CarHvacBaseProperty;
import android.car.hardware.hvac.CarHvacManager.CarHvacBooleanValue;
-import android.car.hardware.hvac.CarHvacManager.CarHvacFloatProperty;
import android.car.hardware.hvac.CarHvacManager.CarHvacFloatValue;
-import android.car.hardware.hvac.CarHvacManager.CarHvacIntProperty;
import android.car.hardware.hvac.CarHvacManager.CarHvacIntValue;
-import android.car.hardware.hvac.CarHvacManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
@@ -45,6 +42,7 @@
import com.google.android.car.kitchensink.R;
import java.lang.Override;
+import java.util.ArrayList;
import java.util.List;
public class HvacTestFragment extends Fragment {
@@ -147,14 +145,24 @@
@Override
public void onDestroy() {
super.onDestroy();
- mCarHvacManager.unregisterListener();
+ try {
+ mCarHvacManager.unregisterListener();
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to unregister listener", e);
+ }
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
View v = inflater.inflate(R.layout.hvac_test, container, false);
- List<CarHvacBaseProperty> props = mCarHvacManager.getPropertyList();
+ List<CarHvacBaseProperty> props;
+ try {
+ props = mCarHvacManager.getPropertyList();
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get HVAC properties", e);
+ props = new ArrayList<>();
+ }
for(CarHvacBaseProperty prop : props) {
int propId = prop.getPropertyId();
@@ -212,8 +220,12 @@
mTbAc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO handle zone properly
- mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_ZONED_AC_ON, mZoneForAcOn,
- mTbAc.isChecked());
+ try {
+ mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_ZONED_AC_ON,
+ mZoneForAcOn, mTbAc.isChecked());
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC boolean property", e);
+ }
}
});
}
@@ -226,19 +238,31 @@
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId) {
case R.id.rbPositionFace:
- mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
- mZoneForFanPosition,
- VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FACE);
+ try{
+ mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
+ mZoneForFanPosition,
+ VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FACE);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC int property", e);
+ }
break;
case R.id.rbPositionFloor:
- mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
- mZoneForFanPosition,
- VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FLOOR);
+ try {
+ mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
+ mZoneForFanPosition,
+ VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FLOOR);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC int property", e);
+ }
break;
case R.id.rbPositionFaceAndFloor:
- mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
- mZoneForFanPosition,
- VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FACE_AND_FLOOR);
+ try {
+ mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_POSITION,
+ mZoneForFanPosition,
+ VehicleHvacFanDirection.VEHICLE_HVAC_FAN_DIRECTION_FACE_AND_FLOOR);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC int property", e);
+ }
break;
}
}
@@ -254,9 +278,13 @@
private void configureFanSpeed(View v, CarHvacBaseProperty prop) {
mZoneForFanSpeed = VehicleZoneUtil.getFirstZone(prop.getZones());
- mCurFanSpeed = mCarHvacManager.getIntProperty(
- CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
- mZoneForFanSpeed);
+ try {
+ mCurFanSpeed = mCarHvacManager.getIntProperty(
+ CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
+ mZoneForFanSpeed);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get HVAC fan speed property", e);
+ }
Button btnFanSpeedUp = (Button) v.findViewById(R.id.btnFanSpeedUp);
btnFanSpeedUp.setEnabled(true);
@@ -265,8 +293,12 @@
if(mCurFanSpeed < 7) {
mCurFanSpeed++;
mTvFanSpeed.setText(String.valueOf(mCurFanSpeed));
- mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
- mZoneForFanSpeed, mCurFanSpeed);
+ try {
+ mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
+ mZoneForFanSpeed, mCurFanSpeed);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC fan speed property", e);
+ }
}
}
});
@@ -278,8 +310,12 @@
if (mCurFanSpeed > 1) {
mCurFanSpeed--;
mTvFanSpeed.setText(String.valueOf(mCurFanSpeed));
- mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
- mZoneForFanSpeed, mCurFanSpeed);
+ try {
+ mCarHvacManager.setIntProperty(CarHvacManager.HVAC_ZONED_FAN_SPEED_SETPOINT,
+ mZoneForFanSpeed, mCurFanSpeed);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC fan speed property", e);
+ }
}
}
});
@@ -306,17 +342,26 @@
}
Button btnDTempUp = (Button) v.findViewById(R.id.btnDTempUp);
if (mZoneForSetTempD != 0) {
- mCurDTemp = mCarHvacManager.getFloatProperty(
- CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempD);
+ try {
+ mCurDTemp = mCarHvacManager.getFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempD);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get HVAC zoned temp property", e);
+ }
btnDTempUp.setEnabled(true);
btnDTempUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mCurDTemp < 29.5) {
mCurDTemp += 0.5;
mTvDTemp.setText(String.valueOf(mCurDTemp));
- mCarHvacManager.setFloatProperty(CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempD, mCurDTemp);
+ try {
+ mCarHvacManager.setFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempD, mCurDTemp);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC zoned temp property", e);
+ }
}
}
});
@@ -328,8 +373,13 @@
if(mCurDTemp > 15.5) {
mCurDTemp -= 0.5;
mTvDTemp.setText(String.valueOf(mCurDTemp));
- mCarHvacManager.setFloatProperty(CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempD, mCurDTemp);
+ try {
+ mCarHvacManager.setFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempD, mCurDTemp);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC zoned temp property", e);
+ }
}
}
});
@@ -339,17 +389,26 @@
Button btnPTempUp = (Button) v.findViewById(R.id.btnPTempUp);
if (mZoneForSetTempP !=0 ) {
- mCurPTemp = mCarHvacManager.getFloatProperty(
- CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempP);
+ try {
+ mCurPTemp = mCarHvacManager.getFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempP);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to get HVAC zoned temp property", e);
+ }
btnPTempUp.setEnabled(true);
btnPTempUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mCurPTemp < 29.5) {
mCurPTemp += 0.5;
mTvPTemp.setText(String.valueOf(mCurPTemp));
- mCarHvacManager.setFloatProperty(CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempP, mCurPTemp);
+ try {
+ mCarHvacManager.setFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempP, mCurPTemp);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC zoned temp property", e);
+ }
}
}
});
@@ -361,8 +420,13 @@
if (mCurPTemp > 15.5) {
mCurPTemp -= 0.5;
mTvPTemp.setText(String.valueOf(mCurPTemp));
- mCarHvacManager.setFloatProperty(CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
- mZoneForSetTempP, mCurPTemp);
+ try {
+ mCarHvacManager.setFloatProperty(
+ CarHvacManager.HVAC_ZONED_TEMP_SETPOINT,
+ mZoneForSetTempP, mCurPTemp);
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC zoned temp property", e);
+ }
}
}
});
@@ -378,9 +442,13 @@
mTbDefrostFront.setEnabled(true);
mTbDefrostFront.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_WINDOW_DEFROSTER_ON,
- VehicleWindow.VEHICLE_WINDOW_FRONT_WINDSHIELD,
- mTbDefrostFront.isChecked());
+ try {
+ mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_WINDOW_DEFROSTER_ON,
+ VehicleWindow.VEHICLE_WINDOW_FRONT_WINDSHIELD,
+ mTbDefrostFront.isChecked());
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC wondow defroster property", e);
+ }
}
});
}
@@ -390,12 +458,15 @@
mTbDefrostRear.setEnabled(true);
mTbDefrostRear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_WINDOW_DEFROSTER_ON,
- VehicleWindow.VEHICLE_WINDOW_REAR_WINDSHIELD,
- mTbDefrostRear.isChecked());
+ try {
+ mCarHvacManager.setBooleanProperty(CarHvacManager.HVAC_WINDOW_DEFROSTER_ON,
+ VehicleWindow.VEHICLE_WINDOW_REAR_WINDSHIELD,
+ mTbDefrostRear.isChecked());
+ } catch (CarNotConnectedException e) {
+ Log.e(TAG, "Failed to set HVAC window deforster property", e);
+ }
}
});
}
}
}
-
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
index 329d4ed..a177c00 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/input/InputTestFragment.java
@@ -18,6 +18,7 @@
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.car.Car;
+import android.car.CarNotConnectedException;
import android.car.test.CarTestManager;
import android.car.test.CarTestManagerBinderWrapper;
import android.content.ComponentName;
@@ -31,6 +32,7 @@
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
@@ -45,6 +47,12 @@
import java.util.Collections;
import java.util.List;
+import com.android.car.vehiclenetwork.VehicleNetworkConsts;
+import com.android.car.vehiclenetwork.VehicleNetworkConsts.VehicleHwKeyInputAction;
+import com.android.car.vehiclenetwork.VehiclePropValueUtil;
+
+import com.google.android.car.kitchensink.R;
+
/**
* Test input event handling to system.
* vehicle hal should have VEHICLE_PROPERTY_HW_KEY_INPUT support for this to work.
@@ -90,8 +98,12 @@
mCar = Car.createCar(getContext(), new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
- mTestManager = new CarTestManager(
- (CarTestManagerBinderWrapper) mCar.getCarManager(Car.TEST_SERVICE));
+ try {
+ mTestManager = new CarTestManager(
+ (CarTestManagerBinderWrapper) mCar.getCarManager(Car.TEST_SERVICE));
+ } catch (CarNotConnectedException e) {
+ throw new RuntimeException("Failed to create test service manager", e);
+ }
boolean hwKeySupported = mTestManager.isPropertySupported(
VehicleNetworkConsts.VEHICLE_PROPERTY_HW_KEY_INPUT);
if (!hwKeySupported) {