Use the correct car-lib api for the system version

There are 2 versions of the car-lib api, one that
works everywhere but sometimes crashes, and one
that only works on R+. Previously car-ui-lib
only used the Q version on google3. Change
car-ui-lib to use the correct version based
on the system the app is running on.

Fixes: 172610002
Test: Manually
Change-Id: I0b55de6c79da302764fd04a1a43fca40a7323c07
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUxRestrictionsUtil.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUxRestrictionsUtil.java
index e5c7fc9..b4baf31 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUxRestrictionsUtil.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUxRestrictionsUtil.java
@@ -22,6 +22,7 @@
 import android.car.drivingstate.CarUxRestrictions.CarUxRestrictionsInfo;
 import android.car.drivingstate.CarUxRestrictionsManager;
 import android.content.Context;
+import android.os.Build;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -34,10 +35,6 @@
 import java.util.Set;
 import java.util.WeakHashMap;
 
-// This can't be in the middle of the rest of the imports on gerrit or it will
-// fail our style checks
-// copybara:insert import android.car.CarNotConnectedException;
-
 /**
  * Utility class to access Car Restriction Manager.
  *
@@ -48,10 +45,6 @@
 public class CarUxRestrictionsUtil {
     private static final String TAG = "CarUxRestrictionsUtil";
 
-    /* copybara:insert
-    private final Car mCarApi;
-    private CarUxRestrictionsManager mCarUxRestrictionsManager;
-    */
     @NonNull
     private CarUxRestrictions mCarUxRestrictions = getDefaultRestrictions();
 
@@ -73,36 +66,36 @@
                     }
                 };
 
-        // copybara:strip_begin
-        Car.createCar(context.getApplicationContext(), null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT,
-                (Car car, boolean ready) -> {
-                    if (ready) {
-                        CarUxRestrictionsManager carUxRestrictionsManager =
-                                (CarUxRestrictionsManager) car.getCarManager(
-                                        Car.CAR_UX_RESTRICTION_SERVICE);
-                        carUxRestrictionsManager.registerListener(listener);
-                        listener.onUxRestrictionsChanged(
-                                carUxRestrictionsManager.getCurrentCarUxRestrictions());
-                    } else {
-                        Log.w(TAG, "Car service disconnected, assuming fully restricted uxr");
-                        listener.onUxRestrictionsChanged(null);
-                    }
-                });
-        /* copybara:strip_end_and_replace
-        mCarApi = Car.createCar(context.getApplicationContext());
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+            Car.createCar(context.getApplicationContext(), null, Car.CAR_WAIT_TIMEOUT_DO_NOT_WAIT,
+                    (Car car, boolean ready) -> {
+                        if (ready) {
+                            CarUxRestrictionsManager carUxRestrictionsManager =
+                                    (CarUxRestrictionsManager) car.getCarManager(
+                                            Car.CAR_UX_RESTRICTION_SERVICE);
+                            carUxRestrictionsManager.registerListener(listener);
+                            listener.onUxRestrictionsChanged(
+                                    carUxRestrictionsManager.getCurrentCarUxRestrictions());
+                        } else {
+                            Log.w(TAG, "Car service disconnected, assuming fully restricted uxr");
+                            listener.onUxRestrictionsChanged(null);
+                        }
+                    });
+        } else {
+            Car carApi = Car.createCar(context.getApplicationContext());
 
-        try {
-            mCarUxRestrictionsManager =
-                    (CarUxRestrictionsManager) mCarApi.getCarManager(
-                            Car.CAR_UX_RESTRICTION_SERVICE);
-            mCarUxRestrictionsManager.registerListener(listener);
-            listener.onUxRestrictionsChanged(
-                    mCarUxRestrictionsManager.getCurrentCarUxRestrictions());
-        } catch (CarNotConnectedException | NullPointerException e) {
-            Log.e(TAG, "Car not connected", e);
-            // mCarUxRestrictions will be the default
+            try {
+                CarUxRestrictionsManager carUxRestrictionsManager =
+                        (CarUxRestrictionsManager) carApi.getCarManager(
+                                Car.CAR_UX_RESTRICTION_SERVICE);
+                carUxRestrictionsManager.registerListener(listener);
+                listener.onUxRestrictionsChanged(
+                        carUxRestrictionsManager.getCurrentCarUxRestrictions());
+            } catch (NullPointerException e) {
+                Log.e(TAG, "Car not connected", e);
+                // mCarUxRestrictions will be the default
+            }
         }
-        */
     }
 
     @NonNull