Car Managers for driving state & UX restrictions

Adding new Car Managers and Services to expose the car's driving
state and the mapped UX Restrictions for that driving state.
CarDrivingStateManager is exposed as a SystemApi, whereas
CarUXRestrictionsManager is exposed as a public API for apps to react.

Bug: b/68716688, b/69859786, b/72052159
Test: KitchenSink app can listen to both driving state and UXR changes.

Change-Id: I962e0bdde4ceef5be203409ca26cf51a68dd84ca
diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java
index bd3b6b7..7d7cb67 100644
--- a/service/src/com/android/car/ICarImpl.java
+++ b/service/src/com/android/car/ICarImpl.java
@@ -59,6 +59,8 @@
     private final CarPackageManagerService mCarPackageManagerService;
     private final CarInputService mCarInputService;
     private final CarSensorService mCarSensorService;
+    private final CarDrivingStateService mCarDrivingStateService;
+    private final CarUXRestrictionsService mCarUXRestrictionsService;
     private final CarInfoService mCarInfoService;
     private final CarAudioService mCarAudioService;
     private final CarProjectionService mCarProjectionService;
@@ -102,6 +104,9 @@
         mCarPowerManagementService = new CarPowerManagementService(
                 mHal.getPowerHal(), systemInterface);
         mCarSensorService = new CarSensorService(serviceContext, mHal.getSensorHal());
+        mCarDrivingStateService = new CarDrivingStateService(serviceContext, mCarSensorService);
+        mCarUXRestrictionsService = new CarUXRestrictionsService(serviceContext,
+                mCarDrivingStateService);
         mCarPackageManagerService = new CarPackageManagerService(serviceContext, mCarSensorService,
                 mSystemActivityMonitoringService);
         mCarInputService = new CarInputService(serviceContext, mHal.getInputHal());
@@ -135,6 +140,8 @@
                 mSystemActivityMonitoringService,
                 mCarPowerManagementService,
                 mCarSensorService,
+                mCarDrivingStateService,
+                mCarUXRestrictionsService,
                 mCarPackageManagerService,
                 mCarInputService,
                 mGarageModeService,
@@ -253,6 +260,11 @@
             case Car.STORAGE_MONITORING_SERVICE:
                 assertPermission(mContext, Car.PERMISSION_STORAGE_MONITORING);
                 return mCarStorageMonitoringService;
+            case Car.CAR_DRIVING_STATE_SERVICE:
+                assertDrivingStatePermission(mContext);
+                return mCarDrivingStateService;
+            case Car.CAR_UX_RESTRICTION_SERVICE:
+                return mCarUXRestrictionsService;
             default:
                 Log.w(CarLog.TAG_SERVICE, "getCarService for unknown service:" + serviceName);
                 return null;
@@ -315,6 +327,10 @@
                 Car.PERMISSION_CAR_DIAGNOSTIC_CLEAR);
     }
 
+    public static void assertDrivingStatePermission(Context context) {
+        assertPermission(context, Car.PERMISSION_CAR_DRIVING_STATE);
+    }
+
     @FutureFeature
     public static void assertVmsPublisherPermission(Context context) {
         assertPermission(context, Car.PERMISSION_VMS_PUBLISHER);
@@ -533,6 +549,5 @@
             }
             mHal.injectIntegerEvent(propId, eventValue);
         }
-
     }
 }