summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius D'Souza <jdsouza@google.com>2021-01-20 18:30:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-01-20 18:30:32 +0000
commite31d545062f13822f9bf50d226bbe16b3fc1acb3 (patch)
tree4f580ab245b778edd379f00b698f2edbc1a4c193
parent1cb2e904fad9780aa4eef3b6a73c411ef0cc94e1 (diff)
parent1adc9e0804e2254d3977bd160d74bf28ecb29f29 (diff)
downloadsetupwizard-e31d545062f13822f9bf50d226bbe16b3fc1acb3.tar.gz
Merge "DO NOT MERGE: Graft gear reversal logic to RVC." into rvc-qpr-dev
-rw-r--r--library/main/src/com/android/car/setupwizardlib/util/CarDrivingStateMonitor.java91
1 files changed, 79 insertions, 12 deletions
diff --git a/library/main/src/com/android/car/setupwizardlib/util/CarDrivingStateMonitor.java b/library/main/src/com/android/car/setupwizardlib/util/CarDrivingStateMonitor.java
index 5bf7bf7..c58e352 100644
--- a/library/main/src/com/android/car/setupwizardlib/util/CarDrivingStateMonitor.java
+++ b/library/main/src/com/android/car/setupwizardlib/util/CarDrivingStateMonitor.java
@@ -18,8 +18,13 @@ package com.android.car.setupwizardlib.util;
import android.car.Car;
import android.car.CarNotConnectedException;
+import android.car.VehicleAreaType;
+import android.car.VehicleGear;
+import android.car.VehiclePropertyIds;
import android.car.drivingstate.CarUxRestrictions;
import android.car.drivingstate.CarUxRestrictionsManager;
+import android.car.hardware.CarPropertyValue;
+import android.car.hardware.property.CarPropertyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -43,11 +48,15 @@ public class CarDrivingStateMonitor implements
public static final String EXIT_BROADCAST_ACTION =
"com.android.car.setupwizardlib.driving_exit";
+ public static final String INTENT_EXTRA_REASON = "reason";
+ public static final String REASON_GEAR_REVERSAL = "gear_reversal";
+
private static final String TAG = "CarDrivingStateMonitor";
private static final long DISCONNECT_DELAY_MS = 700;
private Car mCar;
private CarUxRestrictionsManager mRestrictionsManager;
+ private CarPropertyManager mCarPropertyManager;
// Need to track the number of times the monitor is started so a single stopMonitor call does
// not override them all.
private int mMonitorStartedCount;
@@ -61,6 +70,25 @@ public class CarDrivingStateMonitor implements
@VisibleForTesting
final Runnable mDisconnectRunnable = this::disconnectCarMonitor;
+ private final CarPropertyManager.CarPropertyEventCallback mGearChangeCallback =
+ new CarPropertyManager.CarPropertyEventCallback() {
+ @SuppressWarnings("rawtypes")
+ @Override
+ public void onChangeEvent(CarPropertyValue value) {
+ switch (value.getPropertyId()) {
+ case VehiclePropertyIds.GEAR_SELECTION:
+ if ((Integer) value.getValue() == VehicleGear.GEAR_REVERSE) {
+ Log.v(TAG, "Gear has reversed, exiting SetupWizard.");
+ broadcastGearReversal();
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void onErrorEvent(int propertyId, int zone) {}
+ };
+
private CarDrivingStateMonitor(Context context) {
mContext = context.getApplicationContext();
}
@@ -108,18 +136,9 @@ public class CarDrivingStateMonitor implements
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
- mRestrictionsManager = (CarUxRestrictionsManager)
- mCar.getCarManager(Car.CAR_UX_RESTRICTION_SERVICE);
- if (mRestrictionsManager == null) {
- Log.e(TAG, "Unable to get CarUxRestrictionsManager");
- return;
- }
- onUxRestrictionsChanged(mRestrictionsManager.getCurrentCarUxRestrictions());
- mRestrictionsManager.registerListener(CarDrivingStateMonitor.this);
- if (mStopMonitorAfterUxCheck) {
- mStopMonitorAfterUxCheck = false;
- stopMonitor();
- }
+ registerPropertyManager();
+ registerRestrictionsManager();
+
} catch (CarNotConnectedException e) {
Log.e(TAG, "Car not connected", e);
}
@@ -181,6 +200,10 @@ public class CarDrivingStateMonitor implements
mRestrictionsManager.unregisterListener();
mRestrictionsManager = null;
}
+ if (mCarPropertyManager != null) {
+ mCarPropertyManager.unregisterCallback(mGearChangeCallback);
+ mCarPropertyManager = null;
+ }
} catch (CarNotConnectedException e) {
Log.e(TAG, "Car not connected for unregistering listener", e);
}
@@ -286,4 +309,48 @@ public class CarDrivingStateMonitor implements
CarHelperRegistry.getRegistry(context).putHelper(CarDrivingStateMonitor.class, monitor);
}
+ private void registerRestrictionsManager() {
+ mRestrictionsManager = (CarUxRestrictionsManager)
+ mCar.getCarManager(Car.CAR_UX_RESTRICTION_SERVICE);
+ if (mRestrictionsManager == null) {
+ Log.e(TAG, "Unable to get CarUxRestrictionsManager");
+ return;
+ }
+ onUxRestrictionsChanged(mRestrictionsManager.getCurrentCarUxRestrictions());
+ mRestrictionsManager.registerListener(CarDrivingStateMonitor.this);
+ if (mStopMonitorAfterUxCheck) {
+ mStopMonitorAfterUxCheck = false;
+ stopMonitor();
+ }
+ }
+
+ private void registerPropertyManager() {
+ mCarPropertyManager = (CarPropertyManager) mCar.getCarManager(Car.PROPERTY_SERVICE);
+ if (mCarPropertyManager == null) {
+ Log.e(TAG, "Unable to get CarPropertyManager");
+ return;
+ }
+ mCarPropertyManager.registerCallback(
+ mGearChangeCallback, VehiclePropertyIds.GEAR_SELECTION,
+ CarPropertyManager.SENSOR_RATE_ONCHANGE);
+ CarPropertyValue<Integer> gearSelection =
+ mCarPropertyManager.getProperty(Integer.class, VehiclePropertyIds.GEAR_SELECTION,
+ VehicleAreaType.VEHICLE_AREA_TYPE_GLOBAL);
+ if (gearSelection != null
+ && gearSelection.getStatus() == CarPropertyValue.STATUS_AVAILABLE) {
+ if (gearSelection.getValue() == VehicleGear.GEAR_REVERSE) {
+ Log.v(TAG, "SetupWizard started when gear is in reverse, exiting.");
+ broadcastGearReversal();
+ }
+ } else {
+ Log.e(TAG, "GEAR_SELECTION is not available.");
+ }
+ }
+
+ private void broadcastGearReversal() {
+ Intent intent = new Intent();
+ intent.setAction(EXIT_BROADCAST_ACTION);
+ intent.putExtra(INTENT_EXTRA_REASON, REASON_GEAR_REVERSAL);
+ mContext.sendBroadcast(intent);
+ }
}