diff options
66 files changed, 749 insertions, 834 deletions
diff --git a/car-lib/api/current.txt b/car-lib/api/current.txt index 8a386751e6..ec156b0e8a 100644 --- a/car-lib/api/current.txt +++ b/car-lib/api/current.txt @@ -23,25 +23,25 @@ package android.car { } public final class CarAppFocusManager { - method public void abandonAppFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener, int) throws android.car.CarNotConnectedException; - method public void abandonAppFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.car.CarNotConnectedException; - method public boolean isOwningFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener, int) throws android.car.CarNotConnectedException; - method public void registerFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener, int) throws android.car.CarNotConnectedException; - method public int requestAppFocus(int, android.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.car.CarNotConnectedException, java.lang.SecurityException; - method public void unregisterFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener, int) throws android.car.CarNotConnectedException; - method public void unregisterFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener) throws android.car.CarNotConnectedException; + method public void abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener, int) throws android.car.CarNotConnectedException; + method public void abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.car.CarNotConnectedException; + method public void addFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.car.CarNotConnectedException; + method public boolean isOwningFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener, int) throws android.car.CarNotConnectedException; + method public void removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.car.CarNotConnectedException; + method public void removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener) throws android.car.CarNotConnectedException; + method public int requestAppFocus(int, android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.car.CarNotConnectedException, java.lang.SecurityException; field public static final int APP_FOCUS_REQUEST_FAILED = 0; // 0x0 field public static final int APP_FOCUS_REQUEST_GRANTED = 1; // 0x1 field public static final int APP_FOCUS_TYPE_NAVIGATION = 1; // 0x1 field public static final int APP_FOCUS_TYPE_VOICE_COMMAND = 2; // 0x2 } - public static abstract interface CarAppFocusManager.AppFocusChangeListener { - method public abstract void onAppFocusChange(int, boolean); + public static abstract interface CarAppFocusManager.OnAppFocusChangedListener { + method public abstract void onAppFocusChanged(int, boolean); } - public static abstract interface CarAppFocusManager.AppFocusOwnershipChangeListener { - method public abstract void onAppFocusOwnershipLoss(int); + public static abstract interface CarAppFocusManager.OnAppFocusOwnershipLostListener { + method public abstract void onAppFocusOwnershipLost(int); } public class CarInfoManager { @@ -62,11 +62,11 @@ package android.car { ctor public CarNotConnectedException(java.lang.Exception); } - public class CarNotSupportedException extends java.lang.Exception { - ctor public CarNotSupportedException(); - ctor public CarNotSupportedException(java.lang.String); - ctor public CarNotSupportedException(java.lang.String, java.lang.Throwable); - ctor public CarNotSupportedException(java.lang.Exception); + public class CarOperationNotSupportedException extends java.lang.Exception { + ctor public CarOperationNotSupportedException(); + ctor public CarOperationNotSupportedException(java.lang.String); + ctor public CarOperationNotSupportedException(java.lang.String, java.lang.Throwable); + ctor public CarOperationNotSupportedException(java.lang.Exception); } } @@ -238,26 +238,26 @@ package android.car.hardware { field public final float[] floatValues; field public final int[] intValues; field public int sensorType; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.CarSpeedData { ctor public CarSensorEvent.CarSpeedData(); field public float carSpeed; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.DrivingStatusData { ctor public CarSensorEvent.DrivingStatusData(); field public int status; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.EnvironmentData { ctor public CarSensorEvent.EnvironmentData(); field public float pressure; field public float temperature; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.FuelLevelData { @@ -265,37 +265,37 @@ package android.car.hardware { field public int level; field public boolean lowFuelWarning; field public float range; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.GearData { ctor public CarSensorEvent.GearData(); field public int gear; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.NightData { ctor public CarSensorEvent.NightData(); field public boolean isNightMode; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.OdometerData { ctor public CarSensorEvent.OdometerData(); field public float kms; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.ParkingBrakeData { ctor public CarSensorEvent.ParkingBrakeData(); field public boolean isEngaged; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.RpmData { ctor public CarSensorEvent.RpmData(); field public float rpm; - field public long timeStampNs; + field public long timestamp; } public class CarSensorManager { @@ -303,9 +303,9 @@ package android.car.hardware { method public int[] getSupportedSensors() throws android.car.CarNotConnectedException; 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) throws android.car.CarNotConnectedException; - method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.car.CarNotConnectedException; + method public boolean registerListener(android.car.hardware.CarSensorManager.OnSensorChangedListener, int, int) throws android.car.CarNotConnectedException, java.lang.IllegalArgumentException; + method public void unregisterListener(android.car.hardware.CarSensorManager.OnSensorChangedListener) throws android.car.CarNotConnectedException; + method public void unregisterListener(android.car.hardware.CarSensorManager.OnSensorChangedListener, 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 @@ -322,7 +322,7 @@ package android.car.hardware { field public static final int SENSOR_TYPE_VENDOR_EXTENSION_END = 1879048191; // 0x6fffffff } - public static abstract interface CarSensorManager.CarSensorEventListener { + public static abstract interface CarSensorManager.OnSensorChangedListener { method public abstract void onSensorChanged(android.car.hardware.CarSensorEvent); } diff --git a/car-lib/api/system-current.txt b/car-lib/api/system-current.txt index 3e162c31ac..74807f4aae 100644 --- a/car-lib/api/system-current.txt +++ b/car-lib/api/system-current.txt @@ -38,25 +38,25 @@ package android.car { } public final class CarAppFocusManager { - method public void abandonAppFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener, int) throws android.car.CarNotConnectedException; - method public void abandonAppFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.car.CarNotConnectedException; - method public boolean isOwningFocus(android.car.CarAppFocusManager.AppFocusOwnershipChangeListener, int) throws android.car.CarNotConnectedException; - method public void registerFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener, int) throws android.car.CarNotConnectedException; - method public int requestAppFocus(int, android.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.car.CarNotConnectedException, java.lang.SecurityException; - method public void unregisterFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener, int) throws android.car.CarNotConnectedException; - method public void unregisterFocusListener(android.car.CarAppFocusManager.AppFocusChangeListener) throws android.car.CarNotConnectedException; + method public void abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener, int) throws android.car.CarNotConnectedException; + method public void abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.car.CarNotConnectedException; + method public void addFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.car.CarNotConnectedException; + method public boolean isOwningFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener, int) throws android.car.CarNotConnectedException; + method public void removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.car.CarNotConnectedException; + method public void removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener) throws android.car.CarNotConnectedException; + method public int requestAppFocus(int, android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.car.CarNotConnectedException, java.lang.SecurityException; field public static final int APP_FOCUS_REQUEST_FAILED = 0; // 0x0 field public static final int APP_FOCUS_REQUEST_GRANTED = 1; // 0x1 field public static final int APP_FOCUS_TYPE_NAVIGATION = 1; // 0x1 field public static final int APP_FOCUS_TYPE_VOICE_COMMAND = 2; // 0x2 } - public static abstract interface CarAppFocusManager.AppFocusChangeListener { - method public abstract void onAppFocusChange(int, boolean); + public static abstract interface CarAppFocusManager.OnAppFocusChangedListener { + method public abstract void onAppFocusChanged(int, boolean); } - public static abstract interface CarAppFocusManager.AppFocusOwnershipChangeListener { - method public abstract void onAppFocusOwnershipLoss(int); + public static abstract interface CarAppFocusManager.OnAppFocusOwnershipLostListener { + method public abstract void onAppFocusOwnershipLost(int); } public class CarInfoManager { @@ -77,11 +77,11 @@ package android.car { ctor public CarNotConnectedException(java.lang.Exception); } - public class CarNotSupportedException extends java.lang.Exception { - ctor public CarNotSupportedException(); - ctor public CarNotSupportedException(java.lang.String); - ctor public CarNotSupportedException(java.lang.String, java.lang.Throwable); - ctor public CarNotSupportedException(java.lang.Exception); + public class CarOperationNotSupportedException extends java.lang.Exception { + ctor public CarOperationNotSupportedException(); + ctor public CarOperationNotSupportedException(java.lang.String); + ctor public CarOperationNotSupportedException(java.lang.String, java.lang.Throwable); + ctor public CarOperationNotSupportedException(java.lang.Exception); } public class CarProjectionManager { @@ -473,26 +473,26 @@ package android.car.hardware { field public final float[] floatValues; field public final int[] intValues; field public int sensorType; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.CarSpeedData { ctor public CarSensorEvent.CarSpeedData(); field public float carSpeed; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.DrivingStatusData { ctor public CarSensorEvent.DrivingStatusData(); field public int status; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.EnvironmentData { ctor public CarSensorEvent.EnvironmentData(); field public float pressure; field public float temperature; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.FuelLevelData { @@ -500,37 +500,37 @@ package android.car.hardware { field public int level; field public boolean lowFuelWarning; field public float range; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.GearData { ctor public CarSensorEvent.GearData(); field public int gear; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.NightData { ctor public CarSensorEvent.NightData(); field public boolean isNightMode; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.OdometerData { ctor public CarSensorEvent.OdometerData(); field public float kms; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.ParkingBrakeData { ctor public CarSensorEvent.ParkingBrakeData(); field public boolean isEngaged; - field public long timeStampNs; + field public long timestamp; } public static class CarSensorEvent.RpmData { ctor public CarSensorEvent.RpmData(); field public float rpm; - field public long timeStampNs; + field public long timestamp; } public class CarSensorManager { @@ -538,9 +538,9 @@ package android.car.hardware { method public int[] getSupportedSensors() throws android.car.CarNotConnectedException; 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) throws android.car.CarNotConnectedException; - method public void unregisterListener(android.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.car.CarNotConnectedException; + method public boolean registerListener(android.car.hardware.CarSensorManager.OnSensorChangedListener, int, int) throws android.car.CarNotConnectedException, java.lang.IllegalArgumentException; + method public void unregisterListener(android.car.hardware.CarSensorManager.OnSensorChangedListener) throws android.car.CarNotConnectedException; + method public void unregisterListener(android.car.hardware.CarSensorManager.OnSensorChangedListener, 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 @@ -557,7 +557,7 @@ package android.car.hardware { field public static final int SENSOR_TYPE_VENDOR_EXTENSION_END = 1879048191; // 0x6fffffff } - public static abstract interface CarSensorManager.CarSensorEventListener { + public static abstract interface CarSensorManager.OnSensorChangedListener { method public abstract void onSensorChanged(android.car.hardware.CarSensorEvent); } diff --git a/car-lib/src/android/car/Car.java b/car-lib/src/android/car/Car.java index cda386f62d..1dc798a0d6 100644 --- a/car-lib/src/android/car/Car.java +++ b/car-lib/src/android/car/Car.java @@ -433,7 +433,7 @@ public class Car { * 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 + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public Object getCarManager(String serviceName) throws CarNotConnectedException { CarManagerBase manager; @@ -479,7 +479,7 @@ public class Car { * original exception. * * @param e exception from XyzCarService. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @hide */ public static void checkCarNotConnectedExceptionFromCarService( diff --git a/car-lib/src/android/car/CarApiUtil.java b/car-lib/src/android/car/CarApiUtil.java index 454461af52..e4a7a60624 100644 --- a/car-lib/src/android/car/CarApiUtil.java +++ b/car-lib/src/android/car/CarApiUtil.java @@ -34,7 +34,7 @@ public final class CarApiUtil { /** * CarService throw IllegalStateException with this message is re-thrown as - * {@link CarNotSupportedException}. + * {@link CarOperationNotSupportedException}. * * @hide */ @@ -45,17 +45,17 @@ public final class CarApiUtil { * exception. * * @param e exception from CarService - * @throws CarNotConnectedException - * @throws CarNotSupportedException + * @throws CarNotConnectedException if the connection to the car service has been lost. + * @throws CarOperationNotSupportedException * @hide */ public static void checkAllIllegalStateExceptionsFromCarService(IllegalStateException e) - throws CarNotConnectedException, CarNotSupportedException { + throws CarNotConnectedException, CarOperationNotSupportedException { String message = e.getMessage(); if (message.equals(CAR_NOT_CONNECTED_EXCEPTION_MSG)) { throw new CarNotConnectedException(); } else if (message.equals(CAR_NOT_SUPPORTED_EXCEPTION_MSG)) { - throw new CarNotSupportedException(); + throw new CarOperationNotSupportedException(); } else { throw e; } @@ -67,7 +67,7 @@ public final class CarApiUtil { * exception. * * @param e exception from CarService - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @hide */ public static void checkCarNotConnectedExceptionFromCarService(IllegalStateException e) diff --git a/car-lib/src/android/car/CarAppFocusManager.java b/car-lib/src/android/car/CarAppFocusManager.java index dea903f356..2bd03eab90 100644 --- a/car-lib/src/android/car/CarAppFocusManager.java +++ b/car-lib/src/android/car/CarAppFocusManager.java @@ -18,7 +18,6 @@ package android.car; import android.os.Handler; import android.os.IBinder; -import android.os.Looper; import android.os.RemoteException; import java.lang.ref.WeakReference; @@ -37,20 +36,20 @@ public final class CarAppFocusManager implements CarManagerBase { /** * Listener to get notification for app getting information on application type status changes. */ - public interface AppFocusChangeListener { + public interface OnAppFocusChangedListener { /** * Application focus has changed. Note that {@link CarAppFocusManager} instance * causing the change will not get this notification. * @param appType * @param active */ - void onAppFocusChange(int appType, boolean active); + void onAppFocusChanged(int appType, boolean active); } /** * Listener to get notification for app getting information on app type ownership loss. */ - public interface AppFocusOwnershipChangeListener { + public interface OnAppFocusOwnershipLostListener { /** * Lost ownership for the focus, which happens when other app has set the focus. * The app losing focus should stop the action associated with the focus. @@ -58,7 +57,7 @@ public final class CarAppFocusManager implements CarManagerBase { * upon getting this for {@link CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION}. * @param appType */ - void onAppFocusOwnershipLoss(int appType); + void onAppFocusOwnershipLost(int appType); } /** @@ -86,9 +85,9 @@ public final class CarAppFocusManager implements CarManagerBase { private final IAppFocus mService; private final Handler mHandler; - private final Map<AppFocusChangeListener, IAppFocusListenerImpl> mChangeBinders = + private final Map<OnAppFocusChangedListener, IAppFocusListenerImpl> mChangeBinders = new HashMap<>(); - private final Map<AppFocusOwnershipChangeListener, IAppFocusOwnershipListenerImpl> + private final Map<OnAppFocusOwnershipLostListener, IAppFocusOwnershipListenerImpl> mOwnershipBinders = new HashMap<>(); /** @@ -102,10 +101,10 @@ public final class CarAppFocusManager implements CarManagerBase { /** * Register listener to monitor app focus change. * @param listener - * @param appType Applitcaion type to get notification for. - * @throws CarNotConnectedException + * @param appType Application type to get notification for. + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void registerFocusListener(AppFocusChangeListener listener, int appType) + public void addFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException { if (listener == null) { throw new IllegalArgumentException("null listener"); @@ -130,9 +129,9 @@ public final class CarAppFocusManager implements CarManagerBase { * Unregister listener for application type and stop listening focus change events. * @param listener * @param appType - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void unregisterFocusListener(AppFocusChangeListener listener, int appType) + public void removeFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException { IAppFocusListenerImpl binder; synchronized (this) { @@ -158,9 +157,9 @@ public final class CarAppFocusManager implements CarManagerBase { /** * Unregister listener and stop listening focus change events. * @param listener - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void unregisterFocusListener(AppFocusChangeListener listener) + public void removeFocusListener(OnAppFocusChangedListener listener) throws CarNotConnectedException { IAppFocusListenerImpl binder; synchronized (this) { @@ -180,7 +179,7 @@ public final class CarAppFocusManager implements CarManagerBase { /** * Returns application types currently active in the system. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @hide */ public int[] getActiveAppTypes() throws CarNotConnectedException { @@ -195,9 +194,9 @@ public final class CarAppFocusManager implements CarManagerBase { * Checks if listener is associated with active a focus * @param listener * @param appType - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public boolean isOwningFocus(AppFocusOwnershipChangeListener listener, int appType) + public boolean isOwningFocus(OnAppFocusOwnershipLostListener listener, int appType) throws CarNotConnectedException { IAppFocusOwnershipListenerImpl binder; synchronized (this) { @@ -216,16 +215,16 @@ public final class CarAppFocusManager implements CarManagerBase { /** * Requests application focus. * By requesting this, the application is becoming owner of the focus, and will get - * {@link AppFocusOwnershipChangeListener#onAppFocusOwnershipLoss(int)} + * {@link OnAppFocusOwnershipLostListener#onAppFocusOwnershipLost(int)} * if ownership is given to other app by calling this. Fore-ground app will have higher priority * and other app cannot set the same focus while owner is in fore-ground. * @param appType * @param ownershipListener * @return {@link #APP_FOCUS_REQUEST_FAILED} or {@link #APP_FOCUS_REQUEST_GRANTED} - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @throws SecurityException If owner cannot be changed. */ - public int requestAppFocus(int appType, AppFocusOwnershipChangeListener ownershipListener) + public int requestAppFocus(int appType, OnAppFocusOwnershipLostListener ownershipListener) throws SecurityException, CarNotConnectedException { if (ownershipListener == null) { throw new IllegalArgumentException("null listener"); @@ -251,9 +250,9 @@ public final class CarAppFocusManager implements CarManagerBase { * for the focus. * @param ownershipListener * @param appType - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener, int appType) + public void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener, int appType) throws CarNotConnectedException { if (ownershipListener == null) { throw new IllegalArgumentException("null listener"); @@ -282,9 +281,9 @@ public final class CarAppFocusManager implements CarManagerBase { * Abandon all focuses, i.e. mark them as inactive. This also involves releasing ownership * for the focus. * @param ownershipListener - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener) + public void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener) throws CarNotConnectedException { IAppFocusOwnershipListenerImpl binder; synchronized (this) { @@ -311,10 +310,10 @@ public final class CarAppFocusManager implements CarManagerBase { private static class IAppFocusListenerImpl extends IAppFocusListener.Stub { private final WeakReference<CarAppFocusManager> mManager; - private final WeakReference<AppFocusChangeListener> mListener; + private final WeakReference<OnAppFocusChangedListener> mListener; private final Set<Integer> mAppTypes = new HashSet<>(); - private IAppFocusListenerImpl(CarAppFocusManager manager, AppFocusChangeListener listener) { + private IAppFocusListenerImpl(CarAppFocusManager manager, OnAppFocusChangedListener listener) { mManager = new WeakReference<>(manager); mListener = new WeakReference<>(listener); } @@ -336,16 +335,16 @@ public final class CarAppFocusManager implements CarManagerBase { } @Override - public void onAppFocusChange(final int appType, final boolean active) { + public void onAppFocusChanged(final int appType, final boolean active) { final CarAppFocusManager manager = mManager.get(); - final AppFocusChangeListener listener = mListener.get(); + final OnAppFocusChangedListener listener = mListener.get(); if (manager == null || listener == null) { return; } manager.mHandler.post(new Runnable() { @Override public void run() { - listener.onAppFocusChange(appType, active); + listener.onAppFocusChanged(appType, active); } }); } @@ -354,11 +353,11 @@ public final class CarAppFocusManager implements CarManagerBase { private static class IAppFocusOwnershipListenerImpl extends IAppFocusOwnershipListener.Stub { private final WeakReference<CarAppFocusManager> mManager; - private final WeakReference<AppFocusOwnershipChangeListener> mListener; + private final WeakReference<OnAppFocusOwnershipLostListener> mListener; private final Set<Integer> mAppTypes = new HashSet<>(); private IAppFocusOwnershipListenerImpl(CarAppFocusManager manager, - AppFocusOwnershipChangeListener listener) { + OnAppFocusOwnershipLostListener listener) { mManager = new WeakReference<>(manager); mListener = new WeakReference<>(listener); } @@ -380,16 +379,16 @@ public final class CarAppFocusManager implements CarManagerBase { } @Override - public void onAppFocusOwnershipLoss(final int appType) { + public void onAppFocusOwnershipLost(final int appType) { final CarAppFocusManager manager = mManager.get(); - final AppFocusOwnershipChangeListener listener = mListener.get(); + final OnAppFocusOwnershipLostListener listener = mListener.get(); if (manager == null || listener == null) { return; } manager.mHandler.post(new Runnable() { @Override public void run() { - listener.onAppFocusOwnershipLoss(appType); + listener.onAppFocusOwnershipLost(appType); } }); } diff --git a/car-lib/src/android/car/CarInfoManager.java b/car-lib/src/android/car/CarInfoManager.java index e9f7c7b76c..45cf506172 100644 --- a/car-lib/src/android/car/CarInfoManager.java +++ b/car-lib/src/android/car/CarInfoManager.java @@ -77,7 +77,7 @@ public class CarInfoManager implements CarManagerBase { * Retrieve floating point information for car. * @param key * @return null if the key is not supported. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @throws IllegalArgumentException */ public float getFloat(String key) throws CarNotConnectedException, IllegalArgumentException { @@ -139,7 +139,7 @@ public class CarInfoManager implements CarManagerBase { * getInt / getString, but this is for passing more complex data. * @param key * @return - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @throws IllegalArgumentException * @hide */ diff --git a/car-lib/src/android/car/CarNotSupportedException.java b/car-lib/src/android/car/CarOperationNotSupportedException.java index 10deaef505..3fca5a5b1b 100644 --- a/car-lib/src/android/car/CarNotSupportedException.java +++ b/car-lib/src/android/car/CarOperationNotSupportedException.java @@ -20,21 +20,21 @@ package android.car; /** * Exception thrown when car is not supporting the requested operation. */ -public class CarNotSupportedException extends Exception { +public class CarOperationNotSupportedException extends Exception { private static final long serialVersionUID = -8120487541467522808L; - public CarNotSupportedException() { + public CarOperationNotSupportedException() { } - public CarNotSupportedException(String name) { + public CarOperationNotSupportedException(String name) { super(name); } - public CarNotSupportedException(String name, Throwable cause) { + public CarOperationNotSupportedException(String name, Throwable cause) { super(name, cause); } - public CarNotSupportedException(Exception cause) { + public CarOperationNotSupportedException(Exception cause) { super(cause); } } diff --git a/car-lib/src/android/car/CarProjectionManager.java b/car-lib/src/android/car/CarProjectionManager.java index bdc6eec2e6..dd0316ddc3 100644 --- a/car-lib/src/android/car/CarProjectionManager.java +++ b/car-lib/src/android/car/CarProjectionManager.java @@ -20,7 +20,6 @@ import android.annotation.SystemApi; import android.content.Intent; import android.os.Handler; import android.os.IBinder; -import android.os.Looper; import android.os.RemoteException; import java.lang.ref.WeakReference; @@ -55,7 +54,7 @@ public class CarProjectionManager implements CarManagerBase { private final ICarProjection mService; private final Handler mHandler; - private final ICarProjectionListenerImpl mBinderListener; + private final ICarProjectionCallbackImpl mBinderListener; private CarProjectionListener mListener; private int mVoiceSearchFilter; @@ -66,7 +65,7 @@ public class CarProjectionManager implements CarManagerBase { CarProjectionManager(IBinder service, Handler handler) { mService = ICarProjection.Stub.asInterface(service); mHandler = handler; - mBinderListener = new ICarProjectionListenerImpl(this); + mBinderListener = new ICarProjectionCallbackImpl(this); } /** @@ -74,7 +73,7 @@ public class CarProjectionManager implements CarManagerBase { * 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 + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public void regsiterProjectionListener(CarProjectionListener listener, int voiceSearchFilter) throws CarNotConnectedException { @@ -96,7 +95,7 @@ public class CarProjectionManager implements CarManagerBase { /** * Unregister listener and stop listening projection events. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public void unregsiterProjectionListener() throws CarNotConnectedException { synchronized (this) { @@ -114,7 +113,7 @@ public class CarProjectionManager implements CarManagerBase { * Registers projection runner on projection start with projection service * to create reverse binding. * @param serviceIntent - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public void registerProjectionRunner(Intent serviceIntent) throws CarNotConnectedException { if (serviceIntent == null) { @@ -133,7 +132,7 @@ public class CarProjectionManager implements CarManagerBase { * Unregisters projection runner on projection stop with projection service to create * reverse binding. * @param serviceIntent - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public void unregisterProjectionRunner(Intent serviceIntent) throws CarNotConnectedException { if (serviceIntent == null) { @@ -164,11 +163,11 @@ public class CarProjectionManager implements CarManagerBase { listener.onVoiceAssistantRequest(fromLongPress); } - private static class ICarProjectionListenerImpl extends ICarProjectionListener.Stub { + private static class ICarProjectionCallbackImpl extends ICarProjectionCallback.Stub { private final WeakReference<CarProjectionManager> mManager; - private ICarProjectionListenerImpl(CarProjectionManager manager) { + private ICarProjectionCallbackImpl(CarProjectionManager manager) { mManager = new WeakReference<>(manager); } diff --git a/car-lib/src/android/car/IAppFocus.aidl b/car-lib/src/android/car/IAppFocus.aidl index 1888c246ec..80ebb2f015 100644 --- a/car-lib/src/android/car/IAppFocus.aidl +++ b/car-lib/src/android/car/IAppFocus.aidl @@ -21,13 +21,13 @@ import android.car.IAppFocusOwnershipListener; /** @hide */ interface IAppFocus { - void registerFocusListener(IAppFocusListener listener, int appType) = 0; - void unregisterFocusListener(IAppFocusListener listener, int appType) = 1; + void registerFocusListener(IAppFocusListener callback, int appType) = 0; + void unregisterFocusListener(IAppFocusListener callback, int appType) = 1; int[] getActiveAppTypes() = 2; - /** listener used as a token */ - boolean isOwningFocus(IAppFocusOwnershipListener listener, int appType) = 3; - /** listener used as a token */ - int requestAppFocus(IAppFocusOwnershipListener listener, int appType) = 4; - /** listener used as a token */ - void abandonAppFocus(IAppFocusOwnershipListener listener, int appType) = 5; + /** callback used as a token */ + boolean isOwningFocus(IAppFocusOwnershipListener callback, int appType) = 3; + /** callback used as a token */ + int requestAppFocus(IAppFocusOwnershipListener callback, int appType) = 4; + /** callback used as a token */ + void abandonAppFocus(IAppFocusOwnershipListener callback, int appType) = 5; } diff --git a/car-lib/src/android/car/IAppFocusListener.aidl b/car-lib/src/android/car/IAppFocusListener.aidl index b8db6ff025..c3a310ac36 100644 --- a/car-lib/src/android/car/IAppFocusListener.aidl +++ b/car-lib/src/android/car/IAppFocusListener.aidl @@ -18,5 +18,5 @@ package android.car; /** @hide */ oneway interface IAppFocusListener { - void onAppFocusChange(int appType, boolean active) = 0; + void onAppFocusChanged(int appType, boolean active) = 0; } diff --git a/car-lib/src/android/car/IAppFocusOwnershipListener.aidl b/car-lib/src/android/car/IAppFocusOwnershipListener.aidl index 6ee27232fe..0742096ca2 100644 --- a/car-lib/src/android/car/IAppFocusOwnershipListener.aidl +++ b/car-lib/src/android/car/IAppFocusOwnershipListener.aidl @@ -18,5 +18,5 @@ package android.car; /** @hide */ oneway interface IAppFocusOwnershipListener { - void onAppFocusOwnershipLoss(int appType) = 0; + void onAppFocusOwnershipLost(int appType) = 0; } diff --git a/car-lib/src/android/car/ICarProjection.aidl b/car-lib/src/android/car/ICarProjection.aidl index 44b347c30d..96eb2a9c30 100644 --- a/car-lib/src/android/car/ICarProjection.aidl +++ b/car-lib/src/android/car/ICarProjection.aidl @@ -16,7 +16,7 @@ package android.car; -import android.car.ICarProjectionListener; +import android.car.ICarProjectionCallback; import android.content.Intent; /** @@ -39,13 +39,13 @@ interface ICarProjection { void unregisterProjectionRunner(in Intent serviceIntent) = 1; /** - * Registers projection listener. - * Re-registering same listener with different filter will cause only filter to update. + * Registers projection callback. + * Re-registering same callback with different filter will cause only filter to update. */ - void regsiterProjectionListener(ICarProjectionListener listener, int filter) = 2; + void regsiterProjectionListener(ICarProjectionCallback callback, int filter) = 2; /** - * Unregisters projection listener. + * Unregisters projection callback. */ - void unregsiterProjectionListener(ICarProjectionListener listener) = 3; + void unregsiterProjectionListener(ICarProjectionCallback callback) = 3; } diff --git a/car-lib/src/android/car/ICarProjectionListener.aidl b/car-lib/src/android/car/ICarProjectionCallback.aidl index aef281f82a..1c0ddedf3c 100644 --- a/car-lib/src/android/car/ICarProjectionListener.aidl +++ b/car-lib/src/android/car/ICarProjectionCallback.aidl @@ -19,6 +19,6 @@ package android.car; /** * @hide */ -oneway interface ICarProjectionListener { +oneway interface ICarProjectionCallback { void onVoiceAssistantRequest(boolean fromLongPress) = 0; } diff --git a/car-lib/src/android/car/hardware/CarSensorEvent.java b/car-lib/src/android/car/hardware/CarSensorEvent.java index d99e84d9f9..24dcf0dd75 100644 --- a/car-lib/src/android/car/hardware/CarSensorEvent.java +++ b/car-lib/src/android/car/hardware/CarSensorEvent.java @@ -128,7 +128,7 @@ public class CarSensorEvent implements Parcelable { * When this data was acquired in car or received from car. It is elapsed real-time of data * reception from car in nanoseconds since system boot. */ - public long timeStampNs; + public long timestamp; /** * array holding float type of sensor data. If the sensor has single value, only floatValues[0] * should be used. */ @@ -138,7 +138,7 @@ public class CarSensorEvent implements Parcelable { public CarSensorEvent(Parcel in) { sensorType = in.readInt(); - timeStampNs = in.readLong(); + timestamp = in.readLong(); int len = in.readInt(); floatValues = new float[len]; in.readFloatArray(floatValues); @@ -156,7 +156,7 @@ public class CarSensorEvent implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(sensorType); - dest.writeLong(timeStampNs); + dest.writeLong(timestamp); dest.writeInt(floatValues.length); dest.writeFloatArray(floatValues); dest.writeInt(intValues.length); @@ -174,17 +174,17 @@ public class CarSensorEvent implements Parcelable { } }; - public CarSensorEvent(int sensorType, long timeStampNs, int floatValueSize, int intValueSize) { + public CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize) { this.sensorType = sensorType; - this.timeStampNs = timeStampNs; + this.timestamp = timestamp; floatValues = new float[floatValueSize]; intValues = new int[intValueSize]; } /** @hide */ - CarSensorEvent(int sensorType, long timeStampNs, float[] floatValues, int[] intValues) { + CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues) { this.sensorType = sensorType; - this.timeStampNs = timeStampNs; + this.timestamp = timestamp; this.floatValues = floatValues; this.intValues = intValues; } @@ -198,7 +198,7 @@ public class CarSensorEvent implements Parcelable { } public static class EnvironmentData { - public long timeStampNs; + public long timestamp; /** If unsupported by the car, this value is NaN. */ public float temperature; /** If unsupported by the car, this value is NaN. */ @@ -218,14 +218,14 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new EnvironmentData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.temperature = floatValues[INDEX_ENVIRONMENT_TEMPERATURE]; data.pressure = floatValues[INDEX_ENVIRONMENT_PRESSURE]; return data; } public static class NightData { - public long timeStampNs; + public long timestamp; public boolean isNightMode; } @@ -242,13 +242,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new NightData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.isNightMode = intValues[0] == 1; return data; } public static class GearData { - public long timeStampNs; + public long timestamp; public int gear; } @@ -265,13 +265,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new GearData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.gear = intValues[0]; return data; } public static class ParkingBrakeData { - public long timeStampNs; + public long timestamp; public boolean isEngaged; } @@ -288,13 +288,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new ParkingBrakeData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.isEngaged = intValues[0] == 1; return data; } public static class FuelLevelData { - public long timeStampNs; + public long timestamp; /** Fuel level in %. If unsupported by the car, this value is -1. */ public int level; /** Fuel as possible range in Km. If unsupported by the car, this value is -1. */ @@ -316,7 +316,7 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new FuelLevelData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; if (floatValues == null) { data.level = -1; data.range = -1; @@ -337,7 +337,7 @@ public class CarSensorEvent implements Parcelable { } public static class OdometerData { - public long timeStampNs; + public long timestamp; public float kms; } @@ -354,13 +354,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new OdometerData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.kms = floatValues[0]; return data; } public static class RpmData { - public long timeStampNs; + public long timestamp; public float rpm; } @@ -377,13 +377,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new RpmData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.rpm = floatValues[0]; return data; } public static class CarSpeedData { - public long timeStampNs; + public long timestamp; public float carSpeed; } @@ -400,13 +400,13 @@ public class CarSensorEvent implements Parcelable { if (data == null) { data = new CarSpeedData(); } - data.timeStampNs = timeStampNs; + data.timestamp = timestamp; data.carSpeed = floatValues[0]; return data; } public static class DrivingStatusData { - public long timeStampNs; + public long timestamp; public int status; } diff --git a/car-lib/src/android/car/hardware/CarSensorManager.java b/car-lib/src/android/car/hardware/CarSensorManager.java index 49eede1e87..871530cc73 100644 --- a/car-lib/src/android/car/hardware/CarSensorManager.java +++ b/car-lib/src/android/car/hardware/CarSensorManager.java @@ -27,7 +27,6 @@ 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.util.Log; @@ -73,7 +72,7 @@ public class CarSensorManager implements CarManagerBase { /** * Represents the current status of parking brake. Sensor data in {@link CarSensorEvent} is an * intValues[0]. Value of 1 represents parking brake applied while 0 means the other way - * around. For this sensor, rate in {@link #registerListener(CarSensorEventListener, int, int)} + * around. For this sensor, rate in {@link #registerListener(OnSensorChangedListener, int, int)} * will be ignored and all changes will be notified. */ public static final int SENSOR_TYPE_PARKING_BRAKE = 6; @@ -203,7 +202,7 @@ public class CarSensorManager implements CarManagerBase { /** * Give the list of CarSensors available in the connected car. * @return array of all sensor types supported. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public int[] getSupportedSensors() throws CarNotConnectedException { try { @@ -220,7 +219,7 @@ public class CarSensorManager implements CarManagerBase { * Tells if given sensor is supported or not. * @param sensorType * @return true if the sensor is supported. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public boolean isSensorSupported(int sensorType) throws CarNotConnectedException { int[] sensors = getSupportedSensors(); @@ -251,7 +250,7 @@ public class CarSensorManager implements CarManagerBase { * Listener for car sensor data change. * Callbacks are called in the Looper context. */ - public interface CarSensorEventListener { + public interface OnSensorChangedListener { /** * Called when there is a new sensor data from car. * @param event Incoming sensor event for the given sensor type. @@ -260,7 +259,7 @@ public class CarSensorManager implements CarManagerBase { } /** - * Register {@link CarSensorEventListener} to get repeated sensor updates. Multiple listeners + * Register {@link OnSensorChangedListener} to get repeated sensor updates. Multiple listeners * can be registered for a single sensor or the same listener can be used for different sensors. * If the same listener is registered again for the same sensor, it will be either ignored or * updated depending on the rate. @@ -276,13 +275,13 @@ public class CarSensorManager implements CarManagerBase { * especially when the same sensor is registered with different listener with different * rates. * @return if the sensor was successfully enabled. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @throws IllegalArgumentException for wrong argument like wrong rate * @throws SecurityException if missing the appropriate permission */ @RequiresPermission(anyOf={Manifest.permission.ACCESS_FINE_LOCATION, Car.PERMISSION_SPEED, Car.PERMISSION_MILEAGE, Car.PERMISSION_FUEL}, conditional=true) - public boolean registerListener(CarSensorEventListener listener, int sensorType, int rate) + public boolean registerListener(OnSensorChangedListener listener, int sensorType, int rate) throws CarNotConnectedException, IllegalArgumentException { assertSensorType(sensorType); if (rate != SENSOR_RATE_FASTEST && rate != SENSOR_RATE_NORMAL) { @@ -316,9 +315,9 @@ public class CarSensorManager implements CarManagerBase { * 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 + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void unregisterListener(CarSensorEventListener listener) + public void unregisterListener(OnSensorChangedListener listener) throws CarNotConnectedException { //TODO: removing listener should reset update rate synchronized(mActiveSensorListeners) { @@ -335,16 +334,16 @@ public class CarSensorManager implements CarManagerBase { * for other sensors, those subscriptions will not be affected. * @param listener * @param sensorType - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public void unregisterListener(CarSensorEventListener listener, int sensorType) + public void unregisterListener(OnSensorChangedListener listener, int sensorType) throws CarNotConnectedException { synchronized(mActiveSensorListeners) { doUnregisterListenerLocked(listener, sensorType, null); } } - private void doUnregisterListenerLocked(CarSensorEventListener listener, Integer sensor, + private void doUnregisterListenerLocked(OnSensorChangedListener listener, Integer sensor, Iterator<Integer> sensorIterator) throws CarNotConnectedException { CarSensorListeners listeners = mActiveSensorListeners.get(sensor); if (listeners != null) { @@ -388,7 +387,7 @@ public class CarSensorManager implements CarManagerBase { * with null if there is no data available. * @param type A sensor to request * @return null if there was no sensor update since connected to the car. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public CarSensorEvent getLatestSensorEvent(int type) throws CarNotConnectedException { assertSensorType(type); @@ -442,8 +441,8 @@ public class CarSensorManager implements CarManagerBase { * Represent listeners for a sensor. */ private class CarSensorListeners { - private final LinkedList<CarSensorEventListener> mListeners = - new LinkedList<CarSensorEventListener>(); + private final LinkedList<OnSensorChangedListener> mListeners = + new LinkedList<OnSensorChangedListener>(); private int mUpdateRate; private long mLastUpdateTime = -1; @@ -452,11 +451,11 @@ public class CarSensorManager implements CarManagerBase { mUpdateRate = rate; } - boolean contains(CarSensorEventListener listener) { + boolean contains(OnSensorChangedListener listener) { return mListeners.contains(listener); } - void remove(CarSensorEventListener listener) { + void remove(OnSensorChangedListener listener) { mListeners.remove(listener); } @@ -470,7 +469,7 @@ public class CarSensorManager implements CarManagerBase { * @param updateRate * @return true if rate was updated. Otherwise, returns false. */ - boolean addAndUpdateRate(CarSensorEventListener listener, int updateRate) { + boolean addAndUpdateRate(OnSensorChangedListener listener, int updateRate) { if (!mListeners.contains(listener)) { mListeners.add(listener); } @@ -483,13 +482,13 @@ public class CarSensorManager implements CarManagerBase { void onSensorChanged(CarSensorEvent event) { // throw away old sensor data as oneway binder call can change order. - long updateTime = event.timeStampNs; + long updateTime = event.timestamp; if (updateTime < mLastUpdateTime) { Log.w(CarLibLog.TAG_SENSOR, "dropping old sensor data"); return; } mLastUpdateTime = updateTime; - for (CarSensorEventListener listener: mListeners) { + for (OnSensorChangedListener listener: mListeners) { listener.onSensorChanged(event); } } diff --git a/car-lib/src/android/car/hardware/CarVendorExtensionManager.java b/car-lib/src/android/car/hardware/CarVendorExtensionManager.java index 2c5ea0e5bc..7ae769edce 100644 --- a/car-lib/src/android/car/hardware/CarVendorExtensionManager.java +++ b/car-lib/src/android/car/hardware/CarVendorExtensionManager.java @@ -130,7 +130,7 @@ public class CarVendorExtensionManager implements CarManagerBase { * {@code Integer.class}. * @param propId - property id which is matched with the one defined in vehicle HAL * - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public <E> E getGlobalProperty(Class<E> propertyClass, int propId) throws CarNotConnectedException { @@ -147,7 +147,7 @@ public class CarVendorExtensionManager implements CarManagerBase { * @param area - vehicle area (e.g. {@code VEHICLE_ZONE_ROW_1_LEFT} * or {@code VEHICLE_MIRROR_DRIVER_LEFT} * - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public <E> E getProperty(Class<E> propertyClass, int propId, int area) throws CarNotConnectedException { @@ -164,7 +164,7 @@ public class CarVendorExtensionManager implements CarManagerBase { * @param value - new value, this object should match a class provided in {@code propertyClass} * argument. * - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public <E> void setGlobalProperty(Class<E> propertyClass, int propId, E value) throws CarNotConnectedException { @@ -183,7 +183,7 @@ public class CarVendorExtensionManager implements CarManagerBase { * @param value - new value, this object should match a class provided in {@code propertyClass} * argument. * - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public <E> void setProperty(Class<E> propertyClass, int propId, int area, E value) throws CarNotConnectedException { diff --git a/car-lib/src/android/car/hardware/ICarSensor.aidl b/car-lib/src/android/car/hardware/ICarSensor.aidl index c490531117..6f9e3153fc 100644 --- a/car-lib/src/android/car/hardware/ICarSensor.aidl +++ b/car-lib/src/android/car/hardware/ICarSensor.aidl @@ -25,13 +25,13 @@ interface ICarSensor { int[] getSupportedSensors() = 0; /** - * register a listener or update registration if already updated. - * @param sensorType sensor to listen with this listener. + * register a callback or update registration if already updated. + * @param sensorType sensor to listen with this callback. * @param rate sensor rate. * @return false if requested sensors cannot be subscribed / started. */ boolean registerOrUpdateSensorListener(int sensorType, int rate, - in ICarSensorEventListener listener) = 1; + in ICarSensorEventListener callback) = 1; /** * get latest sensor event for the type. If there was no update after car connection, it will @@ -43,5 +43,5 @@ interface ICarSensor { * Stop listening for the given sensor type. All other sensors registered before will not * be affected. */ - void unregisterSensorListener(int sensorType, in ICarSensorEventListener listener) = 3; + void unregisterSensorListener(int sensorType, in ICarSensorEventListener callback) = 3; } diff --git a/car-lib/src/android/car/hardware/ICarSensorEventListener.aidl b/car-lib/src/android/car/hardware/ICarSensorEventListener.aidl index fc5b07f097..59b7eb4e30 100644 --- a/car-lib/src/android/car/hardware/ICarSensorEventListener.aidl +++ b/car-lib/src/android/car/hardware/ICarSensorEventListener.aidl @@ -19,7 +19,7 @@ package android.car.hardware; import android.car.hardware.CarSensorEvent; /** - * Binder callback for CarSensorEventListener. + * Binder callback for OnSensorChangedListener. * This is generated per each CarClient. * @hide */ diff --git a/car-lib/src/android/car/hardware/camera/CarCameraManager.java b/car-lib/src/android/car/hardware/camera/CarCameraManager.java index fd06e5968e..e097d0fea2 100644 --- a/car-lib/src/android/car/hardware/camera/CarCameraManager.java +++ b/car-lib/src/android/car/hardware/camera/CarCameraManager.java @@ -75,7 +75,7 @@ public class CarCameraManager implements CarManagerBase { * * @param cameraType Camera type to query capabilites * @return Bitmask of camera capabilities available for this device - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public int getCameraCapabilities(int cameraType) throws CarNotConnectedException { int capabilities; diff --git a/car-lib/src/android/car/hardware/property/ICarProperty.aidl b/car-lib/src/android/car/hardware/property/ICarProperty.aidl index da0065f0c1..2121ebb96b 100644 --- a/car-lib/src/android/car/hardware/property/ICarProperty.aidl +++ b/car-lib/src/android/car/hardware/property/ICarProperty.aidl @@ -25,9 +25,9 @@ import android.car.hardware.property.ICarPropertyEventListener; */ interface ICarProperty { - void registerListener(in ICarPropertyEventListener listener) = 0; + void registerListener(in ICarPropertyEventListener callback) = 0; - void unregisterListener(in ICarPropertyEventListener listener) = 1; + void unregisterListener(in ICarPropertyEventListener callback) = 1; List<CarPropertyConfig> getPropertyList() = 2; diff --git a/car-lib/src/android/car/hardware/radio/ICarRadio.aidl b/car-lib/src/android/car/hardware/radio/ICarRadio.aidl index 2de94765d1..4afa211910 100644 --- a/car-lib/src/android/car/hardware/radio/ICarRadio.aidl +++ b/car-lib/src/android/car/hardware/radio/ICarRadio.aidl @@ -29,12 +29,12 @@ interface ICarRadio { /** * Registers the client for updates to radio changes. */ - void registerListener(in ICarRadioEventListener listener) = 1; + void registerListener(in ICarRadioEventListener callback) = 1; /** * Unregisters the client for updates to radio changes. */ - void unregisterListener(in ICarRadioEventListener listener) = 2; + void unregisterListener(in ICarRadioEventListener callback) = 2; /** * Gets the preset values stored for a particular preset number. diff --git a/car-lib/src/android/car/media/CarAudioManager.java b/car-lib/src/android/car/media/CarAudioManager.java index 2d205620a6..620c93f3f8 100644 --- a/car-lib/src/android/car/media/CarAudioManager.java +++ b/car-lib/src/android/car/media/CarAudioManager.java @@ -334,7 +334,7 @@ public class CarAudioManager implements CarManagerBase { * taking audio focus for media stream will get it out of mute state. * * @return true if media is muted. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @hide */ @SystemApi @@ -356,7 +356,7 @@ public class CarAudioManager implements CarManagerBase { * @param mute * @return Mute state of system after the request. Note that mute request can fail if there * is higher priority audio already being played like phone call. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @hide */ @SystemApi diff --git a/car-lib/src/android/car/navigation/CarNavigationManager.java b/car-lib/src/android/car/navigation/CarNavigationManager.java index d0d94d125e..1fee6a7fe9 100644 --- a/car-lib/src/android/car/navigation/CarNavigationManager.java +++ b/car-lib/src/android/car/navigation/CarNavigationManager.java @@ -108,7 +108,7 @@ public class CarNavigationManager implements CarManagerBase { /** * @param status new instrument cluster navigation status. * @return true if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public boolean sendNavigationStatus(int status) throws CarNotConnectedException { try { @@ -148,7 +148,7 @@ public class CarNavigationManager implements CarManagerBase { * @param turnSide turn side ({@link #TURN_SIDE_LEFT}, {@link #TURN_SIDE_RIGHT} or * {@link #TURN_SIDE_UNSPECIFIED}). * @return true if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * */ public boolean sendNavigationTurnEvent(int event, String road, int turnAngle, int turnNumber, @@ -176,7 +176,7 @@ public class CarNavigationManager implements CarManagerBase { * @param displayDistanceUnit units for {@param displayDistanceMillis} param. * See {@link DisplayDistanceUnit} for acceptable values. * @return true if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public boolean sendNavigationTurnDistanceEvent(int distanceMeters, int timeSeconds, int displayDistanceMillis, @DisplayDistanceUnit int displayDistanceUnit) diff --git a/car-lib/src/android/car/navigation/ICarNavigation.aidl b/car-lib/src/android/car/navigation/ICarNavigation.aidl index 0699850a53..9dc8278222 100644 --- a/car-lib/src/android/car/navigation/ICarNavigation.aidl +++ b/car-lib/src/android/car/navigation/ICarNavigation.aidl @@ -28,6 +28,6 @@ interface ICarNavigation { void sendNavigationTurnEvent( int event, String road, int turnAngle, int turnNumber, in Bitmap image, int turnSide); void sendNavigationTurnDistanceEvent(int distanceMeters, int timeSeconds); - boolean registerEventListener(ICarNavigationEventListener listener); - boolean unregisterEventListener(ICarNavigationEventListener listener); + boolean registerEventListener(ICarNavigationEventListener callback); + boolean unregisterEventListener(ICarNavigationEventListener callback); } diff --git a/car-lib/src/android/car/navigation/ICarNavigationEventListener.aidl b/car-lib/src/android/car/navigation/ICarNavigationEventListener.aidl index 10c14c876d..ff04b3680e 100644 --- a/car-lib/src/android/car/navigation/ICarNavigationEventListener.aidl +++ b/car-lib/src/android/car/navigation/ICarNavigationEventListener.aidl @@ -22,6 +22,6 @@ import android.car.navigation.CarNavigationInstrumentCluster; * @hide */ oneway interface ICarNavigationEventListener { - void onInstrumentClusterStart(in CarNavigationInstrumentCluster instrumentCluster) = 0; - void onInstrumentClusterStop() = 1; + void onInstrumentClusterStarted(in CarNavigationInstrumentCluster instrumentCluster) = 0; + void onInstrumentClusterStopped() = 1; } diff --git a/car-support-lib/api/current.txt b/car-support-lib/api/current.txt index 13f3d78dda..56da5f6948 100644 --- a/car-support-lib/api/current.txt +++ b/car-support-lib/api/current.txt @@ -5,8 +5,8 @@ package android.support.car { method public static android.support.car.Car createCar(android.content.Context, android.support.car.ServiceConnectionCallback, android.os.Handler); method public static android.support.car.Car createCar(android.content.Context, android.support.car.ServiceConnectionCallback); method public void disconnect(); - method public int getCarConnectionType() throws android.support.car.CarNotConnectedException; method public java.lang.Object getCarManager(java.lang.String) throws android.support.car.CarNotConnectedException; + method public T getCarManager(java.lang.Class<T>) throws android.support.car.CarNotConnectedException; method public boolean isConnected(); method public boolean isConnectedToCar(); method public boolean isConnecting(); @@ -32,30 +32,30 @@ package android.support.car { public abstract class CarAppFocusManager { ctor public CarAppFocusManager(); - method public abstract void abandonAppFocus(android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener, int) throws android.support.car.CarNotConnectedException; - method public abstract void abandonAppFocus(android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.support.car.CarNotConnectedException; - method public abstract void addFocusListener(int, android.support.car.CarAppFocusManager.AppFocusChangeListener) throws android.support.car.CarNotConnectedException; - method public abstract boolean isOwningFocus(int, android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.support.car.CarNotConnectedException; - method public abstract void removeFocusListener(int, android.support.car.CarAppFocusManager.AppFocusChangeListener) throws android.support.car.CarNotConnectedException; - method public abstract void removeFocusListener(android.support.car.CarAppFocusManager.AppFocusChangeListener) throws android.support.car.CarNotConnectedException; - method public abstract int requestAppFocus(int, android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener) throws android.support.car.CarNotConnectedException, java.lang.IllegalStateException, java.lang.SecurityException; + method public abstract void abandonAppFocus(android.support.car.CarAppFocusManager.OnAppFocusOwnershipLostListener, int) throws android.support.car.CarNotConnectedException; + method public abstract void abandonAppFocus(android.support.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.support.car.CarNotConnectedException; + method public abstract void addFocusListener(android.support.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.support.car.CarNotConnectedException; + method public abstract boolean isOwningFocus(int, android.support.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.support.car.CarNotConnectedException; + method public abstract void removeFocusListener(android.support.car.CarAppFocusManager.OnAppFocusChangedListener, int) throws android.support.car.CarNotConnectedException; + method public abstract void removeFocusListener(android.support.car.CarAppFocusManager.OnAppFocusChangedListener) throws android.support.car.CarNotConnectedException; + method public abstract int requestAppFocus(int, android.support.car.CarAppFocusManager.OnAppFocusOwnershipLostListener) throws android.support.car.CarNotConnectedException, java.lang.IllegalStateException, java.lang.SecurityException; field public static final int APP_FOCUS_REQUEST_FAILED = 0; // 0x0 field public static final int APP_FOCUS_REQUEST_GRANTED = 1; // 0x1 field public static final int APP_FOCUS_TYPE_NAVIGATION = 1; // 0x1 } - public static abstract interface CarAppFocusManager.AppFocusChangeListener { - method public abstract void onAppFocusChange(int, boolean); + public static abstract interface CarAppFocusManager.OnAppFocusChangedListener { + method public abstract void onAppFocusChanged(android.support.car.CarAppFocusManager, int, boolean); } - public static abstract interface CarAppFocusManager.AppFocusOwnershipChangeListener { - method public abstract void onAppFocusOwnershipLoss(int); + public static abstract interface CarAppFocusManager.OnAppFocusOwnershipLostListener { + method public abstract void onAppFocusOwnershipLost(android.support.car.CarAppFocusManager, int); } public abstract class CarConnectionCallback { ctor public CarConnectionCallback(); - method public abstract void onConnected(int); - method public abstract void onDisconnected(); + method public abstract void onConnected(android.support.car.Car, int); + method public abstract void onDisconnected(android.support.car.Car); } public abstract class CarInfoManager { @@ -85,19 +85,11 @@ package android.support.car { ctor public CarNotConnectedException(java.lang.Exception); } - public class CarNotSupportedException extends java.lang.Exception { - ctor public CarNotSupportedException(); - ctor public CarNotSupportedException(java.lang.String); - ctor public CarNotSupportedException(java.lang.String, java.lang.Throwable); - ctor public CarNotSupportedException(java.lang.Exception); - } - public abstract class ServiceConnectionCallback { ctor public ServiceConnectionCallback(); method public abstract void onServiceConnected(); - method public abstract void onServiceConnectionFailed(int); + method public abstract void onServiceConnectionFailed(); method public abstract void onServiceDisconnected(); - method public abstract void onServiceSuspended(int); } } @@ -137,12 +129,12 @@ package android.support.car.hardware { field public final float[] floatValues; field public final int[] intValues; field public final int sensorType; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.AccelerometerData { ctor public CarSensorEvent.AccelerometerData(long, float, float, float); - field public final long timeStampNs; + field public final long timestamp; field public final float x; field public final float y; field public final float z; @@ -153,7 +145,7 @@ package android.support.car.hardware { field public final float bearing; field public final float pitch; field public final float roll; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.DrivingStatusData { @@ -165,7 +157,7 @@ package android.support.car.hardware { method public boolean isVideoRestricted(); method public boolean isVoiceRestricted(); field public final int status; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.FuelLevelData { @@ -173,12 +165,12 @@ package android.support.car.hardware { field public final int level; field public final boolean lowFuelWarning; field public final float range; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.GyroscopeData { ctor public CarSensorEvent.GyroscopeData(long, float, float, float); - field public final long timeStampNs; + field public final long timestamp; field public final float x; field public final float y; field public final float z; @@ -187,40 +179,39 @@ package android.support.car.hardware { public static class CarSensorEvent.NightData { ctor public CarSensorEvent.NightData(long, boolean); field public final boolean isNightMode; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.ParkingBrakeData { ctor public CarSensorEvent.ParkingBrakeData(long, boolean); field public final boolean isEngaged; - field public final long timeStampNs; + field public final long timestamp; } public static class CarSensorEvent.RpmData { ctor public CarSensorEvent.RpmData(long, float); field public final float rpm; - field public final long timeStampNs; + field public final long timestamp; } public abstract class CarSensorManager { ctor public CarSensorManager(); - method public abstract boolean addListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener, int, int) throws android.support.car.CarNotConnectedException, java.lang.IllegalArgumentException; + method public abstract boolean addListener(android.support.car.hardware.CarSensorManager.OnSensorChangedListener, int, int) throws android.support.car.CarNotConnectedException, java.lang.IllegalArgumentException; method public abstract android.support.car.hardware.CarSensorEvent getLatestSensorEvent(int) throws android.support.car.CarNotConnectedException; method public abstract int[] getSupportedSensors() throws android.support.car.CarNotConnectedException; method public abstract boolean isSensorSupported(int) throws android.support.car.CarNotConnectedException; - method public abstract void removeListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener) throws android.support.car.CarNotConnectedException; - method public abstract void removeListener(android.support.car.hardware.CarSensorManager.CarSensorEventListener, int) throws android.support.car.CarNotConnectedException; + method public abstract void removeListener(android.support.car.hardware.CarSensorManager.OnSensorChangedListener) throws android.support.car.CarNotConnectedException; + method public abstract void removeListener(android.support.car.hardware.CarSensorManager.OnSensorChangedListener, int) throws android.support.car.CarNotConnectedException; field public static final int SENSOR_RATE_FASTEST = 0; // 0x0 field public static final int SENSOR_RATE_NORMAL = 3; // 0x3 field public static final int SENSOR_TYPE_COMPASS = 1; // 0x1 field public static final int SENSOR_TYPE_DRIVING_STATUS = 11; // 0xb field public static final int SENSOR_TYPE_NIGHT = 9; // 0x9 field public static final int SENSOR_TYPE_PARKING_BRAKE = 6; // 0x6 - field public static final int SENSOR_TYPE_VENDOR_EXTENSION_END = 1879048191; // 0x6fffffff } - public static abstract interface CarSensorManager.CarSensorEventListener { - method public abstract void onSensorChanged(android.support.car.hardware.CarSensorEvent); + public static abstract interface CarSensorManager.OnSensorChangedListener { + method public abstract void onSensorChanged(android.support.car.hardware.CarSensorManager, android.support.car.hardware.CarSensorEvent); } } @@ -230,11 +221,12 @@ package android.support.car.media { public abstract class CarAudioManager { ctor public CarAudioManager(); method public abstract int abandonAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, android.media.AudioAttributes); - method public abstract android.support.car.media.CarAudioRecord createCarAudioRecord(int) throws android.support.car.CarNotConnectedException, android.support.car.CarNotSupportedException, java.lang.SecurityException; + method public abstract android.support.car.media.CarAudioRecord createCarAudioRecord(int) throws android.support.car.CarNotConnectedException, java.lang.SecurityException; method public abstract android.media.AudioAttributes getAudioAttributesForCarUsage(int); method public abstract android.media.AudioFormat getAudioRecordAudioFormat(); - method public abstract int getAudioRecordMaxBufferSize() throws android.support.car.CarNotConnectedException, android.support.car.CarNotSupportedException; - method public abstract int getAudioRecordMinBufferSize() throws android.support.car.CarNotConnectedException, android.support.car.CarNotSupportedException; + method public abstract int getAudioRecordMaxBufferSize() throws android.support.car.CarNotConnectedException; + method public abstract int getAudioRecordMinBufferSize() throws android.support.car.CarNotConnectedException; + method public abstract boolean isAudioRecordSupported(); method public abstract boolean isMediaMuted() throws android.support.car.CarNotConnectedException; method public abstract int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, android.media.AudioAttributes, int) throws java.lang.IllegalArgumentException; field public static final int CAR_AUDIO_USAGE_ALARM = 6; // 0x6 @@ -281,7 +273,7 @@ package android.support.car.navigation { } public abstract interface CarNavigationStatusManager { - method public abstract void addListener(android.support.car.navigation.CarNavigationStatusManager.CarNavigationListener) throws android.support.car.CarNotConnectedException; + method public abstract void addListener(android.support.car.navigation.CarNavigationStatusManager.CarNavigationCallback) throws android.support.car.CarNotConnectedException; method public abstract void removeListener(); method public abstract boolean sendNavigationStatus(int) throws android.support.car.CarNotConnectedException; method public abstract boolean sendNavigationTurnDistanceEvent(int, int, int, int) throws android.support.car.CarNotConnectedException; @@ -319,9 +311,9 @@ package android.support.car.navigation { field public static final int TURN_U_TURN = 6; // 0x6 } - public static abstract interface CarNavigationStatusManager.CarNavigationListener { - method public abstract void onInstrumentClusterStart(android.support.car.navigation.CarNavigationInstrumentCluster); - method public abstract void onInstrumentClusterStop(); + public static abstract interface CarNavigationStatusManager.CarNavigationCallback { + method public abstract void onInstrumentClusterStarted(android.support.car.navigation.CarNavigationStatusManager, android.support.car.navigation.CarNavigationInstrumentCluster); + method public abstract void onInstrumentClusterStopped(android.support.car.navigation.CarNavigationStatusManager); } } diff --git a/car-support-lib/src/android/support/car/Car.java b/car-support-lib/src/android/support/car/Car.java index 37f1f49dae..28e8994ce7 100644 --- a/car-support-lib/src/android/support/car/Car.java +++ b/car-support-lib/src/android/support/car/Car.java @@ -16,7 +16,6 @@ package android.support.car; -import android.content.ComponentName; import android.content.Context; import android.os.Handler; import android.os.Looper; @@ -28,11 +27,16 @@ import android.support.car.content.pm.CarPackageManager; import android.support.car.hardware.CarSensorManager; import android.support.car.media.CarAudioManager; import android.support.car.navigation.CarNavigationStatusManager; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * Top-level car API that provides access to all car services and data available in the platform. @@ -75,6 +79,21 @@ public class Car { */ public static final String NAVIGATION_STATUS_SERVICE = "car_navigation_service"; + // TODO(jthol) move into a more robust registry implementation + private static final Map<Class, String> CLASS_TO_SERVICE_NAME; + static{ + Map<Class, String> mapping = new HashMap<>(); + mapping.put(CarSensorManager.class, SENSOR_SERVICE); + mapping.put(CarInfoManager.class, INFO_SERVICE); + mapping.put(CarAppFocusManager.class, APP_FOCUS_SERVICE); + mapping.put(CarPackageManager.class, PACKAGE_SERVICE); + mapping.put(CarAudioManager.class, AUDIO_SERVICE); + mapping.put(CarNavigationStatusManager.class, NAVIGATION_STATUS_SERVICE); + + CLASS_TO_SERVICE_NAME = Collections.unmodifiableMap(mapping); + } + + /** * Type of car connection: car emulator, no physical connection. */ @@ -100,14 +119,26 @@ public class Car { */ public static final int CONNECTION_TYPE_EMBEDDED = 5; /** - * Unknown type (the support lib is likely out-of-date). - */ - public static final int CONNECTION_TYPE_UNKNOWN = -1; - /** * Type of car connection: platform runs directly in car with mocked vehicle HAL. Occurs * only in a testing environment. */ public static final int CONNECTION_TYPE_EMBEDDED_MOCKING = 6; + /** + * Unknown type (the support lib is likely out-of-date). + */ + public static final int CONNECTION_TYPE_UNKNOWN = -1; + + private static final Set<Integer> CONNECTION_TYPES = new HashSet<>(); + static { + CONNECTION_TYPES.add(CONNECTION_TYPE_ADB_EMULATOR); + CONNECTION_TYPES.add(CONNECTION_TYPE_USB); + CONNECTION_TYPES.add(CONNECTION_TYPE_WIFI); + CONNECTION_TYPES.add(CONNECTION_TYPE_ON_DEVICE_EMULATOR); + CONNECTION_TYPES.add(CONNECTION_TYPE_ADB_EMULATOR); + CONNECTION_TYPES.add(CONNECTION_TYPE_EMBEDDED); + CONNECTION_TYPES.add(CONNECTION_TYPE_EMBEDDED_MOCKING); + } + /** @hide */ @IntDef({CONNECTION_TYPE_EMULATOR, CONNECTION_TYPE_USB, CONNECTION_TYPE_WIFI, @@ -155,6 +186,12 @@ public class Car { */ private static final String PROJECTED_CAR_SERVICE_LOADER = "com.google.android.gms.car.CarServiceLoaderGms"; + /** + * Permission necessary to change car audio volume through {@link CarAudioManager}. + * @hide + */ + public static final String PERMISSION_CAR_CONTROL_AUDIO_VOLUME = + "android.car.permission.CAR_CONTROL_AUDIO_VOLUME"; private final Context mContext; private final Handler mEventHandler; @@ -187,13 +224,8 @@ public class Car { } @Override - public void onServiceSuspended(int cause) { - mServiceConnectionCallbackClient.onServiceSuspended(cause); - } - - @Override - public void onServiceConnectionFailed(int cause) { - mServiceConnectionCallbackClient.onServiceConnectionFailed(cause); + public void onServiceConnectionFailed() { + mServiceConnectionCallbackClient.onServiceConnectionFailed(); } }; @@ -247,7 +279,7 @@ public class Car { if (mContext.getPackageManager().hasSystemFeature(FEATURE_AUTOMOTIVE)) { mCarServiceLoader = - new CarServiceLoaderEmbedded(context, mServiceConnectionCallback, + new CarServiceLoaderEmbedded(this, context, mServiceConnectionCallback, mEventHandler); } else { mCarServiceLoader = loadCarServiceLoader(PROJECTED_CAR_SERVICE_LOADER, context, @@ -337,7 +369,7 @@ public class Car { } /** - * @return Returns {@code true} if this object is connected to the service and {@code false} if + * @return Returns {@code true} if this object is connected to the service; {@code false} * otherwise. */ public boolean isConnected() { @@ -370,7 +402,7 @@ public class Car { * <pre>{@code CarSensorManager sensorManager = * (CarSensorManager) car.getCarManager(Car.SENSOR_SERVICE);}</pre> * - * @param serviceName Name of service to create, e.g. {@link #SENSOR_SERVICE}. + * @param serviceName Name of service to create, for example {@link #SENSOR_SERVICE}. * @return The requested service manager or null if the service is not available. */ public Object getCarManager(String serviceName) @@ -391,17 +423,40 @@ public class Car { } /** - * Return the type of currently connected car. + * Get a car-specific manager. This is modeled after {@link Context#getSystemService(Class)}. + * The returned service will be type cast to the desired manager. For example, + * to get the sensor service, use the following: + * <pre>{@code CarSensorManager sensorManager = car.getCarManager(CarSensorManager.class); + * }</pre> + * + * @param serviceClass Class: The class of the desired service. For + * example {@link CarSensorManager}. + * @return The service or null if the class is not a supported car service. + */ + public <T> T getCarManager(Class<T> serviceClass) throws CarNotConnectedException { + // TODO(jthol) port to a more robust registry implementation + String serviceName = CLASS_TO_SERVICE_NAME.get(serviceClass); + return (serviceName == null) ? null: (T) getCarManager(serviceName); + + } + + /** + * Return the type of currently connected car. This should only be used for testing scenarios * * @return One of {@link #CONNECTION_TYPE_USB}, {@link #CONNECTION_TYPE_WIFI}, * {@link #CONNECTION_TYPE_EMBEDDED}, {@link #CONNECTION_TYPE_ON_DEVICE_EMULATOR}, * {@link #CONNECTION_TYPE_ADB_EMULATOR}, {@link #CONNECTION_TYPE_EMBEDDED_MOCKING}, * {@link #CONNECTION_TYPE_UNKNOWN}. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. + * @hide */ @ConnectionType public int getCarConnectionType() throws CarNotConnectedException { - return mCarServiceLoader.getCarConnectionType(); + int carConnectionType = mCarServiceLoader.getCarConnectionType(); + if(!CONNECTION_TYPES.contains(carConnectionType)){ + return CONNECTION_TYPE_UNKNOWN; + } + return carConnectionType; } /** diff --git a/car-support-lib/src/android/support/car/CarApiUtil.java b/car-support-lib/src/android/support/car/CarApiUtil.java deleted file mode 100644 index 6f03f27ff9..0000000000 --- a/car-support-lib/src/android/support/car/CarApiUtil.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.support.car; - -/** - * Internal helper utilities - * @hide - */ -public class CarApiUtil { - - /** - * CarService throws IllegalStateException with this message is re-thrown as - * {@link CarNotConnectedException}. - * - * @hide - */ - public static final String CAR_NOT_CONNECTED_EXCEPTION_MSG = "CarNotConnected"; - - /** - * CarService throw IllegalStateException with this message is re-thrown as - * {@link CarNotSupportedException}. - * - * @hide - */ - public static final String CAR_NOT_SUPPORTED_EXCEPTION_MSG = "CarNotSupported"; - - /** - * IllegalStateException from CarService with special message is re-thrown as a different - * exception. - * - * @param e exception from CarService - * @throws CarNotConnectedException - * @throws CarNotSupportedException - * @hide - */ - public static void checkAllIllegalStateExceptionsFromCarService(IllegalStateException e) - throws CarNotConnectedException, CarNotSupportedException { - String message = e.getMessage(); - if (message.equals(CAR_NOT_CONNECTED_EXCEPTION_MSG)) { - throw new CarNotConnectedException(); - } else if (message.equals(CAR_NOT_SUPPORTED_EXCEPTION_MSG)) { - throw new CarNotSupportedException(); - } else { - throw e; - } - } - - /** - * Re-throw IllegalStateException from CarService with - * {@link #CAR_NOT_CONNECTED_EXCEPTION_MSG} message as {@link CarNotConnectedException}. - * exception. - * - * @param e exception from CarService - * @throws CarNotConnectedException - * @hide - */ - public static void checkCarNotConnectedExceptionFromCarService(IllegalStateException e) - throws CarNotConnectedException { - if (e.getMessage().equals(CAR_NOT_CONNECTED_EXCEPTION_MSG)) { - throw new CarNotConnectedException(); - } else { - throw e; - } - } - - /** do not use */ - private CarApiUtil() {}; -} diff --git a/car-support-lib/src/android/support/car/CarAppFocusManager.java b/car-support-lib/src/android/support/car/CarAppFocusManager.java index b9972af8fc..25cb5d7e28 100644 --- a/car-support-lib/src/android/support/car/CarAppFocusManager.java +++ b/car-support-lib/src/android/support/car/CarAppFocusManager.java @@ -26,28 +26,32 @@ public abstract class CarAppFocusManager implements CarManagerBase { /** * Receives notifications when app focus changes. */ - public interface AppFocusChangeListener { + public interface OnAppFocusChangedListener { /** * Indicates the application focus has changed. The {@link CarAppFocusManager} instance * causing the change does not get this notification. + * @param manager the {@link CarAppFocusManager} this listener is attached to. Useful if + * the app wished to unregister the listener. * @param appType application type for which status changed * @param active returns {@code true} if active */ - void onAppFocusChange(int appType, boolean active); + void onAppFocusChanged(CarAppFocusManager manager, int appType, boolean active); } /** * Receives notifications when the application has lost ownership. */ - public interface AppFocusOwnershipChangeListener { + public interface OnAppFocusOwnershipLostListener { /** * Lost ownership for the focus, which occurs when another app has set the focus. * The app losing focus should stop the action associated with the focus. * For example, a navigation app running active navigation should stop navigation * upon getting this for {@link CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION}. + * @param manager the {@link CarAppFocusManager} this listener is attached to. Useful if + * the app wished to unregister the listener. * @param appType */ - void onAppFocusOwnershipLoss(int appType); + void onAppFocusOwnershipLost(CarAppFocusManager manager, int appType); } /** @@ -78,28 +82,28 @@ public abstract class CarAppFocusManager implements CarManagerBase { * Register listener to monitor app focus changes. * Multiple listeners can be registered for a single focus and the same listener can be used * for multiple focuses. - * @param appType Application type to get notification for. * @param listener Listener to register for focus events. - * @throws CarNotConnectedException + * @param appType Application type to get notification for. + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract void addFocusListener(int appType, AppFocusChangeListener listener) + public abstract void addFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException; /** * Unregister listener for app type and stop listening to focus change events. - * @param appType Application type to get notification for. * @param listener Listener to unregister from focus events. - * @throws CarNotConnectedException + * @param appType Application type to get notification for. + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract void removeFocusListener(int appType, AppFocusChangeListener listener) + public abstract void removeFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException; /** * Unregister listener for all app types and stop listening to focus change events. * @param listener Listener to unregister from focus events. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract void removeFocusListener(AppFocusChangeListener listener) + public abstract void removeFocusListener(OnAppFocusChangedListener listener) throws CarNotConnectedException; /** @@ -107,16 +111,23 @@ public abstract class CarAppFocusManager implements CarManagerBase { * @param appType Application type. * @param listener Listener that was used to request ownership. * @return Returns {@code true} if current listener owns focus for application type. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract boolean isOwningFocus(int appType, AppFocusOwnershipChangeListener listener) + public abstract boolean isOwningFocus(int appType, OnAppFocusOwnershipLostListener listener) throws CarNotConnectedException; /** * Request application focus. By requesting this, the app gains the focus for this appType. - * {@link AppFocusOwnershipChangeListener#onAppFocusOwnershipLoss(int)} will be sent to the app + * {@link OnAppFocusOwnershipLostListener#onAppFocusOwnershipLost(CarAppFocusManager, int)} + * will be sent to + * the + * app * that currently holds focus. The foreground app will have higher priority; other apps cannot * set the same focus while owner is in foreground. + * <p> + * The listener provided here is the identifier for the focus. Apps need to pass it into + * other app focus methods such as {@link #isOwningFocus(int, OnAppFocusOwnershipLostListener)} + * or {@link #abandonAppFocus(OnAppFocusOwnershipLostListener)}. * * @param appType Application type to request focus for. * @param ownershipListener Ownership listener to request app focus for. Cannot be null. @@ -124,26 +135,26 @@ public abstract class CarAppFocusManager implements CarManagerBase { * @return {@link #APP_FOCUS_REQUEST_FAILED} or {@link #APP_FOCUS_REQUEST_GRANTED} * @throws IllegalStateException if listener was not registered. * @throws SecurityException if owner cannot be changed. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public abstract int requestAppFocus(int appType, - AppFocusOwnershipChangeListener ownershipListener) + OnAppFocusOwnershipLostListener ownershipListener) throws IllegalStateException, SecurityException, CarNotConnectedException; /** * Abandon the given focus (mark it as inactive). * @param ownershipListener Ownership listener to abandon app focus for. Cannot be null. * @param appType Application type to abandon focus for. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener, + public abstract void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener, int appType) throws CarNotConnectedException; /** * Abandon all focuses (mark them as inactive). * @param ownershipListener Ownership listener to abandon focus for. Cannot be null. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - public abstract void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener) + public abstract void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener) throws CarNotConnectedException; } diff --git a/car-support-lib/src/android/support/car/CarAppFocusManagerEmbedded.java b/car-support-lib/src/android/support/car/CarAppFocusManagerEmbedded.java index c688e3a51e..f8092b7830 100644 --- a/car-support-lib/src/android/support/car/CarAppFocusManagerEmbedded.java +++ b/car-support-lib/src/android/support/car/CarAppFocusManagerEmbedded.java @@ -27,9 +27,9 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { private final android.car.CarAppFocusManager mManager; - private final Map<AppFocusChangeListener, AppFocusChangeListenerProxy> + private final Map<OnAppFocusChangedListener, OnAppFocusChangedListenerProxy> mChangeListeners = new HashMap<>(); - private final Map<AppFocusOwnershipChangeListener, AppFocusOwnershipChangeListenerProxy> + private final Map<OnAppFocusOwnershipLostListener, OnAppFocusOwnershipLostListenerProxy> mOwnershipListeners = new HashMap<>(); /** @@ -40,30 +40,30 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } @Override - public void addFocusListener(int appType, AppFocusChangeListener listener) + public void addFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException { if (listener == null) { throw new IllegalArgumentException("null listener"); } - AppFocusChangeListenerProxy proxy; + OnAppFocusChangedListenerProxy proxy; synchronized (this) { proxy = mChangeListeners.get(listener); if (proxy == null) { - proxy = new AppFocusChangeListenerProxy(listener); + proxy = new OnAppFocusChangedListenerProxy(this, listener); mChangeListeners.put(listener, proxy); } } try { - mManager.registerFocusListener(proxy, appType); + mManager.addFocusListener(proxy, appType); } catch (android.car.CarNotConnectedException e) { throw new CarNotConnectedException(e); } } @Override - public void removeFocusListener(int appType, AppFocusChangeListener listener) + public void removeFocusListener(OnAppFocusChangedListener listener, int appType) throws CarNotConnectedException { - AppFocusChangeListenerProxy proxy; + OnAppFocusChangedListenerProxy proxy; synchronized (this) { proxy = mChangeListeners.get(listener); if (proxy == null) { @@ -71,16 +71,16 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } } try { - mManager.unregisterFocusListener(proxy, appType); + mManager.removeFocusListener(proxy, appType); } catch (android.car.CarNotConnectedException e) { throw new CarNotConnectedException(e); } } @Override - public void removeFocusListener(AppFocusChangeListener listener) + public void removeFocusListener(OnAppFocusChangedListener listener) throws CarNotConnectedException { - AppFocusChangeListenerProxy proxy; + OnAppFocusChangedListenerProxy proxy; synchronized (this) { proxy = mChangeListeners.remove(listener); if (proxy == null) { @@ -88,16 +88,16 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } } try { - mManager.unregisterFocusListener(proxy); + mManager.removeFocusListener(proxy); } catch (android.car.CarNotConnectedException e) { throw new CarNotConnectedException(e); } } @Override - public boolean isOwningFocus(int appType, AppFocusOwnershipChangeListener listener) + public boolean isOwningFocus(int appType, OnAppFocusOwnershipLostListener listener) throws CarNotConnectedException { - AppFocusOwnershipChangeListenerProxy proxy; + OnAppFocusOwnershipLostListenerProxy proxy; synchronized (this) { proxy = mOwnershipListeners.get(listener); if (proxy == null) { @@ -112,16 +112,16 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } @Override - public int requestAppFocus(int appType, AppFocusOwnershipChangeListener ownershipListener) + public int requestAppFocus(int appType, OnAppFocusOwnershipLostListener ownershipListener) throws IllegalStateException, SecurityException, CarNotConnectedException { if (ownershipListener == null) { throw new IllegalArgumentException("null listener"); } - AppFocusOwnershipChangeListenerProxy proxy; + OnAppFocusOwnershipLostListenerProxy proxy; synchronized (this) { proxy = mOwnershipListeners.get(ownershipListener); if (proxy == null) { - proxy = new AppFocusOwnershipChangeListenerProxy(ownershipListener); + proxy = new OnAppFocusOwnershipLostListenerProxy(this, ownershipListener); mOwnershipListeners.put(ownershipListener, proxy); } } @@ -133,12 +133,12 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } @Override - public void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener, int appType) + public void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener, int appType) throws CarNotConnectedException { if (ownershipListener == null) { throw new IllegalArgumentException("null listener"); } - AppFocusOwnershipChangeListenerProxy proxy; + OnAppFocusOwnershipLostListenerProxy proxy; synchronized (this) { proxy = mOwnershipListeners.get(ownershipListener); if (proxy == null) { @@ -153,12 +153,12 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { } @Override - public void abandonAppFocus(AppFocusOwnershipChangeListener ownershipListener) + public void abandonAppFocus(OnAppFocusOwnershipLostListener ownershipListener) throws CarNotConnectedException { if (ownershipListener == null) { throw new IllegalArgumentException("null listener"); } - AppFocusOwnershipChangeListenerProxy proxy; + OnAppFocusOwnershipLostListenerProxy proxy; synchronized (this) { proxy = mOwnershipListeners.get(ownershipListener); if (proxy == null) { @@ -177,33 +177,40 @@ public class CarAppFocusManagerEmbedded extends CarAppFocusManager { // nothing to do } - private static class AppFocusChangeListenerProxy implements - android.car.CarAppFocusManager.AppFocusChangeListener { + private static class OnAppFocusChangedListenerProxy + implements android.car.CarAppFocusManager.OnAppFocusChangedListener { - private final AppFocusChangeListener mListener; + private final OnAppFocusChangedListener mListener; + private final CarAppFocusManager mManager; - AppFocusChangeListenerProxy(AppFocusChangeListener listener) { + OnAppFocusChangedListenerProxy(CarAppFocusManager manager, + OnAppFocusChangedListener listener) { + mManager = manager; mListener = listener; } @Override - public void onAppFocusChange(int appType, boolean active) { - mListener.onAppFocusChange(appType, active); + public void onAppFocusChanged(int appType, boolean active) { + mListener.onAppFocusChanged(mManager, appType, active); } } - private static class AppFocusOwnershipChangeListenerProxy implements - android.car.CarAppFocusManager.AppFocusOwnershipChangeListener { + private static class OnAppFocusOwnershipLostListenerProxy + implements android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener { - private final AppFocusOwnershipChangeListener mListener; + private final OnAppFocusOwnershipLostListener mListener; + private final CarAppFocusManager mManager; - AppFocusOwnershipChangeListenerProxy(AppFocusOwnershipChangeListener listener) { + + OnAppFocusOwnershipLostListenerProxy(CarAppFocusManager manager, + OnAppFocusOwnershipLostListener listener) { mListener = listener; + mManager = manager; } @Override - public void onAppFocusOwnershipLoss(int focus) { - mListener.onAppFocusOwnershipLoss(focus); + public void onAppFocusOwnershipLost(int focus) { + mListener.onAppFocusOwnershipLost(mManager, focus); } } } diff --git a/car-support-lib/src/android/support/car/CarConnectionCallback.java b/car-support-lib/src/android/support/car/CarConnectionCallback.java index 9ab7c59850..c120ad5fd8 100644 --- a/car-support-lib/src/android/support/car/CarConnectionCallback.java +++ b/car-support-lib/src/android/support/car/CarConnectionCallback.java @@ -25,9 +25,13 @@ public abstract class CarConnectionCallback { * Called when the Car has been connected. Does not guarantee the car is still connected * while this callback is running, so {@link CarNotConnectedException}s may still be * thrown from {@link Car} method calls. + * @param car the car with which this callback is registered. * @param connectionType Type of car connected. */ - public abstract void onConnected(@Car.ConnectionType int connectionType); - /** Called when the Car has been disconnected. */ - public abstract void onDisconnected(); + public abstract void onConnected(Car car, @Car.ConnectionType int connectionType); + /** + * Called when the Car has been disconnected. + * @param car the car with which this callback is registered. + */ + public abstract void onDisconnected(Car car); } diff --git a/car-support-lib/src/android/support/car/CarInfoManager.java b/car-support-lib/src/android/support/car/CarInfoManager.java index 2db4b9f896..e1da9ba069 100644 --- a/car-support-lib/src/android/support/car/CarInfoManager.java +++ b/car-support-lib/src/android/support/car/CarInfoManager.java @@ -23,8 +23,7 @@ import android.support.car.annotation.ValueTypeDef; * Utility to retrieve static information from a car. String keys require different types of * values, so be sure to query using the correct API (such as {@link #getFloat(String)} for float * type and {@link #getInt(String)} for int type). Passing a key string to the wrong - * API causes an {@link IllegalArgumentException}. Get* APIs return null if the requested - * property is not supported by the car. + * API causes an {@link IllegalArgumentException}. */ public abstract class CarInfoManager implements CarManagerBase { diff --git a/car-support-lib/src/android/support/car/CarNotConnectedException.java b/car-support-lib/src/android/support/car/CarNotConnectedException.java index 264ee8250d..aa0cfcdd41 100644 --- a/car-support-lib/src/android/support/car/CarNotConnectedException.java +++ b/car-support-lib/src/android/support/car/CarNotConnectedException.java @@ -19,7 +19,8 @@ package android.support.car; /** * Exception thrown when an API that requires a car connection is called while disconnected from a - * car. + * car. This may have happened because the car and phone have become disconnected, the system is + * undergoing an upgrade, or some other event. */ public class CarNotConnectedException extends Exception { private static final long serialVersionUID = -5629175439268813047L; diff --git a/car-support-lib/src/android/support/car/CarNotSupportedException.java b/car-support-lib/src/android/support/car/CarNotSupportedException.java deleted file mode 100644 index 4ee71d6abd..0000000000 --- a/car-support-lib/src/android/support/car/CarNotSupportedException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.support.car; - - -/** - * Exception thrown when car does not support the requested operation. - */ -public class CarNotSupportedException extends Exception { - private static final long serialVersionUID = -8120487541467522808L; - - public CarNotSupportedException() { - } - - public CarNotSupportedException(String name) { - super(name); - } - - public CarNotSupportedException(String name, Throwable cause) { - super(name, cause); - } - - public CarNotSupportedException(Exception cause) { - super(cause); - } -} diff --git a/car-support-lib/src/android/support/car/CarServiceLoader.java b/car-support-lib/src/android/support/car/CarServiceLoader.java index 1f18350fa3..115c55364b 100644 --- a/car-support-lib/src/android/support/car/CarServiceLoader.java +++ b/car-support-lib/src/android/support/car/CarServiceLoader.java @@ -18,7 +18,6 @@ package android.support.car; import android.content.Context; import android.os.Handler; -import android.os.Looper; /** * CarServiceLoader is the abstraction for loading different types of car service. @@ -27,12 +26,12 @@ import android.os.Looper; public abstract class CarServiceLoader { private final Context mContext; - private final ServiceConnectionCallback mListener; + private final ServiceConnectionCallback mCallback; private final Handler mEventHandler; - public CarServiceLoader(Context context, ServiceConnectionCallback listener, Handler handler) { + public CarServiceLoader(Context context, ServiceConnectionCallback callback, Handler handler) { mContext = context; - mListener = listener; + mCallback = callback; mEventHandler = handler; } @@ -41,17 +40,16 @@ public abstract class CarServiceLoader { public abstract boolean isConnectedToCar(); @Car.ConnectionType public abstract int getCarConnectionType() throws CarNotConnectedException; - public abstract void registerCarConnectionCallback(CarConnectionCallback listener) + public abstract void registerCarConnectionCallback(CarConnectionCallback callback) throws CarNotConnectedException; - public abstract void unregisterCarConnectionCallback(CarConnectionCallback listener); + public abstract void unregisterCarConnectionCallback(CarConnectionCallback callback); /** * Retrieves a manager object for a specified Car*Manager. * @param serviceName One of the android.car.Car#*_SERVICE constants. * @return An instance of the request manager. Null if the manager is not supported on the * current vehicle. - * @throws CarNotConnectedException Thrown when the device is not connected to a car data - * source. + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public abstract Object getCarManager(String serviceName) throws CarNotConnectedException; @@ -59,8 +57,8 @@ public abstract class CarServiceLoader { return mContext; } - protected ServiceConnectionCallback getConnectionListener() { - return mListener; + protected ServiceConnectionCallback getConnectionCallback() { + return mCallback; } protected Handler getEventHandler() { diff --git a/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java b/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java index 7f8465b778..387124113e 100644 --- a/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java +++ b/car-support-lib/src/android/support/car/CarServiceLoaderEmbedded.java @@ -39,47 +39,49 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { @Override public void onServiceConnected(ComponentName name, IBinder service) { - getConnectionListener().onServiceConnected(); + getConnectionCallback().onServiceConnected(); } @Override public void onServiceDisconnected(ComponentName name) { - getConnectionListener().onServiceDisconnected(); + getConnectionCallback().onServiceDisconnected(); } }; - private final android.car.Car mCar; - private final LinkedList<CarConnectionCallback> mCarConnectionCallbackses = + private final android.car.Car mEmbeddedCar; + private final LinkedList<CarConnectionCallback> mCarConnectionCallback = new LinkedList<>(); private final CallbackHandler mHandler; - public CarServiceLoaderEmbedded(Context context, ServiceConnectionCallback listener, + /** @hide */ + CarServiceLoaderEmbedded(Car car, Context context, ServiceConnectionCallback + serviceConnectionCallback, Handler handler) { - super(context, listener, handler); - mCar = android.car.Car.createCar(context, mServiceConnection, handler); - mHandler = new CallbackHandler(handler.getLooper()); + super(context, serviceConnectionCallback, handler); + mEmbeddedCar = android.car.Car.createCar(context, mServiceConnection, handler); + mHandler = new CallbackHandler(car, handler.getLooper()); } @Override public void connect() throws IllegalStateException { - mCar.connect(); + mEmbeddedCar.connect(); } @Override public void disconnect() { - mCar.disconnect(); + mEmbeddedCar.disconnect(); } @Override public boolean isConnectedToCar() { // for embedded, connected to service means connected to car. - return mCar.isConnected(); + return mEmbeddedCar.isConnected(); } @Override public int getCarConnectionType() throws CarNotConnectedException { @android.support.car.Car.ConnectionType - int carConnectionType = mCar.getCarConnectionType(); + int carConnectionType = mEmbeddedCar.getCarConnectionType(); return carConnectionType; } @@ -87,7 +89,7 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { public void registerCarConnectionCallback(final CarConnectionCallback listener) throws CarNotConnectedException { synchronized (this) { - mCarConnectionCallbackses.add(listener); + mCarConnectionCallback.add(listener); } // car service connection is checked when this is called. So just dispatch it. mHandler.dispatchCarConnectionCall(listener, getCarConnectionType()); @@ -96,7 +98,7 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { @Override public void unregisterCarConnectionCallback(CarConnectionCallback listener) { synchronized (this) { - mCarConnectionCallbackses.remove(listener); + mCarConnectionCallback.remove(listener); } } @@ -104,7 +106,7 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { public Object getCarManager(String serviceName) throws CarNotConnectedException { Object manager; try { - manager = mCar.getCarManager(serviceName); + manager = mEmbeddedCar.getCarManager(serviceName); } catch (android.car.CarNotConnectedException e) { throw new CarNotConnectedException(e); } @@ -133,10 +135,12 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { private static class CallbackHandler extends Handler { - private static final int MSG_DISPATCH_CAR_CONNECTION = 0; + private static final int MSG_DISPATCH_CAR_CONNECTION = 0; + private final Car mCar; - private CallbackHandler(Looper looper) { + private CallbackHandler(Car car, Looper looper) { super(looper); + mCar = car; } private void dispatchCarConnectionCall(CarConnectionCallback listener, int connectionType) { @@ -148,7 +152,7 @@ public class CarServiceLoaderEmbedded extends CarServiceLoader { switch (msg.what) { case MSG_DISPATCH_CAR_CONNECTION: CarConnectionCallback listener = (CarConnectionCallback) msg.obj; - listener.onConnected(msg.arg1); + listener.onConnected(mCar, msg.arg1); break; } } diff --git a/car-support-lib/src/android/support/car/ServiceConnectionCallback.java b/car-support-lib/src/android/support/car/ServiceConnectionCallback.java index 35dfc58c6f..e27bca9620 100644 --- a/car-support-lib/src/android/support/car/ServiceConnectionCallback.java +++ b/car-support-lib/src/android/support/car/ServiceConnectionCallback.java @@ -16,7 +16,6 @@ package android.support.car; -import android.content.ComponentName; import android.content.ServiceConnection; /** @@ -38,14 +37,7 @@ public abstract class ServiceConnectionCallback { public abstract void onServiceDisconnected(); /** - * Car Service is temporarily suspended for reasons such as an update. - * @param cause The reason for the suspension. Currently unused. - */ - public abstract void onServiceSuspended(int cause); - - /** * Connection failed. Client may retry. - * @param cause The reason for the failure. Currently unused. */ - public abstract void onServiceConnectionFailed(int cause); + public abstract void onServiceConnectionFailed(); } diff --git a/car-support-lib/src/android/support/car/app/CarProxyActivity.java b/car-support-lib/src/android/support/car/app/CarProxyActivity.java index 773e763be6..c00dfc0d2d 100644 --- a/car-support-lib/src/android/support/car/app/CarProxyActivity.java +++ b/car-support-lib/src/android/support/car/app/CarProxyActivity.java @@ -62,18 +62,13 @@ public class CarProxyActivity extends Activity { private final ServiceConnectionCallback mConnectionListener= new ServiceConnectionCallback() { @Override - public void onServiceSuspended(int cause) { - Log.w(TAG, "Car service suspended: " + cause); - } - - @Override public void onServiceDisconnected() { Log.w(TAG, "Car service disconnected"); } @Override - public void onServiceConnectionFailed(int cause) { - Log.w(TAG, "Car service connection failed: " + cause); + public void onServiceConnectionFailed() { + Log.w(TAG, "Car service connection failed"); } @Override diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorEvent.java b/car-support-lib/src/android/support/car/hardware/CarSensorEvent.java index 9c8a5c93e3..aa27802508 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorEvent.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorEvent.java @@ -79,7 +79,7 @@ public class CarSensorEvent { * reception from the car in nanoseconds since system boot. */ @VersionDef(version = 1) - public final long timeStampNs; + public final long timestamp; /** * Array holding float type of sensor data. If the sensor has single value, only floatValues[0] * should be used. */ @@ -94,17 +94,17 @@ public class CarSensorEvent { * CarSensorManager implementations. App developers need not worry about constructing these * objects. */ - public CarSensorEvent(int sensorType, long timeStampNs, int floatValueSize, int intValueSize) { + public CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize) { this.sensorType = sensorType; - this.timeStampNs = timeStampNs; + this.timestamp = timestamp; floatValues = new float[floatValueSize]; intValues = new int[intValueSize]; } /** @hide */ - CarSensorEvent(int sensorType, long timeStampNs, float[] floatValues, int[] intValues) { + CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues) { this.sensorType = sensorType; - this.timeStampNs = timeStampNs; + this.timestamp = timestamp; this.floatValues = floatValues; this.intValues = intValues; } @@ -122,7 +122,7 @@ public class CarSensorEvent { */ public static class CompassData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** The bearing in degrees. If unsupported by the car, this value is NaN. */ public final float bearing; /** The pitch in degrees. Nose down is positive. If unsupported by the car, this value is NaN. */ @@ -130,8 +130,8 @@ public class CarSensorEvent { /** The roll in degrees. Right door down is positive. If unsupported by the car, this value is NaN. */ public final float roll; - public CompassData(long timeStampNs, float bearing, float pitch, float roll) { - this.timeStampNs = timeStampNs; + public CompassData(long timestamp, float bearing, float pitch, float roll) { + this.timestamp = timestamp; this.bearing = bearing; this.pitch = pitch; this.roll = roll; @@ -155,12 +155,12 @@ public class CarSensorEvent { */ public static class ParkingBrakeData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** Returns {@code true} if the parking brake is engaged. */ public final boolean isEngaged; - public ParkingBrakeData(long timeStampNs, boolean isEngaged) { - this.timeStampNs = timeStampNs; + public ParkingBrakeData(long timestamp, boolean isEngaged) { + this.timestamp = timestamp; this.isEngaged = isEngaged; } } @@ -173,21 +173,21 @@ public class CarSensorEvent { */ public ParkingBrakeData getParkingBrakeData() { checkType(CarSensorManager.SENSOR_TYPE_PARKING_BRAKE); - return new ParkingBrakeData(timeStampNs, (intValues[0] == 1)); + return new ParkingBrakeData(timestamp, (intValues[0] == 1)); } /** * Indicates if the system is in night mode (a state in which the screen is - * darkened or displays a darker color pallete). + * darkened or displays a darker color palette). */ public static class NightData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** Returns {@code true} if the system is in night mode. */ public final boolean isNightMode; - public NightData(long timeStampNs, boolean isNightMode) { - this.timeStampNs = timeStampNs; + public NightData(long timestamp, boolean isNightMode) { + this.timestamp = timestamp; this.isNightMode = isNightMode; } } @@ -200,7 +200,7 @@ public class CarSensorEvent { */ public NightData getNightData() { checkType(CarSensorManager.SENSOR_TYPE_NIGHT); - return new NightData(timeStampNs, (intValues[0] == 1)); + return new NightData(timestamp, (intValues[0] == 1)); } /** @@ -210,7 +210,7 @@ public class CarSensorEvent { /** * The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** * A bitmask with the following field values: {@link #DRIVE_STATUS_NO_VIDEO}, * {@link #DRIVE_STATUS_NO_KEYBOARD_INPUT}, {@link #DRIVE_STATUS_NO_VOICE_INPUT}, @@ -219,8 +219,8 @@ public class CarSensorEvent { */ public final int status; - public DrivingStatusData(long timeStampNs, int status) { - this.timeStampNs = timeStampNs; + public DrivingStatusData(long timestamp, int status) { + this.timestamp = timestamp; this.status = status; } @@ -276,7 +276,7 @@ public class CarSensorEvent { */ public DrivingStatusData getDrivingStatusData() { checkType(CarSensorManager.SENSOR_TYPE_DRIVING_STATUS); - return new DrivingStatusData(timeStampNs, intValues[0]); + return new DrivingStatusData(timestamp, intValues[0]); } @@ -441,14 +441,14 @@ public class CarSensorEvent { /** @hide */ public static class EnvironmentData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** If unsupported by the car, this value is NaN. */ public final float temperature; /** If unsupported by the car, this value is NaN. */ public final float pressure; - public EnvironmentData(long timeStampNs, float temperature, float pressure) { - this.timeStampNs = timeStampNs; + public EnvironmentData(long timestamp, float temperature, float pressure) { + this.timestamp = timestamp; this.temperature = temperature; this.pressure = pressure; } @@ -466,17 +466,17 @@ public class CarSensorEvent { float temperature = floatValues[INDEX_ENVIRONMENT_TEMPERATURE]; float pressure = floatValues[INDEX_ENVIRONMENT_PRESSURE]; - return new EnvironmentData(timeStampNs, temperature, pressure); + return new EnvironmentData(timestamp, temperature, pressure); } /** @hide */ public static class GearData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; public final int gear; - public GearData(long timeStampNs, int gear) { - this.timeStampNs = timeStampNs; + public GearData(long timestamp, int gear) { + this.timestamp = timestamp; this.gear = gear; } } @@ -490,13 +490,13 @@ public class CarSensorEvent { */ public GearData getGearData() { checkType(CarSensorManager.SENSOR_TYPE_GEAR); - return new GearData(timeStampNs,intValues[0] ); + return new GearData(timestamp,intValues[0] ); } /** @hide */ public static class FuelLevelData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** Fuel level in %. If unsupported by the car, this value is -1. */ public final int level; /** Fuel as possible range in Km. If unsupported by the car, this value is -1. */ @@ -504,8 +504,8 @@ public class CarSensorEvent { /** If unsupported by the car, this value is false. */ public final boolean lowFuelWarning; - public FuelLevelData(long timeStampNs, int level, float range, boolean lowFuelWarning) { - this.timeStampNs = timeStampNs; + public FuelLevelData(long timestamp, int level, float range, boolean lowFuelWarning) { + this.timestamp = timestamp; this.level = level; this.range = range; this.lowFuelWarning = lowFuelWarning; @@ -532,17 +532,17 @@ public class CarSensorEvent { } } boolean lowFuelWarning = (intValues[0] == 1); - return new FuelLevelData(timeStampNs, level, range, lowFuelWarning); + return new FuelLevelData(timestamp, level, range, lowFuelWarning); } /** @hide */ public static class OdometerData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; public final float kms; - public OdometerData(long timeStampNs, float kms) { - this.timeStampNs = timeStampNs; + public OdometerData(long timestamp, float kms) { + this.timestamp = timestamp; this.kms = kms; } } @@ -556,17 +556,17 @@ public class CarSensorEvent { */ public OdometerData getOdometerData() { checkType(CarSensorManager.SENSOR_TYPE_ODOMETER); - return new OdometerData(timeStampNs,floatValues[0]); + return new OdometerData(timestamp,floatValues[0]); } /** @hide */ public static class RpmData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; public final float rpm; - public RpmData(long timeStampNs, float rpm) { - this.timeStampNs = timeStampNs; + public RpmData(long timestamp, float rpm) { + this.timestamp = timestamp; this.rpm = rpm; } } @@ -579,17 +579,17 @@ public class CarSensorEvent { */ public RpmData getRpmData() { checkType(CarSensorManager.SENSOR_TYPE_RPM); - return new RpmData(timeStampNs, floatValues[0]); + return new RpmData(timestamp, floatValues[0]); } /** @hide */ public static class CarSpeedData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; public final float carSpeed; - public CarSpeedData(long timeStampNs, float carSpeed) { - this.timeStampNs = timeStampNs; + public CarSpeedData(long timestamp, float carSpeed) { + this.timestamp = timestamp; this.carSpeed = carSpeed; } } @@ -603,7 +603,7 @@ public class CarSensorEvent { */ public CarSpeedData getCarSpeedData() { checkType(CarSensorManager.SENSOR_TYPE_CAR_SPEED); - return new CarSpeedData(timeStampNs, floatValues[0]); + return new CarSpeedData(timestamp, floatValues[0]); } /** @@ -642,21 +642,21 @@ public class CarSensorEvent { if ((presense & (0x1 << INDEX_LOCATION_BEARING)) != 0) { location.setBearing(floatValues[INDEX_LOCATION_BEARING]); } - location.setElapsedRealtimeNanos(timeStampNs); + location.setElapsedRealtimeNanos(timestamp); // There is a risk of scheduler delaying 2nd elapsedRealtimeNs value. // But will not try to fix it assuming that is acceptable as UTC time's accuracy is not // guaranteed in Location data. long currentTimeMs = System.currentTimeMillis(); long elapsedRealtimeNs = SystemClock.elapsedRealtimeNanos(); location.setTime( - currentTimeMs - (elapsedRealtimeNs - timeStampNs) / MILLI_IN_NANOS); + currentTimeMs - (elapsedRealtimeNs - timestamp) / MILLI_IN_NANOS); return location; } /** @hide */ public static class AccelerometerData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** If unsupported by the car, this value is NaN. */ public final float x; /** If unsupported by the car, this value is NaN. */ @@ -664,8 +664,8 @@ public class CarSensorEvent { /** If unsupported by the car, this value is NaN. */ public final float z; - public AccelerometerData(long timeStampNs, float x, float y, float z) { - this.timeStampNs = timeStampNs; + public AccelerometerData(long timestamp, float x, float y, float z) { + this.timestamp = timestamp; this.x = x; this.y = y; this.z = z; @@ -683,13 +683,13 @@ public class CarSensorEvent { float x = floatValues[INDEX_ACCELEROMETER_X]; float y = floatValues[INDEX_ACCELEROMETER_Y]; float z = floatValues[INDEX_ACCELEROMETER_Z]; - return new AccelerometerData(timeStampNs, x, y, z); + return new AccelerometerData(timestamp, x, y, z); } /** @hide */ public static class GyroscopeData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** If unsupported by the car, this value is NaN. */ public final float x; /** If unsupported by the car, this value is NaN. */ @@ -697,8 +697,8 @@ public class CarSensorEvent { /** If unsupported by the car, this value is NaN. */ public final float z; - public GyroscopeData(long timeStampNs, float x, float y, float z) { - this.timeStampNs = timeStampNs; + public GyroscopeData(long timestamp, float x, float y, float z) { + this.timestamp = timestamp; this.x = x; this.y = y; this.z = z; @@ -716,7 +716,7 @@ public class CarSensorEvent { float x = floatValues[INDEX_GYROSCOPE_X]; float y = floatValues[INDEX_GYROSCOPE_Y]; float z = floatValues[INDEX_GYROSCOPE_Z]; - return new GyroscopeData(timeStampNs, x, y, z); + return new GyroscopeData(timestamp, x, y, z); } // android.location.GpsSatellite doesn't have a public constructor, so that can't be used. @@ -727,7 +727,7 @@ public class CarSensorEvent { */ public static class GpsSatelliteData { /** The time in nanoseconds since system boot. */ - public final long timeStampNs; + public final long timestamp; /** * Number of satellites used in GPS fix or -1 of unavailable. */ @@ -762,9 +762,9 @@ public class CarSensorEvent { */ public final float[] elevation ; - public GpsSatelliteData(long timeStampNs, int numberInUse, int numberInView, + public GpsSatelliteData(long timestamp, int numberInUse, int numberInView, boolean[] usedInFix, int[] prn, float[] snr, float[] azimuth, float[] elevation) { - this.timeStampNs = timeStampNs; + this.timestamp = timestamp; this.numberInUse = numberInUse; this.numberInView = numberInView; this.usedInFix = usedInFix; @@ -822,7 +822,7 @@ public class CarSensorEvent { + CarSensorEvent.INDEX_GPS_SATELLITE_ELEVATION_OFFSET]; } } - return new GpsSatelliteData(timeStampNs, numberInUse, numberInView, usedInFix, prn, snr, + return new GpsSatelliteData(timestamp, numberInUse, numberInView, usedInFix, prn, snr, azimuth, elevation); } 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 9fd77a1638..cecabbd983 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorManager.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorManager.java @@ -65,8 +65,8 @@ public abstract class CarSensorManager implements CarManagerBase { /** * Represent the current status of parking brake. Sensor data in {@link CarSensorEvent} is in * intValues[0]. A value of 1 indicates the parking brake is engaged; a value of 0 indicates - * the parking brake is not enagaged. - * For this sensor, rate in {@link #addListener(CarSensorEventListener, int, int)} is + * the parking brake is not engaged. + * For this sensor, rate in {@link #addListener(OnSensorChangedListener, int, int)} is * ignored and all changes are notified. */ public static final int SENSOR_TYPE_PARKING_BRAKE = 6; @@ -131,6 +131,7 @@ public abstract class CarSensorManager implements CarManagerBase { * @hide */ public static final int SENSOR_TYPE_VENDOR_EXTENSION_START = 0x60000000; + /** @hide */ public static final int SENSOR_TYPE_VENDOR_EXTENSION_END = 0x6fffffff; /** Read sensor at the default normal rate set for each sensors. This is default rate. */ @@ -146,18 +147,20 @@ public abstract class CarSensorManager implements CarManagerBase { * Listener for car sensor data change. * Callbacks are called in the Looper context. */ - public interface CarSensorEventListener { + public interface OnSensorChangedListener { /** * Called when there is new sensor data from car. + * @param manager The manager the listener is attached to. Useful if the app wished to + * unregister. * @param event Incoming sensor event for the given sensor type. */ - void onSensorChanged(final CarSensorEvent event); + void onSensorChanged(final CarSensorManager manager, final CarSensorEvent event); } /** * Get the list of CarSensors available in the connected car. * @return Array of all sensor types supported. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public abstract int[] getSupportedSensors() throws CarNotConnectedException; @@ -165,16 +168,19 @@ public abstract class CarSensorManager implements CarManagerBase { * Indicate support for a given sensor. * @param sensorType * @return Returns {@code true} if the sensor is supported. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public abstract boolean isSensorSupported(int sensorType) throws CarNotConnectedException; /** - * Register {@link CarSensorEventListener} to get repeated sensor updates. Can register + * Register {@link OnSensorChangedListener} to get repeated sensor updates. Can register * multiple listeners for a single sensor or use the same listener for different * sensors. If the same listener is registered again for the same sensor, it is ignored or * updated (depending on the rate). * <p> + * The {@link OnSensorChangedListener} is the identifier for the request and the same + * instance must be passed into {@link #removeListener(OnSensorChangedListener)}. + * <p> * Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} for * {@link #SENSOR_TYPE_LOCATION}, {@link Car#PERMISSION_SPEED} for * {@link #SENSOR_TYPE_CAR_SPEED}, {@link Car#PERMISSION_MILEAGE} for @@ -187,13 +193,13 @@ public abstract class CarSensorManager implements CarManagerBase { * respected, especially when the same sensor is registered with a different listener * and with different rates. * @return Returns {@code true} if the sensor was successfully enabled. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. * @throws IllegalArgumentException if wrong argument (such as wrong rate). * @throws SecurityException if missing the appropriate permission. */ @RequiresPermission(anyOf={Manifest.permission.ACCESS_FINE_LOCATION, Car.PERMISSION_SPEED, Car.PERMISSION_MILEAGE, Car.PERMISSION_FUEL}, conditional=true) - public abstract boolean addListener(CarSensorEventListener listener, int sensorType, + public abstract boolean addListener(OnSensorChangedListener listener, int sensorType, int rate) throws CarNotConnectedException, IllegalArgumentException; /** @@ -201,7 +207,7 @@ public abstract class CarSensorManager implements CarManagerBase { * this listener, all listening is stopped. * @param listener The listener to remove. */ - public abstract void removeListener(CarSensorEventListener listener) + public abstract void removeListener(OnSensorChangedListener listener) throws CarNotConnectedException; /** @@ -210,14 +216,14 @@ public abstract class CarSensorManager implements CarManagerBase { * @param listener The listener to remove. * @param sensorType The type to stop receiving notifications for. */ - public abstract void removeListener(CarSensorEventListener listener, int sensorType) + public abstract void removeListener(OnSensorChangedListener listener, int sensorType) throws CarNotConnectedException; /** * Get the most recent CarSensorEvent for the given type. * @param type A sensor to request. * @return null if no sensor update since connection to the car. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ public abstract CarSensorEvent getLatestSensorEvent(int type) throws CarNotConnectedException; } 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 aa94cfec1d..4246d3f003 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorManagerEmbedded.java @@ -31,11 +31,11 @@ public class CarSensorManagerEmbedded extends CarSensorManager { private final android.car.hardware.CarSensorManager mManager; private final CarSensorsProxy mCarSensorsProxy; - private final LinkedList<CarSensorEventListenerProxy> mListeners = new LinkedList<>(); + private final LinkedList<OnSensorChangedListenerProxy> mListeners = new LinkedList<>(); public CarSensorManagerEmbedded(Object manager, Context context) { mManager = (android.car.hardware.CarSensorManager) manager; - mCarSensorsProxy = new CarSensorsProxy(context); + mCarSensorsProxy = new CarSensorsProxy(this, context); } @Override @@ -85,16 +85,16 @@ public class CarSensorManagerEmbedded extends CarSensorManager { } @Override - public boolean addListener(CarSensorEventListener listener, int sensorType, + public boolean addListener(OnSensorChangedListener listener, int sensorType, int rate) throws CarNotConnectedException, IllegalArgumentException { if (isSensorProxied(sensorType)) { return mCarSensorsProxy.registerSensorListener(listener, sensorType, rate); } - CarSensorEventListenerProxy proxy = null; + OnSensorChangedListenerProxy proxy = null; synchronized (this) { proxy = findListenerLocked(listener); if (proxy == null) { - proxy = new CarSensorEventListenerProxy(listener, sensorType); + proxy = new OnSensorChangedListenerProxy(listener, sensorType, this); mListeners.add(proxy); } else { proxy.sensors.add(sensorType); @@ -108,10 +108,10 @@ public class CarSensorManagerEmbedded extends CarSensorManager { } @Override - public void removeListener(CarSensorEventListener listener) + public void removeListener(OnSensorChangedListener listener) throws CarNotConnectedException { mCarSensorsProxy.unregisterSensorListener(listener); - CarSensorEventListenerProxy proxy = null; + OnSensorChangedListenerProxy proxy = null; synchronized (this) { proxy = findListenerLocked(listener); if (proxy == null) { @@ -127,10 +127,10 @@ public class CarSensorManagerEmbedded extends CarSensorManager { } @Override - public void removeListener(CarSensorEventListener listener, int sensorType) + public void removeListener(OnSensorChangedListener listener, int sensorType) throws CarNotConnectedException { mCarSensorsProxy.unregisterSensorListener(listener, sensorType); - CarSensorEventListenerProxy proxy = null; + OnSensorChangedListenerProxy proxy = null; synchronized (this) { proxy = findListenerLocked(listener); if (proxy == null) { @@ -165,8 +165,8 @@ public class CarSensorManagerEmbedded extends CarSensorManager { //nothing to do } - private CarSensorEventListenerProxy findListenerLocked(CarSensorEventListener listener) { - for (CarSensorEventListenerProxy proxy : mListeners) { + private OnSensorChangedListenerProxy findListenerLocked(OnSensorChangedListener listener) { + for (OnSensorChangedListenerProxy proxy : mListeners) { if (proxy.listener == listener) { return proxy; } @@ -178,25 +178,28 @@ public class CarSensorManagerEmbedded extends CarSensorManager { if (event == null) { return null; } - return new CarSensorEvent(event.sensorType, event.timeStampNs, event.floatValues, + return new CarSensorEvent(event.sensorType, event.timestamp, event.floatValues, event.intValues); } - private static class CarSensorEventListenerProxy implements - android.car.hardware.CarSensorManager.CarSensorEventListener { + private static class OnSensorChangedListenerProxy + implements android.car.hardware.CarSensorManager.OnSensorChangedListener { - public final CarSensorEventListener listener; - public final Set<Integer> sensors = new HashSet<Integer>(); + public final OnSensorChangedListener listener; + public final Set<Integer> sensors = new HashSet<>(); + public final CarSensorManager manager; - CarSensorEventListenerProxy(CarSensorEventListener listener, int sensor) { + OnSensorChangedListenerProxy(OnSensorChangedListener listener, int sensor, + CarSensorManager manager) { this.listener = listener; this.sensors.add(sensor); + this.manager = manager; } @Override public void onSensorChanged(android.car.hardware.CarSensorEvent event) { CarSensorEvent newEvent = convert(event); - listener.onSensorChanged(newEvent); + listener.onSensorChanged(manager, newEvent); } } } diff --git a/car-support-lib/src/android/support/car/hardware/CarSensorsProxy.java b/car-support-lib/src/android/support/car/hardware/CarSensorsProxy.java index 641ae7ecfd..34966d90e8 100644 --- a/car-support-lib/src/android/support/car/hardware/CarSensorsProxy.java +++ b/car-support-lib/src/android/support/car/hardware/CarSensorsProxy.java @@ -46,7 +46,7 @@ class CarSensorsProxy { private static final int MSG_SENSORT_EVENT = 1; // @GuardedBy("this") - private final Map<Integer, Set<CarSensorManager.CarSensorEventListener>> mListenersMultiMap; + private final Map<Integer, Set<CarSensorManager.OnSensorChangedListener>> mListenersMultiMap; private final LocationManager mLocationManager; private final SensorManager mSensorManager; private final Sensor mAccelerometerSensor; @@ -54,6 +54,9 @@ class CarSensorsProxy { private final Sensor mGyroscopeSensor; private final int[] mSupportedSensors; + // returned with the onSensorChanged messages. + private final CarSensorManager mCarSensorManager; + // @GuardedBy("this") private Location mLastLocation; // @GuardedBy("this") @@ -157,15 +160,15 @@ class CarSensorsProxy { switch (msg.what) { case MSG_SENSORT_EVENT: int sensorType = msg.arg1; - Collection<CarSensorManager.CarSensorEventListener> listenersCollection; + Collection<CarSensorManager.OnSensorChangedListener> listenersCollection; synchronized (CarSensorsProxy.this) { listenersCollection = mListenersMultiMap.get(sensorType); } CarSensorEvent event = (CarSensorEvent) msg.obj; if (event != null) { - for (CarSensorManager.CarSensorEventListener listener : + for (CarSensorManager.OnSensorChangedListener listener : listenersCollection) { - listener.onSensorChanged(event); + listener.onSensorChanged(mCarSensorManager, event); } } break; @@ -176,15 +179,15 @@ class CarSensorsProxy { } }; - CarSensorsProxy(Context context) { + CarSensorsProxy(CarSensorManager carSensorManager, Context context) { mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mAccelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mGyroscopeSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); - mListenersMultiMap = new HashMap<Integer, Set<CarSensorManager.CarSensorEventListener>>(); + mListenersMultiMap = new HashMap<Integer, Set<CarSensorManager.OnSensorChangedListener>>(); mSupportedSensors = initSupportedSensors(context); - + mCarSensorManager = carSensorManager; } private int[] initSupportedSensors(Context context) { @@ -232,14 +235,14 @@ class CarSensorsProxy { return mSupportedSensors; } - public boolean registerSensorListener(CarSensorManager.CarSensorEventListener listener, + public boolean registerSensorListener(CarSensorManager.OnSensorChangedListener listener, int sensorType, int rate) { // current implementation ignores rate. boolean sensorSetChanged = false; synchronized (this) { if (mListenersMultiMap.get(sensorType) == null) { mListenersMultiMap.put(sensorType, - new HashSet<CarSensorManager.CarSensorEventListener>()); + new HashSet<CarSensorManager.OnSensorChangedListener>()); sensorSetChanged = true; } mListenersMultiMap.get(sensorType).add(listener); @@ -253,14 +256,14 @@ class CarSensorsProxy { return true; } - public void unregisterSensorListener(CarSensorManager.CarSensorEventListener listener, + public void unregisterSensorListener(CarSensorManager.OnSensorChangedListener listener, int sensorType) { if (listener == null) { return; } boolean sensorSetChanged = false; synchronized (this) { - Set<CarSensorManager.CarSensorEventListener> sensorTypeListeneres = + Set<CarSensorManager.OnSensorChangedListener> sensorTypeListeneres = mListenersMultiMap.get(sensorType); if (sensorTypeListeneres != null) { sensorTypeListeneres.remove(listener); @@ -275,13 +278,13 @@ class CarSensorsProxy { }; } - public void unregisterSensorListener(CarSensorManager.CarSensorEventListener listener) { + public void unregisterSensorListener(CarSensorManager.OnSensorChangedListener listener) { if (listener == null) { return; } Set<Integer> sensorsToRemove = new HashSet<>(); synchronized (this) { - for (Map.Entry<Integer, Set<CarSensorManager.CarSensorEventListener>> entry : + for (Map.Entry<Integer, Set<CarSensorManager.OnSensorChangedListener>> entry : mListenersMultiMap.entrySet()) { if (entry.getValue().contains(listener)) { entry.getValue().remove(listener); diff --git a/car-support-lib/src/android/support/car/media/CarAudioManager.java b/car-support-lib/src/android/support/car/media/CarAudioManager.java index 20709ae3a3..a9df19de24 100644 --- a/car-support-lib/src/android/support/car/media/CarAudioManager.java +++ b/car-support-lib/src/android/support/car/media/CarAudioManager.java @@ -24,7 +24,6 @@ import android.support.annotation.IntDef; import android.support.annotation.RequiresPermission; import android.support.car.CarManagerBase; import android.support.car.CarNotConnectedException; -import android.support.car.CarNotSupportedException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -146,13 +145,15 @@ public abstract class CarAudioManager implements CarManagerBase { */ public abstract AudioFormat getAudioRecordAudioFormat(); + public abstract boolean isAudioRecordSupported(); + /** * Get minimum buffer size for {@link CarAudioRecord}. * * @return Buffer size in bytes. */ public abstract int getAudioRecordMinBufferSize() - throws CarNotConnectedException, CarNotSupportedException; + throws CarNotConnectedException; /** * Get maximum buffer size for {@link CarAudioRecord}. @@ -160,7 +161,7 @@ public abstract class CarAudioManager implements CarManagerBase { * @return Buffer size in bytes. */ public abstract int getAudioRecordMaxBufferSize() - throws CarNotConnectedException, CarNotSupportedException; + throws CarNotConnectedException; /** * Create a {@link CarAudioRecord} for the current {@link CarAudioManager}. There can be @@ -177,7 +178,7 @@ public abstract class CarAudioManager implements CarManagerBase { */ @RequiresPermission(Manifest.permission.RECORD_AUDIO) public abstract CarAudioRecord createCarAudioRecord(int bufferSize) - throws SecurityException, CarNotConnectedException, CarNotSupportedException; + throws SecurityException, CarNotConnectedException; /** * Check if media audio is muted or not (includes music and radio). Any application @@ -190,7 +191,8 @@ public abstract class CarAudioManager implements CarManagerBase { /** * Mute or unmute media stream including radio. Can involve audio focus change to stop * the the app currently holding audio focus. If requester is currently holding audio focus, - * it gets LOSS_TRANSIENT focus loss. Requires {@link PERMISSION_CAR_CONTROL_AUDIO_VOLUME} + * it gets LOSS_TRANSIENT focus loss. Requires + * {@link android.support.car.Car#PERMISSION_CAR_CONTROL_AUDIO_VOLUME} * permission. * * @param mute Returns {@code true} if media stream should be muted. diff --git a/car-support-lib/src/android/support/car/media/CarAudioManagerEmbedded.java b/car-support-lib/src/android/support/car/media/CarAudioManagerEmbedded.java index cb44f15eca..ec2fb770ce 100644 --- a/car-support-lib/src/android/support/car/media/CarAudioManagerEmbedded.java +++ b/car-support-lib/src/android/support/car/media/CarAudioManagerEmbedded.java @@ -66,6 +66,12 @@ public class CarAudioManagerEmbedded extends CarAudioManager { } @Override + public boolean isAudioRecordSupported(){ + //always true in embedded + return true; + } + + @Override public AudioFormat getAudioRecordAudioFormat() { return AUDIO_RECORD_FORMAT; } diff --git a/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManager.java b/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManager.java index 6fd749f331..4dedf9a8c2 100644 --- a/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManager.java +++ b/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManager.java @@ -27,7 +27,7 @@ import android.support.car.CarNotConnectedException; * turn-by-turn information to the cluster through this manager. * <p/> * Navigation applications should first call {@link CarAppFocusManager#requestAppFocus(int, - * CarAppFocusManager.AppFocusOwnershipChangeListener)} and request {@link + * CarAppFocusManager.OnAppFocusOwnershipLostListener)} and request {@link * CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION}. After navigation focus is granted, apps can * request this manager via {@link Car#getCarManager(String)}. In cars without an instrument * cluster, a null value is returned. @@ -49,18 +49,23 @@ public interface CarNavigationStatusManager extends CarManagerBase { /** * Listener for navigation related events. Callbacks are called in the Looper context. */ - public interface CarNavigationListener { + public interface CarNavigationCallback { /** * Instrument Cluster started in navigation mode. + * @param manager The manager the callback is attached to. Useful if the app wished to + * unregister. * @param instrumentCluster An object describing the configuration and state of the car's * navigation instrument cluster. */ - void onInstrumentClusterStart(CarNavigationInstrumentCluster instrumentCluster); + void onInstrumentClusterStarted(CarNavigationStatusManager manager, + CarNavigationInstrumentCluster instrumentCluster); /** * Instrument cluster ended. + * @param manager The manager the callback is attached to. Useful if the app wished to + * unregister. */ - void onInstrumentClusterStop(); + void onInstrumentClusterStopped(CarNavigationStatusManager manager); } /* Navigation statuses */ @@ -144,7 +149,7 @@ public interface CarNavigationStatusManager extends CarManagerBase { * @param status New instrument cluster navigation status, one of the STATUS_* constants in * this class. * @return Returns {@code true} if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ boolean sendNavigationStatus(int status) throws CarNotConnectedException; @@ -168,7 +173,7 @@ public interface CarNavigationStatusManager extends CarManagerBase { * @param turnSide Turn side ({@link #TURN_SIDE_LEFT}, {@link #TURN_SIDE_RIGHT} or {@link * #TURN_SIDE_UNSPECIFIED}). * @return Returns {@code true} if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ boolean sendNavigationTurnEvent(int event, String road, int turnAngle, int turnNumber, int turnSide) throws CarNotConnectedException; @@ -197,20 +202,20 @@ public interface CarNavigationStatusManager extends CarManagerBase { * @param displayDistanceUnit Unit type to use on of the DISTANCE_* types defined in this * file. * @return Returns {@code true} if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ boolean sendNavigationTurnDistanceEvent(int distanceMeters, int timeSeconds, int displayDistanceMillis, int displayDistanceUnit) throws CarNotConnectedException; /** - * @param Listener {@link CarNavigationListener} to be registered, replacing any existing + * @param callback {@link CarNavigationCallback} to be registered, replacing any existing * listeners. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ - void addListener(CarNavigationListener listener) throws CarNotConnectedException; + void addListener(CarNavigationCallback callback) throws CarNotConnectedException; /** - * Unregister the {@link CarNavigationListener} associated with this instance. + * Unregister the {@link CarNavigationCallback} associated with this instance. */ void removeListener(); } diff --git a/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManagerEmbedded.java b/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManagerEmbedded.java index 3db80e0d45..501a5cc065 100644 --- a/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManagerEmbedded.java +++ b/car-support-lib/src/android/support/car/navigation/CarNavigationStatusManagerEmbedded.java @@ -32,7 +32,7 @@ public class CarNavigationStatusManagerEmbedded implements CarNavigationStatusMa /** * @param status new instrument cluster navigation status. * @return true if successful. - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ @Override public boolean sendNavigationStatus(int status) throws CarNotConnectedException { @@ -77,17 +77,17 @@ public class CarNavigationStatusManagerEmbedded implements CarNavigationStatusMa } /** - * In this implementation we just immediately call {@code listener#onInstrumentClusterStart} as + * In this implementation we just immediately call {@code listener#onInstrumentClusterStarted} as * we expect instrument cluster to be working all the time. * - * @throws CarNotConnectedException + * @throws CarNotConnectedException if the connection to the car service has been lost. */ @Override - public void addListener(CarNavigationListener listener) + public void addListener(CarNavigationCallback callback) throws CarNotConnectedException { try { - listener.onInstrumentClusterStart(convert(mManager.getInstrumentClusterInfo())); + callback.onInstrumentClusterStarted(this, convert(mManager.getInstrumentClusterInfo())); } catch (android.car.CarNotConnectedException e) { throw new CarNotConnectedException(e); } diff --git a/service/src/com/android/car/AppFocusService.java b/service/src/com/android/car/AppFocusService.java index d7f9c3e815..4e85e81a4c 100644 --- a/service/src/com/android/car/AppFocusService.java +++ b/service/src/com/android/car/AppFocusService.java @@ -307,14 +307,14 @@ public class AppFocusService extends IAppFocus.Stub implements CarServiceBase, private void dispatchAppFocusOwnershipLoss(IAppFocusOwnershipListener listener, int appType) { try { - listener.onAppFocusOwnershipLoss(appType); + listener.onAppFocusOwnershipLost(appType); } catch (RemoteException e) { } } private void dispatchAppFocusChange(IAppFocusListener listener, int appType, boolean active) { try { - listener.onAppFocusChange(appType, active); + listener.onAppFocusChanged(appType, active); } catch (RemoteException e) { } } diff --git a/service/src/com/android/car/CarProjectionService.java b/service/src/com/android/car/CarProjectionService.java index 1c5f15dfee..52fd93f38e 100644 --- a/service/src/com/android/car/CarProjectionService.java +++ b/service/src/com/android/car/CarProjectionService.java @@ -17,7 +17,7 @@ package com.android.car; import android.car.CarProjectionManager; import android.car.ICarProjection; -import android.car.ICarProjectionListener; +import android.car.ICarProjectionCallback; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -36,7 +36,7 @@ import java.io.PrintWriter; * It also enables proejcted applications to handle voice action requests. */ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase, - BinderInterfaceContainer.BinderEventHandler<ICarProjectionListener> { + BinderInterfaceContainer.BinderEventHandler<ICarProjectionCallback> { private final ListenerHolder mAllListeners; private final CarInputService mCarInputService; private final Context mContext; @@ -136,7 +136,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase } private synchronized void handleVoiceAssitantRequest(boolean isTriggeredByLongPress) { - for (BinderInterfaceContainer.BinderInterface<ICarProjectionListener> listener : + for (BinderInterfaceContainer.BinderInterface<ICarProjectionCallback> listener : mAllListeners.getInterfaces()) { ListenerInfo listenerInfo = (ListenerInfo) listener; if ((listenerInfo.hasFilter(CarProjectionManager.PROJECTION_LONG_PRESS_VOICE_SEARCH) @@ -149,7 +149,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase } @Override - public void regsiterProjectionListener(ICarProjectionListener listener, int filter) { + public void regsiterProjectionListener(ICarProjectionCallback listener, int filter) { synchronized (this) { ListenerInfo info = (ListenerInfo) mAllListeners.getBinderInterface(listener); if (info == null) { @@ -163,7 +163,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase } @Override - public void unregsiterProjectionListener(ICarProjectionListener listener) { + public void unregsiterProjectionListener(ICarProjectionCallback listener) { synchronized (this) { mAllListeners.removeBinder(listener); } @@ -174,7 +174,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase boolean listenShortPress = false; boolean listenLongPress = false; synchronized (this) { - for (BinderInterfaceContainer.BinderInterface<ICarProjectionListener> listener : + for (BinderInterfaceContainer.BinderInterface<ICarProjectionCallback> listener : mAllListeners.getInterfaces()) { ListenerInfo listenerInfo = (ListenerInfo) listener; listenShortPress |= listenerInfo.hasFilter( @@ -203,7 +203,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase @Override public void onBinderDeath( - BinderInterfaceContainer.BinderInterface<ICarProjectionListener> bInterface) { + BinderInterfaceContainer.BinderInterface<ICarProjectionCallback> bInterface) { unregsiterProjectionListener(bInterface.binderInterface); } @@ -211,7 +211,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase public void dump(PrintWriter writer) { writer.println("**CarProjectionService**"); synchronized (this) { - for (BinderInterfaceContainer.BinderInterface<ICarProjectionListener> listener : + for (BinderInterfaceContainer.BinderInterface<ICarProjectionCallback> listener : mAllListeners.getInterfaces()) { ListenerInfo listenerInfo = (ListenerInfo) listener; writer.println(listenerInfo.toString()); @@ -219,7 +219,7 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase } } - private void dispatchVoiceAssistantRequest(ICarProjectionListener listener, + private void dispatchVoiceAssistantRequest(ICarProjectionCallback listener, boolean fromLongPress) { try { listener.onVoiceAssistantRequest(fromLongPress); @@ -227,17 +227,17 @@ class CarProjectionService extends ICarProjection.Stub implements CarServiceBase } } - private static class ListenerHolder extends BinderInterfaceContainer<ICarProjectionListener> { + private static class ListenerHolder extends BinderInterfaceContainer<ICarProjectionCallback> { private ListenerHolder(CarProjectionService service) { super(service); } } private static class ListenerInfo extends - BinderInterfaceContainer.BinderInterface<ICarProjectionListener> { + BinderInterfaceContainer.BinderInterface<ICarProjectionCallback> { private int mFilter; - private ListenerInfo(ListenerHolder holder, ICarProjectionListener binder, int filter) { + private ListenerInfo(ListenerHolder holder, ICarProjectionCallback binder, int filter) { super(holder, binder); this.mFilter = filter; } diff --git a/service/src/com/android/car/CarSensorEventFactory.java b/service/src/com/android/car/CarSensorEventFactory.java index e270eba852..fbae0edfe1 100644 --- a/service/src/com/android/car/CarSensorEventFactory.java +++ b/service/src/com/android/car/CarSensorEventFactory.java @@ -21,21 +21,21 @@ import android.car.hardware.CarSensorEvent; //TODO add memory pool and recycling public class CarSensorEventFactory { - public static CarSensorEvent createBooleanEvent(int sensorType, long timeStampNs, + public static CarSensorEvent createBooleanEvent(int sensorType, long timestamp, boolean value) { - CarSensorEvent event = new CarSensorEvent(sensorType, timeStampNs, 0, 1); + CarSensorEvent event = new CarSensorEvent(sensorType, timestamp, 0, 1); event.intValues[0] = value ? 1 : 0; return event; } - public static CarSensorEvent createIntEvent(int sensorType, long timeStampNs, int value) { - CarSensorEvent event = new CarSensorEvent(sensorType, timeStampNs, 0, 1); + public static CarSensorEvent createIntEvent(int sensorType, long timestamp, int value) { + CarSensorEvent event = new CarSensorEvent(sensorType, timestamp, 0, 1); event.intValues[0] = value; return event; } - public static CarSensorEvent createFloatEvent(int sensorType, long timeStampNs, float value) { - CarSensorEvent event = new CarSensorEvent(sensorType, timeStampNs, 1, 0); + public static CarSensorEvent createFloatEvent(int sensorType, long timestamp, float value) { + CarSensorEvent event = new CarSensorEvent(sensorType, timestamp, 1, 0); event.floatValues[0] = value; return event; } diff --git a/service/src/com/android/car/CarSensorService.java b/service/src/com/android/car/CarSensorService.java index 0c452180f1..f0bc8d11b7 100644 --- a/service/src/com/android/car/CarSensorService.java +++ b/service/src/com/android/car/CarSensorService.java @@ -16,16 +16,13 @@ package com.android.car; -import android.Manifest; import android.car.Car; import android.car.hardware.CarSensorEvent; import android.car.hardware.CarSensorManager; import android.car.hardware.ICarSensor; import android.car.hardware.ICarSensorEventListener; -import android.car.hardware.CarSensorManager.CarSensorEventListener; import android.content.Context; import android.content.pm.PackageManager; -import android.hardware.SensorEvent; import android.os.Binder; import android.os.Handler; import android.os.HandlerThread; @@ -42,13 +39,11 @@ import android.util.SparseBooleanArray; import com.android.car.hal.VehicleHal; import com.android.car.hal.SensorHalService; import com.android.car.hal.SensorHalServiceBase; -import com.android.car.hal.SensorHalServiceBase.SensorListener; import com.android.internal.annotations.GuardedBy; import java.io.PrintWriter; import java.util.Arrays; import java.util.ConcurrentModificationException; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -237,7 +232,7 @@ public class CarSensorService extends ICarSensor.Stub if (record != null) { if (record.lastEvent == null) { record.lastEvent = event; - } else if (record.lastEvent.timeStampNs < event.timeStampNs) { + } else if (record.lastEvent.timestamp < event.timestamp) { record.lastEvent = event; //TODO recycle event } else { // wrong timestamp, throw away this. 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 b5463fcc82..c9eab99bdc 100644 --- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java +++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/KitchenSinkActivity.java @@ -18,7 +18,6 @@ package com.google.android.car.kitchensink; import android.car.hardware.camera.CarCameraManager; import android.car.hardware.hvac.CarHvacManager; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -94,10 +93,10 @@ public class KitchenSinkActivity extends CarDrawerActivity { private CubesTestFragment mCubesTestFragment; private OrientationTestFragment mOrientationFragment; - private final CarSensorManager.CarSensorEventListener mListener = - new CarSensorManager.CarSensorEventListener() { + private final CarSensorManager.OnSensorChangedListener mListener = + new CarSensorManager.OnSensorChangedListener() { @Override - public void onSensorChanged(CarSensorEvent event) { + public void onSensorChanged(CarSensorManager manager, CarSensorEvent event) { switch (event.sensorType) { case CarSensorManager.SENSOR_TYPE_DRIVING_STATUS: Log.d(TAG, "driving status:" + event.intValues[0]); @@ -209,12 +208,7 @@ public class KitchenSinkActivity extends CarDrawerActivity { } @Override - public void onServiceSuspended(int cause) { - Log.d(TAG, "Car Service connection suspended"); - } - - @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { Log.d(TAG, "Car Service connection failed"); } }; 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 bafdad193b..2087e2db80 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 @@ -18,8 +18,8 @@ package com.google.android.car.kitchensink.audio; import android.car.Car; import android.car.CarAppFocusManager; -import android.car.CarAppFocusManager.AppFocusChangeListener; -import android.car.CarAppFocusManager.AppFocusOwnershipChangeListener; +import android.car.CarAppFocusManager.OnAppFocusChangedListener; +import android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener; import android.car.CarNotConnectedException; import android.car.media.CarAudioManager; import android.content.ComponentName; @@ -119,10 +119,10 @@ public class AudioTestFragment extends Fragment { } }; - private final AppFocusOwnershipChangeListener mOwnershipListener = - new AppFocusOwnershipChangeListener() { + private final CarAppFocusManager.OnAppFocusOwnershipLostListener mOwnershipListener = + new OnAppFocusOwnershipLostListener() { @Override - public void onAppFocusOwnershipLoss(int focus) { + public void onAppFocusOwnershipLost(int focus) { } }; @@ -139,14 +139,14 @@ public class AudioTestFragment extends Fragment { throw new RuntimeException("Failed to create app focus manager", e); } try { - AppFocusChangeListener listener = new AppFocusChangeListener() { + OnAppFocusChangedListener listener = new OnAppFocusChangedListener() { @Override - public void onAppFocusChange(int appType, boolean active) { + public void onAppFocusChanged(int appType, boolean active) { } }; - mAppFocusManager.registerFocusListener(listener, + mAppFocusManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); - mAppFocusManager.registerFocusListener(listener, + mAppFocusManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); } catch (CarNotConnectedException e) { Log.e(TAG, "Failed to register focus listener", e); 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 108d263934..a6bdeb8106 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 @@ -16,13 +16,10 @@ package com.google.android.car.kitchensink.cluster; import android.app.AlertDialog; -import android.content.ComponentName; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.car.Car; import android.support.car.CarAppFocusManager; -import android.support.car.CarAppFocusManager.AppFocusChangeListener; -import android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener; import android.support.car.CarNotConnectedException; import android.support.car.ServiceConnectionCallback; import android.support.car.navigation.CarNavigationStatusManager; @@ -65,12 +62,7 @@ public class InstrumentClusterFragment extends Fragment { } @Override - public void onServiceSuspended(int cause) { - Log.d(TAG, "Car Service connection suspended"); - } - - @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { Log.d(TAG, "Car Service connection failed"); } }; @@ -119,21 +111,21 @@ public class InstrumentClusterFragment extends Fragment { private void initCluster() { try { - mCarAppFocusManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, - new AppFocusChangeListener() { - @Override - public void onAppFocusChange(int appType, boolean active) { - Log.d(TAG, "onAppFocusChange, appType: " + appType + " active: " + active); - } - }); + mCarAppFocusManager.addFocusListener(new CarAppFocusManager.OnAppFocusChangedListener() { + @Override + public void onAppFocusChanged(CarAppFocusManager manager, int appType, boolean active) { + Log.d(TAG, "onAppFocusChanged, appType: " + appType + " active: " + active); + } + }, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); } catch (CarNotConnectedException e) { Log.e(TAG, "Failed to register focus listener", e); } - AppFocusOwnershipChangeListener focusListener = new AppFocusOwnershipChangeListener() { + CarAppFocusManager.OnAppFocusOwnershipLostListener + focusListener = new CarAppFocusManager.OnAppFocusOwnershipLostListener() { @Override - public void onAppFocusOwnershipLoss(int focus) { - Log.w(TAG, "onAppFocusOwnershipLoss, focus: " + focus); + public void onAppFocusOwnershipLost(CarAppFocusManager manager, int focus) { + Log.w(TAG, "onAppFocusOwnershipLost, focus: " + focus); new AlertDialog.Builder(getContext()) .setTitle(getContext().getApplicationInfo().name) .setMessage(R.string.cluster_nav_app_context_loss) diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/keyboard/KeyboardFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/keyboard/KeyboardFragment.java index efa2f3d831..b8b97086ea 100644 --- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/keyboard/KeyboardFragment.java +++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/keyboard/KeyboardFragment.java @@ -99,7 +99,7 @@ public class KeyboardFragment extends Fragment { try { mSensorManager = (CarSensorManager) mActivity.getCar().getCarManager(Car.SENSOR_SERVICE); - mSensorManager.addListener(mCarSensorListener, + mSensorManager.addListener(mOnSensorChangedListener, CarSensorManager.SENSOR_TYPE_DRIVING_STATUS, CarSensorManager.SENSOR_RATE_FASTEST); } catch (CarNotConnectedException e) { @@ -112,17 +112,17 @@ public class KeyboardFragment extends Fragment { super.onPause(); if (mSensorManager != null) { try { - mSensorManager.removeListener(mCarSensorListener); + mSensorManager.removeListener(mOnSensorChangedListener); } catch (CarNotConnectedException e) { Log.e(TAG, "Car not connected", e); } } } - private final CarSensorManager.CarSensorEventListener mCarSensorListener = - new CarSensorManager.CarSensorEventListener() { + private final CarSensorManager.OnSensorChangedListener mOnSensorChangedListener = + new CarSensorManager.OnSensorChangedListener() { @Override - public void onSensorChanged(CarSensorEvent event) { + public void onSensorChanged(CarSensorManager manager, CarSensorEvent event) { if (event.sensorType != CarSensorManager.SENSOR_TYPE_DRIVING_STATUS) { return; } diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java index 1c13e37bee..d563a9a97f 100644 --- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java +++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/sensor/SensorsTestFragment.java @@ -61,10 +61,10 @@ public class SensorsTestFragment extends Fragment { Car.PERMISSION_SPEED }; - private final CarSensorManager.CarSensorEventListener mCarSensorListener = - new CarSensorManager.CarSensorEventListener() { + private final CarSensorManager.OnSensorChangedListener mOnSensorChangedListener = + new CarSensorManager.OnSensorChangedListener() { @Override - public void onSensorChanged(CarSensorEvent event) { + public void onSensorChanged(CarSensorManager manager, CarSensorEvent event) { if (DBG_VERBOSE) { Log.v(TAG, "New car sensor event: " + event); } @@ -115,7 +115,7 @@ public class SensorsTestFragment extends Fragment { super.onPause(); if (mSensorManager != null) { try { - mSensorManager.removeListener(mCarSensorListener); + mSensorManager.removeListener(mOnSensorChangedListener); } catch (CarNotConnectedException e) { Log.e(TAG, "Car not connected", e); } @@ -133,7 +133,7 @@ public class SensorsTestFragment extends Fragment { && !mActivePermissions.contains(Manifest.permission.ACCESS_FINE_LOCATION)) { continue; } - mSensorManager.addListener(mCarSensorListener, sensor, + mSensorManager.addListener(mOnSensorChangedListener, sensor, CarSensorManager.SENSOR_RATE_NORMAL); } } catch (CarNotConnectedException e) { @@ -295,7 +295,7 @@ public class SensorsTestFragment extends Fragment { if (event == null) { return mNaString; } - return mDateFormat.format(new Date(event.timeStampNs / 1000L)); + return mDateFormat.format(new Date(event.timestamp / 1000L)); } private String getCompassString(CarSensorEvent event) { diff --git a/tests/android_car_api_test/src/android/car/apitest/CarApiUtilTest.java b/tests/android_car_api_test/src/android/car/apitest/CarApiUtilTest.java index 8ec85b40fc..f5b473c28f 100644 --- a/tests/android_car_api_test/src/android/car/apitest/CarApiUtilTest.java +++ b/tests/android_car_api_test/src/android/car/apitest/CarApiUtilTest.java @@ -18,7 +18,7 @@ package android.car.apitest; import android.car.Car; import android.car.CarApiUtil; import android.car.CarNotConnectedException; -import android.car.CarNotSupportedException; +import android.car.CarOperationNotSupportedException; import android.car.settings.CarSettings; import junit.framework.TestCase; @@ -97,7 +97,7 @@ public class CarApiUtilTest extends TestCase { } catch (Exception exception) { resultException = exception; } - assertTrue(resultException instanceof CarNotSupportedException); + assertTrue(resultException instanceof CarOperationNotSupportedException); e = new IllegalStateException("Hello"); resultException = null; diff --git a/tests/android_car_api_test/src/android/car/apitest/CarAppFocusManagerTest.java b/tests/android_car_api_test/src/android/car/apitest/CarAppFocusManagerTest.java index ba389070b8..17de9bf4cb 100644 --- a/tests/android_car_api_test/src/android/car/apitest/CarAppFocusManagerTest.java +++ b/tests/android_car_api_test/src/android/car/apitest/CarAppFocusManagerTest.java @@ -48,7 +48,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { // Request all application focuses and abandon them to ensure no active context is present // when test starts. - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); mManager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, owner); mManager.requestAppFocus(APP_FOCUS_TYPE_VOICE_COMMAND, owner); mManager.abandonAppFocus(owner); @@ -68,7 +68,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { public void testRegisterNull() throws Exception { try { - mManager.registerFocusListener(null, 0); + mManager.addFocusListener(null, 0); fail(); } catch (IllegalArgumentException e) { // expected @@ -76,27 +76,27 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } public void testRegisterUnregister() throws Exception { - FocusChangeListener listener = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - mManager.registerFocusListener(listener, 1); - mManager.registerFocusListener(listener2, 1); - mManager.unregisterFocusListener(listener); - mManager.unregisterFocusListener(listener2); - mManager.unregisterFocusListener(listener2); // Double-unregister is OK + FocusChangedListener listener = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + mManager.addFocusListener(listener, 1); + mManager.addFocusListener(listener2, 1); + mManager.removeFocusListener(listener); + mManager.removeFocusListener(listener2); + mManager.removeFocusListener(listener2); // Double-unregister is OK } public void testRegisterUnregisterSpecificApp() throws Exception { - FocusChangeListener listener1 = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); + FocusChangedListener listener1 = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); CarAppFocusManager manager = createManager(); - manager.registerFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); - manager.registerFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); - manager.registerFocusListener(listener2, APP_FOCUS_TYPE_VOICE_COMMAND); + manager.addFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); + manager.addFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); + manager.addFocusListener(listener2, APP_FOCUS_TYPE_VOICE_COMMAND); - manager.unregisterFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); + manager.removeFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); - manager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, new FocusOwnershipChangeListener()); + manager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, new FocusOwnershipLostListener()); // Unregistred from nav app, no events expected. assertFalse(listener1.waitForFocusChangeAndAssert( @@ -104,16 +104,16 @@ public class CarAppFocusManagerTest extends CarApiTestBase { assertTrue(listener2.waitForFocusChangeAndAssert( DEFAULT_WAIT_TIMEOUT_MS, APP_FOCUS_TYPE_NAVIGATION, true)); - manager.unregisterFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); - manager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, new FocusOwnershipChangeListener()); + manager.removeFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); + manager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, new FocusOwnershipLostListener()); assertFalse(listener2.waitForFocusChangeAndAssert( DEFAULT_WAIT_TIMEOUT_MS, APP_FOCUS_TYPE_NAVIGATION, true)); - manager.requestAppFocus(APP_FOCUS_TYPE_VOICE_COMMAND, new FocusOwnershipChangeListener()); + manager.requestAppFocus(APP_FOCUS_TYPE_VOICE_COMMAND, new FocusOwnershipLostListener()); assertTrue(listener2.waitForFocusChangeAndAssert( DEFAULT_WAIT_TIMEOUT_MS, APP_FOCUS_TYPE_VOICE_COMMAND, true)); - manager.unregisterFocusListener(listener2, 2); - manager.unregisterFocusListener(listener2, 2); // Double-unregister is OK + manager.removeFocusListener(listener2, 2); + manager.removeFocusListener(listener2, 2); // Double-unregister is OK } public void testFocusChange() throws Exception { @@ -123,14 +123,14 @@ public class CarAppFocusManagerTest extends CarApiTestBase { final int[] emptyFocus = new int[0]; Assert.assertArrayEquals(emptyFocus, manager1.getActiveAppTypes()); - FocusChangeListener change1 = new FocusChangeListener(); - FocusChangeListener change2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner1 = new FocusOwnershipChangeListener(); - FocusOwnershipChangeListener owner2 = new FocusOwnershipChangeListener(); - manager1.registerFocusListener(change1, APP_FOCUS_TYPE_NAVIGATION); - manager1.registerFocusListener(change1, APP_FOCUS_TYPE_VOICE_COMMAND); - manager2.registerFocusListener(change2, APP_FOCUS_TYPE_NAVIGATION); - manager2.registerFocusListener(change2, APP_FOCUS_TYPE_VOICE_COMMAND); + FocusChangedListener change1 = new FocusChangedListener(); + FocusChangedListener change2 = new FocusChangedListener(); + FocusOwnershipLostListener owner1 = new FocusOwnershipLostListener(); + FocusOwnershipLostListener owner2 = new FocusOwnershipLostListener(); + manager1.addFocusListener(change1, APP_FOCUS_TYPE_NAVIGATION); + manager1.addFocusListener(change1, APP_FOCUS_TYPE_VOICE_COMMAND); + manager2.addFocusListener(change2, APP_FOCUS_TYPE_NAVIGATION); + manager2.addFocusListener(change2, APP_FOCUS_TYPE_VOICE_COMMAND); manager1.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, owner1); int[] expectedFocuses = new int[] {APP_FOCUS_TYPE_NAVIGATION}; @@ -226,8 +226,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { assertTrue(change1.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, APP_FOCUS_TYPE_NAVIGATION, false)); - manager1.unregisterFocusListener(change1); - manager2.unregisterFocusListener(change2); + manager1.removeFocusListener(change1); + manager2.removeFocusListener(change2); } public void testFilter() throws Exception { @@ -237,12 +237,12 @@ public class CarAppFocusManagerTest extends CarApiTestBase { Assert.assertArrayEquals(new int[0], manager1.getActiveAppTypes()); Assert.assertArrayEquals(new int[0], manager2.getActiveAppTypes()); - FocusChangeListener listener1 = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); - manager1.registerFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); - manager1.registerFocusListener(listener1, APP_FOCUS_TYPE_VOICE_COMMAND); - manager2.registerFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); + FocusChangedListener listener1 = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); + manager1.addFocusListener(listener1, APP_FOCUS_TYPE_NAVIGATION); + manager1.addFocusListener(listener1, APP_FOCUS_TYPE_VOICE_COMMAND); + manager2.addFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); assertEquals(APP_FOCUS_REQUEST_GRANTED, manager1.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, owner)); @@ -303,12 +303,12 @@ public class CarAppFocusManagerTest extends CarApiTestBase { public void testMultipleChangeListenersPerManager() throws Exception { CarAppFocusManager manager = createManager(); - FocusChangeListener listener = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); - manager.registerFocusListener(listener, APP_FOCUS_TYPE_NAVIGATION); - manager.registerFocusListener(listener, APP_FOCUS_TYPE_VOICE_COMMAND); - manager.registerFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); + FocusChangedListener listener = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); + manager.addFocusListener(listener, APP_FOCUS_TYPE_NAVIGATION); + manager.addFocusListener(listener, APP_FOCUS_TYPE_VOICE_COMMAND); + manager.addFocusListener(listener2, APP_FOCUS_TYPE_NAVIGATION); manager.requestAppFocus(APP_FOCUS_TYPE_NAVIGATION, owner); assertTrue(listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, @@ -341,7 +341,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { APP_FOCUS_TYPE_NAVIGATION, false)); } - private class FocusChangeListener implements CarAppFocusManager.AppFocusChangeListener { + private class FocusChangedListener implements CarAppFocusManager.OnAppFocusChangedListener { private volatile int mLastChangeAppType; private volatile boolean mLastChangeAppActive; private volatile Semaphore mChangeWait = new Semaphore(0); @@ -365,7 +365,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } @Override - public void onAppFocusChange(int appType, boolean active) { + public void onAppFocusChanged(int appType, boolean active) { assertEventThread(); mLastChangeAppType = appType; mLastChangeAppActive = active; @@ -373,8 +373,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } } - private class FocusOwnershipChangeListener - implements CarAppFocusManager.AppFocusOwnershipChangeListener { + private class FocusOwnershipLostListener + implements CarAppFocusManager.OnAppFocusOwnershipLostListener { private int mLastLossEvent; private final Semaphore mLossEventWait = new Semaphore(0); @@ -388,8 +388,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } @Override - public void onAppFocusOwnershipLoss(int appType) { - Log.i(TAG, "onAppFocusOwnershipLoss " + appType); + public void onAppFocusOwnershipLost(int appType) { + Log.i(TAG, "onAppFocusOwnershipLost " + appType); assertEventThread(); mLastLossEvent = appType; mLossEventWait.release(); diff --git a/tests/android_car_api_test/src/android/car/apitest/CarNavigationManagerTest.java b/tests/android_car_api_test/src/android/car/apitest/CarNavigationManagerTest.java index 0d9ea2baeb..1a6811b752 100644 --- a/tests/android_car_api_test/src/android/car/apitest/CarNavigationManagerTest.java +++ b/tests/android_car_api_test/src/android/car/apitest/CarNavigationManagerTest.java @@ -17,8 +17,7 @@ package android.car.apitest; import android.car.Car; import android.car.CarAppFocusManager; -import android.car.CarAppFocusManager.AppFocusChangeListener; -import android.car.CarAppFocusManager.AppFocusOwnershipChangeListener; +import android.car.CarAppFocusManager.OnAppFocusOwnershipLostListener; import android.car.navigation.CarNavigationManager; import android.test.suitebuilder.annotation.MediumTest; import android.util.Log; @@ -58,15 +57,15 @@ public class CarNavigationManagerTest extends CarApiTestBase { // Expected. Client should acquire focus ownership for APP_FOCUS_TYPE_NAVIGATION. } - mCarAppFocusManager.registerFocusListener(new AppFocusChangeListener() { + mCarAppFocusManager.addFocusListener(new CarAppFocusManager.OnAppFocusChangedListener() { @Override - public void onAppFocusChange(int appType, boolean active) { + public void onAppFocusChanged(int appType, boolean active) { // Nothing to do here. } }, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); - AppFocusOwnershipChangeListener ownershipListener = new AppFocusOwnershipChangeListener() { + OnAppFocusOwnershipLostListener ownershipListener = new OnAppFocusOwnershipLostListener() { @Override - public void onAppFocusOwnershipLoss(int focus) { + public void onAppFocusOwnershipLost(int focus) { // Nothing to do here. } }; diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarApiTestBase.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarApiTestBase.java index 7a16dd3714..cf9866bf2e 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarApiTestBase.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarApiTestBase.java @@ -61,19 +61,13 @@ public class CarApiTestBase extends AndroidTestCase { public void waitForConnection(long timeoutMs) throws InterruptedException { mConnectionWait.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS); } - - @Override - public void onServiceSuspended(int cause) { - assertMainThread(); - } - @Override public void onServiceDisconnected() { assertMainThread(); } @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { assertMainThread(); } diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarAppFocusManagerTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarAppFocusManagerTest.java index fa97882fd7..6b5ec52eca 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarAppFocusManagerTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarAppFocusManagerTest.java @@ -36,7 +36,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { // Request all application focuses and abandon them to ensure no active context is present // when test starts. - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); mManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, owner); mManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, owner); mManager.abandonAppFocus(owner); @@ -53,7 +53,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { public void testRegisterNull() throws Exception { try { - mManager.addFocusListener(0, null); + mManager.addFocusListener(null, 0); fail(); } catch (IllegalArgumentException e) { // expected @@ -61,10 +61,10 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } public void testRegisterUnregister() throws Exception { - FocusChangeListener listener = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - mManager.addFocusListener(1, listener); - mManager.addFocusListener(1, listener2); + FocusChangedListener listener = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + mManager.addFocusListener(listener, 1); + mManager.addFocusListener(listener2, 1); mManager.removeFocusListener(listener); mManager.removeFocusListener(listener2); } @@ -80,14 +80,14 @@ public class CarAppFocusManagerTest extends CarApiTestBase { assertNotNull(manager2); final int[] emptyFocus = new int[0]; - FocusChangeListener change = new FocusChangeListener(); - FocusChangeListener change2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); - FocusOwnershipChangeListener owner2 = new FocusOwnershipChangeListener(); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, change); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, change); - manager2.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, change2); - manager2.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, change2); + FocusChangedListener change = new FocusChangedListener(); + FocusChangedListener change2 = new FocusChangedListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); + FocusOwnershipLostListener owner2 = new FocusOwnershipLostListener(); + mManager.addFocusListener(change, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); + mManager.addFocusListener(change, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); + manager2.addFocusListener(change2, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); + manager2.addFocusListener(change2, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); mManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, owner); assertTrue(mManager.isOwningFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, owner)); @@ -172,12 +172,12 @@ public class CarAppFocusManagerTest extends CarApiTestBase { car2.getCarManager(Car.APP_FOCUS_SERVICE); assertNotNull(manager2); - FocusChangeListener listener = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, listener); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, listener); - manager2.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, listener2); + FocusChangedListener listener = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); + mManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); + mManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); + manager2.addFocusListener(listener2, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); mManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, owner); assertTrue(listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, @@ -211,12 +211,12 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } public void testMultipleChangeListenersPerManager() throws Exception { - FocusChangeListener listener = new FocusChangeListener(); - FocusChangeListener listener2 = new FocusChangeListener(); - FocusOwnershipChangeListener owner = new FocusOwnershipChangeListener(); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, listener); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, listener); - mManager.addFocusListener(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, listener2); + FocusChangedListener listener = new FocusChangedListener(); + FocusChangedListener listener2 = new FocusChangedListener(); + FocusOwnershipLostListener owner = new FocusOwnershipLostListener(); + mManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); + mManager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); + mManager.addFocusListener(listener2, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); mManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, owner); assertTrue(listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, @@ -249,7 +249,7 @@ public class CarAppFocusManagerTest extends CarApiTestBase { CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, false)); } - private class FocusChangeListener implements CarAppFocusManager.AppFocusChangeListener { + private class FocusChangedListener implements CarAppFocusManager.OnAppFocusChangedListener { private int mLastChangeAppType; private boolean mLastChangeAppActive; private final Semaphore mChangeWait = new Semaphore(0); @@ -270,8 +270,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } @Override - public void onAppFocusChange(int appType, boolean active) { - Log.i(TAG, "onAppFocusChange appType=" + appType + " active=" + active); + public void onAppFocusChanged(CarAppFocusManager manager, int appType, boolean active) { + Log.i(TAG, "onAppFocusChanged appType=" + appType + " active=" + active); assertMainThread(); mLastChangeAppType = appType; mLastChangeAppActive = active; @@ -279,8 +279,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } } - private class FocusOwnershipChangeListener - implements CarAppFocusManager.AppFocusOwnershipChangeListener { + private class FocusOwnershipLostListener + implements CarAppFocusManager.OnAppFocusOwnershipLostListener { private int mLastLossEvent; private final Semaphore mLossEventWait = new Semaphore(0); @@ -294,8 +294,8 @@ public class CarAppFocusManagerTest extends CarApiTestBase { } @Override - public void onAppFocusOwnershipLoss(int appType) { - Log.i(TAG, "onAppFocusOwnershipLoss " + appType); + public void onAppFocusOwnershipLost(CarAppFocusManager manager, int appType) { + Log.i(TAG, "onAppFocusOwnershipLost " + appType); assertMainThread(); mLastLossEvent = appType; mLossEventWait.release(); diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarConnectionCallbackTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarConnectionCallbackTest.java index e3cc87bb92..4ae66853b7 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarConnectionCallbackTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarConnectionCallbackTest.java @@ -53,7 +53,7 @@ public class CarConnectionCallbackTest extends CarApiTestBase { private Semaphore mWaitSemaphore = new Semaphore(0); @Override - public void onConnected(int connectionType) { + public void onConnected(Car car, int connectionType) { Log.i(TAG, "onConnected " + connectionType); mConnectionType = connectionType; mIsConnected = true; @@ -61,7 +61,7 @@ public class CarConnectionCallbackTest extends CarApiTestBase { } @Override - public void onDisconnected() { + public void onDisconnected(Car car) { Log.i(TAG, "onDisconnected"); mIsConnected = false; mWaitSemaphore.release(); diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarNavigationStatusManagerTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarNavigationStatusManagerTest.java index a00f9b8c25..adebe70d39 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarNavigationStatusManagerTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarNavigationStatusManagerTest.java @@ -19,11 +19,10 @@ import static android.support.car.CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION; import android.support.car.Car; import android.support.car.CarAppFocusManager; -import android.support.car.CarAppFocusManager.AppFocusChangeListener; -import android.support.car.CarAppFocusManager.AppFocusOwnershipChangeListener; +import android.support.car.CarAppFocusManager.OnAppFocusChangedListener; +import android.support.car.CarAppFocusManager.OnAppFocusOwnershipLostListener; import android.support.car.navigation.CarNavigationInstrumentCluster; import android.support.car.navigation.CarNavigationStatusManager; -import android.support.car.navigation.CarNavigationStatusManager.CarNavigationListener; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -50,9 +49,10 @@ public class CarNavigationStatusManagerTest extends CarApiTestBase { public void testStart() throws Exception { final CountDownLatch onStartLatch = new CountDownLatch(1); - mCarNavigationStatusManager.addListener(new CarNavigationListener() { + mCarNavigationStatusManager.addListener(new CarNavigationStatusManager.CarNavigationCallback() { @Override - public void onInstrumentClusterStart(CarNavigationInstrumentCluster instrumentCluster) { + public void onInstrumentClusterStarted(CarNavigationStatusManager manager, + CarNavigationInstrumentCluster instrumentCluster) { // TODO: we should use VehicleHalMock once we implement HAL support in // CarNavigationStatusService. assertFalse(instrumentCluster.supportsCustomImages()); @@ -61,7 +61,7 @@ public class CarNavigationStatusManagerTest extends CarApiTestBase { } @Override - public void onInstrumentClusterStop() { + public void onInstrumentClusterStopped(CarNavigationStatusManager manager) { // TODO } }); @@ -76,15 +76,17 @@ public class CarNavigationStatusManagerTest extends CarApiTestBase { } mCarAppFocusManager - .addFocusListener(APP_FOCUS_TYPE_NAVIGATION, new AppFocusChangeListener() { + .addFocusListener(new OnAppFocusChangedListener() { @Override - public void onAppFocusChange(int appType, boolean active) { + public void onAppFocusChanged(CarAppFocusManager manager, int appType, + boolean active) { // Nothing to do here. } - }); - AppFocusOwnershipChangeListener ownershipListener = new AppFocusOwnershipChangeListener() { + }, APP_FOCUS_TYPE_NAVIGATION); + CarAppFocusManager.OnAppFocusOwnershipLostListener + ownershipListener = new OnAppFocusOwnershipLostListener() { @Override - public void onAppFocusOwnershipLoss(int focus) { + public void onAppFocusOwnershipLost(CarAppFocusManager manager, int focus) { // Nothing to do here. } }; diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarPackageManagerTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarPackageManagerTest.java index 8b0087fda7..dd279e6d1e 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarPackageManagerTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarPackageManagerTest.java @@ -38,19 +38,13 @@ public class CarPackageManagerTest extends AndroidTestCase { private final ServiceConnectionCallback mConnectionCallbacks = new ServiceConnectionCallback() { - - @Override - public void onServiceSuspended(int cause) { - assertMainThread(); - } - @Override public void onServiceDisconnected() { assertMainThread(); } @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { assertMainThread(); } diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java index b191f61ee8..09fcd5ae33 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarSensorManagerTest.java @@ -43,19 +43,13 @@ public class CarSensorManagerTest extends AndroidTestCase { private final ServiceConnectionCallback mConnectionCallbacks = new ServiceConnectionCallback() { - - @Override - public void onServiceSuspended(int cause) { - assertMainThread(); - } - @Override public void onServiceDisconnected() { assertMainThread(); } @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { assertMainThread(); } diff --git a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarTest.java b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarTest.java index 95afac362f..a9eee69df2 100644 --- a/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarTest.java +++ b/tests/android_support_car_api_test/src/com/android/support/car/apitest/CarTest.java @@ -37,17 +37,12 @@ public class CarTest extends AndroidTestCase { new ServiceConnectionCallback() { @Override - public void onServiceSuspended(int cause) { - assertMainThread(); - } - - @Override public void onServiceDisconnected() { assertMainThread(); } @Override - public void onServiceConnectionFailed(int cause) { + public void onServiceConnectionFailed() { assertMainThread(); } diff --git a/tests/carservice_test/src/com/android/car/test/AppFocusTest.java b/tests/carservice_test/src/com/android/car/test/AppFocusTest.java index ca88bc1464..4d3ef5012c 100644 --- a/tests/carservice_test/src/com/android/car/test/AppFocusTest.java +++ b/tests/carservice_test/src/com/android/car/test/AppFocusTest.java @@ -20,8 +20,6 @@ import android.car.CarAppFocusManager; import android.test.suitebuilder.annotation.MediumTest; import android.util.Log; -import com.android.car.test.MockedCarTestBase; - import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -39,10 +37,10 @@ public class AppFocusTest extends MockedCarTestBase { public void testFocusChange() throws Exception { CarAppFocusManager manager = (CarAppFocusManager) getCar().getCarManager( Car.APP_FOCUS_SERVICE); - FocusChangeListener listener = new FocusChangeListener(); - FocusOwnershipChangeListerner ownershipListener = new FocusOwnershipChangeListerner(); - manager.registerFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); - manager.registerFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); + FocusChangedListener listener = new FocusChangedListener(); + FocusOwnershipLostListerner ownershipListener = new FocusOwnershipLostListerner(); + manager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); + manager.addFocusListener(listener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); manager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, ownershipListener); listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, true); @@ -55,10 +53,10 @@ public class AppFocusTest extends MockedCarTestBase { manager.abandonAppFocus(ownershipListener, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND); listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS, CarAppFocusManager.APP_FOCUS_TYPE_VOICE_COMMAND, false); - manager.unregisterFocusListener(listener); + manager.removeFocusListener(listener); } - private class FocusChangeListener implements CarAppFocusManager.AppFocusChangeListener { + private class FocusChangedListener implements CarAppFocusManager.OnAppFocusChangedListener { private int mLastChangeAppType; private boolean mLastChangeAppActive; private final Semaphore mChangeWait = new Semaphore(0); @@ -74,16 +72,16 @@ public class AppFocusTest extends MockedCarTestBase { } @Override - public void onAppFocusChange(int appType, boolean active) { - Log.i(TAG, "onAppFocusChange appType=" + appType + " active=" + active); + public void onAppFocusChanged(int appType, boolean active) { + Log.i(TAG, "onAppFocusChanged appType=" + appType + " active=" + active); mLastChangeAppType = appType; mLastChangeAppActive = active; mChangeWait.release(); } } - private class FocusOwnershipChangeListerner - implements CarAppFocusManager.AppFocusOwnershipChangeListener { + private class FocusOwnershipLostListerner + implements CarAppFocusManager.OnAppFocusOwnershipLostListener { private int mLastLossEvent; private final Semaphore mLossEventWait = new Semaphore(0); @@ -97,8 +95,8 @@ public class AppFocusTest extends MockedCarTestBase { } @Override - public void onAppFocusOwnershipLoss(int appType) { - Log.i(TAG, "onAppFocusOwnershipLoss " + appType); + public void onAppFocusOwnershipLost(int appType) { + Log.i(TAG, "onAppFocusOwnershipLost " + appType); mLastLossEvent = appType; mLossEventWait.release(); } |