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 */
16package com.android.car.vehiclehal.test;
17
18import static org.junit.Assert.assertEquals;
19
20import android.hardware.automotive.vehicle.V2_0.IVehicle;
21import android.hardware.automotive.vehicle.V2_0.StatusCode;
22import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
23import android.os.RemoteException;
24
25import com.android.car.vehiclehal.VehiclePropValueBuilder;
26
27import java.io.File;
28
29class JsonVhalEventGenerator implements VhalEventGenerator {
30
31    private IVehicle mVehicle;
32    private File mFile;
33
34    JsonVhalEventGenerator(IVehicle vehicle) {
35        mVehicle = vehicle;
36    }
37
38    public JsonVhalEventGenerator setJsonFile(File file) throws Exception {
39        if (!file.exists()) {
40            throw new Exception("JSON test data file does not exist: " + file.getAbsolutePath());
41        }
42        mFile = file;
43        return this;
44    }
45
46    @Override
47    public void start() throws RemoteException {
48        VehiclePropValue request =
49                VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
50                    .addIntValue(CMD_START_JSON)
51                    .setStringValue(mFile.getAbsolutePath())
52                    .build();
53        assertEquals(StatusCode.OK, mVehicle.set(request));
54    }
55
56    @Override
57    public void stop() throws RemoteException {
58        VehiclePropValue request =
59                VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
60                    .addIntValue(CMD_STOP_JSON)
61                    .build();
62        assertEquals(StatusCode.OK, mVehicle.set(request));
63    }
64}
65