1 /* 2 * Copyright (C) 2017 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 17 package com.android.car.vehiclehal.test; 18 19 import static com.android.car.vehiclehal.test.Utils.isVhalPropertyAvailable; 20 import static com.android.car.vehiclehal.test.Utils.readVhalProperty; 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.assertNotNull; 23 import static org.junit.Assume.assumeTrue; 24 25 import android.hardware.automotive.vehicle.V2_0.IVehicle; 26 import android.hardware.automotive.vehicle.V2_0.StatusCode; 27 import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; 28 import android.hardware.automotive.vehicle.V2_0.VehicleProperty; 29 import android.os.RemoteException; 30 import android.util.Log; 31 32 import com.android.car.vehiclehal.VehiclePropValueBuilder; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 37 /** Test retrieving the OBD2_FREEZE_FRAME property from VHAL */ 38 public class Obd2FreezeFrameTest { 39 private static final String TAG = Utils.concatTag(Obd2FreezeFrameTest.class); 40 41 private IVehicle mVehicle = null; 42 43 @Before 44 public void setUp() throws Exception { 45 mVehicle = Utils.getVehicle(); 46 assumeTrue("Freeze frame not available, test-case ignored.", isFreezeFrameAvailable()); 47 } 48 49 @Test 50 public void testFreezeFrame() throws RemoteException { 51 readVhalProperty( 52 mVehicle, 53 VehicleProperty.OBD2_FREEZE_FRAME_INFO, 54 (Integer status, VehiclePropValue value) -> { 55 assertEquals(StatusCode.OK, status.intValue()); 56 assertNotNull("OBD2_FREEZE_FRAME_INFO is supported; should not be null", value); 57 Log.i(TAG, "dump of OBD2_FREEZE_FRAME_INFO:\n" + value); 58 for(long timestamp: value.value.int64Values) { 59 Log.i(TAG, "timestamp: " + timestamp); 60 readVhalProperty( 61 mVehicle, 62 VehiclePropValueBuilder.newBuilder(VehicleProperty.OBD2_FREEZE_FRAME) 63 .setInt64Value(timestamp) 64 .build(), 65 (Integer frameStatus, VehiclePropValue freezeFrame) -> { 66 if (StatusCode.OK == frameStatus.intValue()) { 67 assertNotNull("OBD2_FREEZE_FRAME read OK; should not be null", 68 freezeFrame); 69 Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + freezeFrame); 70 assertEquals(freezeFrame.timestamp, timestamp); 71 } 72 return true; 73 }); 74 } 75 return true; 76 }); 77 } 78 79 private boolean isFreezeFrameAvailable() throws RemoteException { 80 return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME) && 81 isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME_INFO); 82 } 83 } 84