diff options
author | android-build-team Robot | 2018-05-16 02:27:02 -0500 |
---|---|---|
committer | android-build-team Robot | 2018-05-16 02:27:02 -0500 |
commit | b3a1303ae043e10ed90490e1a68454055f19686f (patch) | |
tree | cacc5cc598ac6fc1e3d4dad374702cb9b310d739 | |
parent | 361945653a8fc04a40ec5c691f03d122e25fdb19 (diff) | |
parent | 6fbb7f89ac829e8ea53ec2b92acbfe36619a9869 (diff) | |
download | platform-packages-services-car-b3a1303ae043e10ed90490e1a68454055f19686f.tar.gz platform-packages-services-car-b3a1303ae043e10ed90490e1a68454055f19686f.tar.xz platform-packages-services-car-b3a1303ae043e10ed90490e1a68454055f19686f.zip |
Snap for 4784261 from 6fbb7f89ac829e8ea53ec2b92acbfe36619a9869 to pi-release
Change-Id: Ie62d8f1cc85710314aa228d42750245193f63689
30 files changed, 268 insertions, 37 deletions
diff --git a/car_product/build/car.mk b/car_product/build/car.mk index 22a56667..669e828d 100644 --- a/car_product/build/car.mk +++ b/car_product/build/car.mk | |||
@@ -16,6 +16,9 @@ | |||
16 | 16 | ||
17 | # Common make file for all car builds | 17 | # Common make file for all car builds |
18 | 18 | ||
19 | BOARD_PLAT_PUBLIC_SEPOLICY_DIR += packages/services/Car/car_product/sepolicy/public | ||
20 | BOARD_PLAT_PRIVATE_SEPOLICY_DIR += packages/services/Car/car_product/sepolicy/private | ||
21 | |||
19 | PRODUCT_PACKAGES += \ | 22 | PRODUCT_PACKAGES += \ |
20 | Bluetooth \ | 23 | Bluetooth \ |
21 | OneTimeInitializer \ | 24 | OneTimeInitializer \ |
@@ -40,6 +43,8 @@ PRODUCT_PACKAGES += \ | |||
40 | DirectRenderingClusterSample \ | 43 | DirectRenderingClusterSample \ |
41 | com.android.car.powertestservice \ | 44 | com.android.car.powertestservice \ |
42 | 45 | ||
46 | # SEPolicy for test apps / services | ||
47 | BOARD_SEPOLICY_DIRS += packages/services/Car/car_product/sepolicy/test | ||
43 | endif | 48 | endif |
44 | 49 | ||
45 | PRODUCT_COPY_FILES := \ | 50 | PRODUCT_COPY_FILES := \ |
diff --git a/car_product/build/car_base.mk b/car_product/build/car_base.mk index 0181ec13..91380902 100644 --- a/car_product/build/car_base.mk +++ b/car_product/build/car_base.mk | |||
@@ -19,9 +19,6 @@ | |||
19 | 19 | ||
20 | PRODUCT_PACKAGE_OVERLAYS += packages/services/Car/car_product/overlay | 20 | PRODUCT_PACKAGE_OVERLAYS += packages/services/Car/car_product/overlay |
21 | 21 | ||
22 | # TODO: need to split policy by partition: public/private/vendor | ||
23 | BOARD_SEPOLICY_DIRS += packages/services/Car/car_product/sepolicy | ||
24 | |||
25 | PRODUCT_PACKAGES += \ | 22 | PRODUCT_PACKAGES += \ |
26 | ContactsProvider \ | 23 | ContactsProvider \ |
27 | DefaultContainerService \ | 24 | DefaultContainerService \ |
diff --git a/car_product/sepolicy/domain.te b/car_product/sepolicy/domain.te deleted file mode 100644 index d643e83b..00000000 --- a/car_product/sepolicy/domain.te +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | # Ignore personality-8 denials. | ||
2 | dontaudit domain kernel:system module_request; | ||
diff --git a/car_product/sepolicy/init.te b/car_product/sepolicy/init.te deleted file mode 100644 index a80ab0e9..00000000 --- a/car_product/sepolicy/init.te +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | # Allow legacy sdcard for creating directory symlinks | ||
2 | allow init tmpfs:lnk_file create_file_perms; | ||
diff --git a/car_product/sepolicy/netd.te b/car_product/sepolicy/netd.te deleted file mode 100644 index 2b002ec9..00000000 --- a/car_product/sepolicy/netd.te +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | dontaudit netd self:capability sys_module; | ||
diff --git a/car_product/sepolicy/carservice_app.te b/car_product/sepolicy/private/carservice_app.te index af119a8a..247cd4da 100644 --- a/car_product/sepolicy/carservice_app.te +++ b/car_product/sepolicy/private/carservice_app.te | |||
@@ -1,5 +1,4 @@ | |||
1 | # Domain to run Car Service (com.android.car) | 1 | # Domain to run Car Service (com.android.car) |
2 | type carservice_app, domain, coredomain; | ||
3 | app_domain(carservice_app); | 2 | app_domain(carservice_app); |
4 | 3 | ||
5 | # Allow Car Service to be the client of Vehicle and Audio Control HALs | 4 | # Allow Car Service to be the client of Vehicle and Audio Control HALs |
@@ -17,7 +16,10 @@ allow carservice_app carservice_service:service_manager add; | |||
17 | allow carservice_app { | 16 | allow carservice_app { |
18 | accessibility_service | 17 | accessibility_service |
19 | activity_service | 18 | activity_service |
19 | audio_service | ||
20 | audioserver_service | ||
20 | autofill_service | 21 | autofill_service |
22 | bluetooth_manager_service | ||
21 | connectivity_service | 23 | connectivity_service |
22 | content_service | 24 | content_service |
23 | deviceidle_service | 25 | deviceidle_service |
@@ -28,6 +30,7 @@ allow carservice_app { | |||
28 | location_service | 30 | location_service |
29 | network_management_service | 31 | network_management_service |
30 | power_service | 32 | power_service |
33 | procfsinspector_service | ||
31 | sensorservice_service | 34 | sensorservice_service |
32 | surfaceflinger_service | 35 | surfaceflinger_service |
33 | uimode_service | 36 | uimode_service |
@@ -39,3 +42,8 @@ allow carservice_app system_app_data_file:{ file lnk_file } create_file_perms; | |||
39 | 42 | ||
40 | # For I/O stats tracker | 43 | # For I/O stats tracker |
41 | allow carservice_app proc_uid_io_stats:file { read open getattr }; | 44 | allow carservice_app proc_uid_io_stats:file { read open getattr }; |
45 | |||
46 | allow carservice_app procfsinspector:binder call; | ||
47 | |||
48 | # To access /sys/fs/<type>/<partition>/lifetime_write_kbytes | ||
49 | allow carservice_app sysfs_fs_lifetime_write:file { getattr open read }; | ||
diff --git a/procfs-inspector/server/sepolicy/file_contexts b/car_product/sepolicy/private/file_contexts index 52839933..52839933 100644 --- a/procfs-inspector/server/sepolicy/file_contexts +++ b/car_product/sepolicy/private/file_contexts | |||
diff --git a/car_product/sepolicy/private/procfsinspector.te b/car_product/sepolicy/private/procfsinspector.te new file mode 100644 index 00000000..8e1a5334 --- /dev/null +++ b/car_product/sepolicy/private/procfsinspector.te | |||
@@ -0,0 +1,9 @@ | |||
1 | type procfsinspector, domain, coredomain; | ||
2 | type procfsinspector_exec, exec_type, file_type; | ||
3 | |||
4 | init_daemon_domain(procfsinspector) | ||
5 | |||
6 | add_service(procfsinspector, procfsinspector_service) | ||
7 | binder_use(procfsinspector) | ||
8 | |||
9 | allow carservice_app procfsinspector:binder call; | ||
diff --git a/car_product/sepolicy/private/property.te b/car_product/sepolicy/private/property.te new file mode 100644 index 00000000..409cbdc6 --- /dev/null +++ b/car_product/sepolicy/private/property.te | |||
@@ -0,0 +1 @@ | |||
type car_prop, property_type; | |||
diff --git a/car_product/sepolicy/private/property_contexts b/car_product/sepolicy/private/property_contexts new file mode 100644 index 00000000..da14e3e0 --- /dev/null +++ b/car_product/sepolicy/private/property_contexts | |||
@@ -0,0 +1 @@ | |||
boot.car_service_created u:object_r:car_prop:s0 | |||
diff --git a/car_product/sepolicy/private/seapp_contexts b/car_product/sepolicy/private/seapp_contexts new file mode 100644 index 00000000..97217bf2 --- /dev/null +++ b/car_product/sepolicy/private/seapp_contexts | |||
@@ -0,0 +1 @@ | |||
user=system seinfo=platform name=com.android.car domain=carservice_app type=system_app_data_file | |||
diff --git a/car_product/sepolicy/private/service_contexts b/car_product/sepolicy/private/service_contexts new file mode 100644 index 00000000..7ac544c1 --- /dev/null +++ b/car_product/sepolicy/private/service_contexts | |||
@@ -0,0 +1,2 @@ | |||
1 | car_service u:object_r:carservice_service:s0 | ||
2 | com.android.car.procfsinspector u:object_r:procfsinspector_service:s0 | ||
diff --git a/car_product/sepolicy/property.te b/car_product/sepolicy/property.te deleted file mode 100644 index 64340e7c..00000000 --- a/car_product/sepolicy/property.te +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | type hw_cabl_prop, property_type; | ||
2 | type wlan_driver_prop, property_type; | ||
3 | type car_prop, property_type; | ||
diff --git a/car_product/sepolicy/property_contexts b/car_product/sepolicy/property_contexts deleted file mode 100644 index a6ffc71e..00000000 --- a/car_product/sepolicy/property_contexts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | hw.cabl. u:object_r:hw_cabl_prop:s0 | ||
2 | wlan.driver. u:object_r:wlan_driver_prop:s0 | ||
3 | |||
4 | boot.car_service_created u:object_r:car_prop:s0 | ||
diff --git a/car_product/sepolicy/public/carservice_app.te b/car_product/sepolicy/public/carservice_app.te new file mode 100644 index 00000000..fd276b63 --- /dev/null +++ b/car_product/sepolicy/public/carservice_app.te | |||
@@ -0,0 +1,2 @@ | |||
1 | # Domain to run Car Service (com.android.car) | ||
2 | type carservice_app, domain, coredomain; | ||
diff --git a/car_product/sepolicy/public/file.te b/car_product/sepolicy/public/file.te new file mode 100644 index 00000000..ea79a248 --- /dev/null +++ b/car_product/sepolicy/public/file.te | |||
@@ -0,0 +1,5 @@ | |||
1 | # This type for lifetime_write_kbytes files which resides in | ||
2 | # /sys/fs/<filesystem>/<partition>/lifetime_writes_kbytes | ||
3 | # Vendors are supposed to extend genfs_contexts with the | ||
4 | # partition names for their devices. | ||
5 | type sysfs_fs_lifetime_write, sysfs_type, fs_type; | ||
diff --git a/car_product/sepolicy/public/service.te b/car_product/sepolicy/public/service.te new file mode 100644 index 00000000..6c514f31 --- /dev/null +++ b/car_product/sepolicy/public/service.te | |||
@@ -0,0 +1,2 @@ | |||
1 | type carservice_service, service_manager_type; | ||
2 | type procfsinspector_service, service_manager_type; | ||
diff --git a/car_product/sepolicy/seapp_contexts b/car_product/sepolicy/seapp_contexts deleted file mode 100644 index ec629bec..00000000 --- a/car_product/sepolicy/seapp_contexts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | user=system seinfo=platform name=com.android.car domain=carservice_app type=system_app_data_file | ||
2 | |||
3 | # Allow Kitchen Sink app (for test purpose) to run in the Car Service security domain | ||
4 | user=system seinfo=platform name=com.google.android.car.kitchensink domain=carservice_app type=system_app_data_file | ||
diff --git a/car_product/sepolicy/service.te b/car_product/sepolicy/service.te deleted file mode 100644 index 6eff13bb..00000000 --- a/car_product/sepolicy/service.te +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | type carservice_service, service_manager_type; | ||
diff --git a/car_product/sepolicy/service_contexts b/car_product/sepolicy/service_contexts deleted file mode 100644 index 844d65d4..00000000 --- a/car_product/sepolicy/service_contexts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | car_service u:object_r:carservice_service:s0 | ||
diff --git a/car_product/sepolicy/system_server.te b/car_product/sepolicy/system_server.te deleted file mode 100644 index b6785c16..00000000 --- a/car_product/sepolicy/system_server.te +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | # Set wlan.driver.* properties. | ||
2 | set_prop(system_server, wlan_driver_prop) | ||
3 | |||
4 | dontaudit system_server self:capability sys_module; | ||
diff --git a/car_product/sepolicy/file_contexts b/car_product/sepolicy/test/file_contexts index 7be7605f..7be7605f 100644 --- a/car_product/sepolicy/file_contexts +++ b/car_product/sepolicy/test/file_contexts | |||
diff --git a/car_product/sepolicy/test/kitchensink_app.te b/car_product/sepolicy/test/kitchensink_app.te new file mode 100644 index 00000000..8bd5a68e --- /dev/null +++ b/car_product/sepolicy/test/kitchensink_app.te | |||
@@ -0,0 +1,30 @@ | |||
1 | # Domain to run EmbeddedKitchenSink app (for test-purpose) | ||
2 | type kitchensink_app, domain; | ||
3 | app_domain(kitchensink_app); | ||
4 | |||
5 | # Allow Car Service to be the client of Vehicle HAL | ||
6 | hal_client_domain(kitchensink_app, hal_vehicle) | ||
7 | |||
8 | # Keep alphabetically sorted. | ||
9 | allow kitchensink_app { | ||
10 | accessibility_service | ||
11 | activity_service | ||
12 | autofill_service | ||
13 | connectivity_service | ||
14 | content_service | ||
15 | deviceidle_service | ||
16 | display_service | ||
17 | graphicsstats_service | ||
18 | input_method_service | ||
19 | input_service | ||
20 | location_service | ||
21 | network_management_service | ||
22 | power_service | ||
23 | sensorservice_service | ||
24 | surfaceflinger_service | ||
25 | uimode_service | ||
26 | }:service_manager find; | ||
27 | |||
28 | # Read and write /data/data subdirectory. | ||
29 | allow kitchensink_app system_app_data_file:dir { create_dir_perms getattr }; | ||
30 | allow kitchensink_app system_app_data_file:{ file lnk_file } create_file_perms; | ||
diff --git a/car_product/sepolicy/powertestservice.te b/car_product/sepolicy/test/powertestservice.te index 2e2ace7f..2e2ace7f 100644 --- a/car_product/sepolicy/powertestservice.te +++ b/car_product/sepolicy/test/powertestservice.te | |||
diff --git a/car_product/sepolicy/test/seapp_contexts b/car_product/sepolicy/test/seapp_contexts new file mode 100644 index 00000000..530e60ec --- /dev/null +++ b/car_product/sepolicy/test/seapp_contexts | |||
@@ -0,0 +1 @@ | |||
user=system seinfo=platform name=com.google.android.car.kitchensink domain=kitchensink_app type=system_app_data_file | |||
diff --git a/procfs-inspector/server/Android.mk b/procfs-inspector/server/Android.mk index d6a7d437..fab1cf88 100644 --- a/procfs-inspector/server/Android.mk +++ b/procfs-inspector/server/Android.mk | |||
@@ -18,9 +18,6 @@ LOCAL_PATH:= $(call my-dir) | |||
18 | 18 | ||
19 | include $(CLEAR_VARS) | 19 | include $(CLEAR_VARS) |
20 | 20 | ||
21 | BOARD_SEPOLICY_DIRS += \ | ||
22 | packages/services/Car/procfs-inspector/server/sepolicy | ||
23 | |||
24 | LOCAL_SRC_FILES := \ | 21 | LOCAL_SRC_FILES := \ |
25 | main.cpp \ | 22 | main.cpp \ |
26 | server.cpp \ | 23 | server.cpp \ |
diff --git a/procfs-inspector/server/sepolicy/com.android.car.procfsinspector.te b/procfs-inspector/server/sepolicy/com.android.car.procfsinspector.te deleted file mode 100644 index acd7ddf0..00000000 --- a/procfs-inspector/server/sepolicy/com.android.car.procfsinspector.te +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | type procfsinspector, domain, coredomain; | ||
2 | type procfsinspector_exec, exec_type, file_type; | ||
3 | |||
4 | init_daemon_domain(procfsinspector) | ||
5 | |||
6 | allow system_app procfsinspector:binder call; | ||
diff --git a/service/src/com/android/car/CarVolumeGroup.java b/service/src/com/android/car/CarVolumeGroup.java index 7975f9c4..448979bb 100644 --- a/service/src/com/android/car/CarVolumeGroup.java +++ b/service/src/com/android/car/CarVolumeGroup.java | |||
@@ -111,7 +111,7 @@ import java.util.Arrays; | |||
111 | if (info.getMinGain() < mMinGain) { | 111 | if (info.getMinGain() < mMinGain) { |
112 | mMinGain = info.getMinGain(); | 112 | mMinGain = info.getMinGain(); |
113 | } | 113 | } |
114 | if (mStoredGainIndex < 0) { | 114 | if (mStoredGainIndex < getMinGainIndex() || mStoredGainIndex > getMaxGainIndex()) { |
115 | // We expected to load a value from last boot, but if we didn't (perhaps this is the | 115 | // We expected to load a value from last boot, but if we didn't (perhaps this is the |
116 | // first boot ever?), then use the highest "default" we've seen to initialize | 116 | // first boot ever?), then use the highest "default" we've seen to initialize |
117 | // ourselves. | 117 | // ourselves. |
diff --git a/tests/carservice_test/Android.mk b/tests/carservice_test/Android.mk index 0ed57d47..d4c327ce 100644 --- a/tests/carservice_test/Android.mk +++ b/tests/carservice_test/Android.mk | |||
@@ -44,7 +44,8 @@ LOCAL_STATIC_JAVA_LIBRARIES += car-service-lib-for-test \ | |||
44 | mockito-target-inline \ | 44 | mockito-target-inline \ |
45 | android-support-test \ | 45 | android-support-test \ |
46 | android.hardware.automotive.vehicle-V2.0-java \ | 46 | android.hardware.automotive.vehicle-V2.0-java \ |
47 | com.android.car.test.utils | 47 | com.android.car.test.utils \ |
48 | truth-prebuilt | ||
48 | 49 | ||
49 | LOCAL_JAVA_LIBRARIES := android.car android.test.runner android.test.base | 50 | LOCAL_JAVA_LIBRARIES := android.car android.test.runner android.test.base |
50 | 51 | ||
diff --git a/tests/carservice_test/src/com/android/car/CarDrivingRestrictionsTest.java b/tests/carservice_test/src/com/android/car/CarDrivingRestrictionsTest.java new file mode 100644 index 00000000..ff93e668 --- /dev/null +++ b/tests/carservice_test/src/com/android/car/CarDrivingRestrictionsTest.java | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2018 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | package com.android.car; | ||
17 | |||
18 | import static com.google.common.truth.Truth.assertThat; | ||
19 | |||
20 | import static org.junit.Assert.assertNotNull; | ||
21 | import static org.junit.Assert.assertTrue; | ||
22 | |||
23 | import android.car.Car; | ||
24 | import android.car.CarNotConnectedException; | ||
25 | import android.car.drivingstate.CarDrivingStateEvent; | ||
26 | import android.car.drivingstate.CarDrivingStateManager; | ||
27 | import android.car.drivingstate.CarUxRestrictions; | ||
28 | import android.car.drivingstate.CarUxRestrictionsManager; | ||
29 | import android.hardware.automotive.vehicle.V2_0.VehicleGear; | ||
30 | import android.hardware.automotive.vehicle.V2_0.VehicleProperty; | ||
31 | import android.os.SystemClock; | ||
32 | import android.support.test.filters.SmallTest; | ||
33 | import android.support.test.runner.AndroidJUnit4; | ||
34 | import android.util.Log; | ||
35 | |||
36 | import com.android.car.vehiclehal.VehiclePropValueBuilder; | ||
37 | import com.android.internal.annotations.GuardedBy; | ||
38 | |||
39 | import org.junit.Test; | ||
40 | import org.junit.runner.RunWith; | ||
41 | |||
42 | @RunWith(AndroidJUnit4.class) | ||
43 | @SmallTest | ||
44 | public class CarDrivingRestrictionsTest extends MockedCarTestBase { | ||
45 | private static final String TAG = CarDrivingRestrictionsTest.class | ||
46 | .getSimpleName(); | ||
47 | private CarDrivingStateManager mCarDrivingStateManager; | ||
48 | private CarUxRestrictionsManager mCarUxRManager; | ||
49 | |||
50 | @Override | ||
51 | protected synchronized void configureMockedHal() { | ||
52 | addProperty(VehicleProperty.PERF_VEHICLE_SPEED, VehiclePropValueBuilder | ||
53 | .newBuilder(VehicleProperty.PERF_VEHICLE_SPEED) | ||
54 | .addFloatValue(0f) | ||
55 | .build()); | ||
56 | addProperty(VehicleProperty.PARKING_BRAKE_ON, VehiclePropValueBuilder | ||
57 | .newBuilder(VehicleProperty.PARKING_BRAKE_ON) | ||
58 | .setBooleanValue(false) | ||
59 | .build()); | ||
60 | addProperty(VehicleProperty.GEAR_SELECTION, VehiclePropValueBuilder | ||
61 | .newBuilder(VehicleProperty.GEAR_SELECTION) | ||
62 | .addIntValue(0) | ||
63 | .build()); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public void setUp() throws Exception { | ||
68 | super.setUp(); | ||
69 | mCarDrivingStateManager = (CarDrivingStateManager) getCar() | ||
70 | .getCarManager(Car.CAR_DRIVING_STATE_SERVICE); | ||
71 | mCarUxRManager = (CarUxRestrictionsManager) getCar() | ||
72 | .getCarManager(Car.CAR_UX_RESTRICTION_SERVICE); | ||
73 | } | ||
74 | |||
75 | @Test | ||
76 | public void testDrivingStateChange() throws CarNotConnectedException, InterruptedException { | ||
77 | CarDrivingStateEvent drivingEvent; | ||
78 | CarUxRestrictions restrictions; | ||
79 | DrivingStateListener listener = new DrivingStateListener(); | ||
80 | mCarDrivingStateManager.registerListener(listener); | ||
81 | mCarUxRManager.registerListener(listener); | ||
82 | // With no gear value available, driving state should be unknown | ||
83 | listener.reset(); | ||
84 | getMockedVehicleHal().injectEvent( | ||
85 | VehiclePropValueBuilder.newBuilder(VehicleProperty.PERF_VEHICLE_SPEED) | ||
86 | .addFloatValue(0.0f) | ||
87 | .setTimestamp(SystemClock.elapsedRealtimeNanos()) | ||
88 | .build()); | ||
89 | |||
90 | // Test Parked state and corresponding restrictions based on car_ux_restrictions_map.xml | ||
91 | //listener.reset(); | ||
92 | getMockedVehicleHal().injectEvent( | ||
93 | VehiclePropValueBuilder.newBuilder(VehicleProperty.GEAR_SELECTION) | ||
94 | .addIntValue(VehicleGear.GEAR_PARK) | ||
95 | .setTimestamp(SystemClock.elapsedRealtimeNanos()) | ||
96 | .build()); | ||
97 | drivingEvent = listener.waitForDrivingStateChange(); | ||
98 | assertNotNull(drivingEvent); | ||
99 | assertThat(drivingEvent.eventValue).isEqualTo(CarDrivingStateEvent.DRIVING_STATE_PARKED); | ||
100 | |||
101 | // Test Idling state and corresponding restrictions based on car_ux_restrictions_map.xml | ||
102 | listener.reset(); | ||
103 | getMockedVehicleHal().injectEvent( | ||
104 | VehiclePropValueBuilder.newBuilder(VehicleProperty.GEAR_SELECTION) | ||
105 | .addIntValue(VehicleGear.GEAR_DRIVE) | ||
106 | .setTimestamp(SystemClock.elapsedRealtimeNanos()) | ||
107 | .build()); | ||
108 | drivingEvent = listener.waitForDrivingStateChange(); | ||
109 | assertNotNull(drivingEvent); | ||
110 | assertThat(drivingEvent.eventValue).isEqualTo(CarDrivingStateEvent.DRIVING_STATE_IDLING); | ||
111 | restrictions = listener.waitForUxRestrictionsChange(); | ||
112 | assertNotNull(restrictions); | ||
113 | assertTrue(restrictions.isRequiresDistractionOptimization()); | ||
114 | assertThat(restrictions.getActiveRestrictions()) | ||
115 | .isEqualTo(CarUxRestrictions.UX_RESTRICTIONS_BASELINE); | ||
116 | |||
117 | |||
118 | // Test Moving state and corresponding restrictions based on car_ux_restrictions_map.xml | ||
119 | listener.reset(); | ||
120 | getMockedVehicleHal().injectEvent( | ||
121 | VehiclePropValueBuilder.newBuilder(VehicleProperty.PERF_VEHICLE_SPEED) | ||
122 | .addFloatValue(30.0f) | ||
123 | .setTimestamp(SystemClock.elapsedRealtimeNanos()) | ||
124 | .build()); | ||
125 | drivingEvent = listener.waitForDrivingStateChange(); | ||
126 | assertNotNull(drivingEvent); | ||
127 | assertThat(drivingEvent.eventValue).isEqualTo(CarDrivingStateEvent.DRIVING_STATE_MOVING); | ||
128 | restrictions = listener.waitForUxRestrictionsChange(); | ||
129 | assertNotNull(restrictions); | ||
130 | assertTrue(restrictions.isRequiresDistractionOptimization()); | ||
131 | assertThat(restrictions.getActiveRestrictions()) | ||
132 | .isEqualTo(CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED); | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * Callback function we register for driving state update notifications. | ||
137 | */ | ||
138 | private class DrivingStateListener implements | ||
139 | CarDrivingStateManager.CarDrivingStateEventListener, | ||
140 | CarUxRestrictionsManager.onUxRestrictionsChangedListener { | ||
141 | private final Object mDrivingStateLock = new Object(); | ||
142 | @GuardedBy("mDrivingStateLock") | ||
143 | private CarDrivingStateEvent mLastEvent = null; | ||
144 | private final Object mUxRLock = new Object(); | ||
145 | @GuardedBy("mUxRLock") | ||
146 | private CarUxRestrictions mLastRestrictions = null; | ||
147 | |||
148 | void reset() { | ||
149 | mLastEvent = null; | ||
150 | mLastRestrictions = null; | ||
151 | } | ||
152 | |||
153 | // Returns True to indicate receipt of a driving state event. False indicates a timeout. | ||
154 | CarDrivingStateEvent waitForDrivingStateChange() throws InterruptedException { | ||
155 | long start = SystemClock.elapsedRealtime(); | ||
156 | |||
157 | synchronized (mDrivingStateLock) { | ||
158 | while (mLastEvent == null | ||
159 | && (start + DEFAULT_WAIT_TIMEOUT_MS > SystemClock.elapsedRealtime())) { | ||
160 | mDrivingStateLock.wait(100L); | ||
161 | } | ||
162 | return mLastEvent; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | @Override | ||
167 | public void onDrivingStateChanged(CarDrivingStateEvent event) { | ||
168 | Log.d(TAG, "onDrivingStateChanged, event: " + event.eventValue); | ||
169 | synchronized (mDrivingStateLock) { | ||
170 | // We're going to hold a reference to this object | ||
171 | mLastEvent = event; | ||
172 | mDrivingStateLock.notify(); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | CarUxRestrictions waitForUxRestrictionsChange() throws InterruptedException { | ||
177 | long start = SystemClock.elapsedRealtime(); | ||
178 | synchronized (mUxRLock) { | ||
179 | while (mLastRestrictions == null | ||
180 | && (start + DEFAULT_WAIT_TIMEOUT_MS > SystemClock.elapsedRealtime())) { | ||
181 | mUxRLock.wait(100L); | ||
182 | } | ||
183 | } | ||
184 | return mLastRestrictions; | ||
185 | } | ||
186 | |||
187 | @Override | ||
188 | public void onUxRestrictionsChanged(CarUxRestrictions restrictions) { | ||
189 | Log.d(TAG, "onUxRestrictionsChanged, restrictions: " | ||
190 | + restrictions.getActiveRestrictions()); | ||
191 | synchronized (mUxRLock) { | ||
192 | mLastRestrictions = restrictions; | ||
193 | mUxRLock.notify(); | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | } | ||